fixing parsing
This commit is contained in:
parent
0aa49cfe9b
commit
333534a8d1
8 changed files with 95 additions and 47 deletions
|
@ -8,7 +8,7 @@ s, t ::= s | t (disjunction, a.k.a. union)
|
||||||
| s => t (implication)
|
| s => t (implication)
|
||||||
| s -> t (arrow, a.k.a. function)
|
| s -> t (arrow, a.k.a. function)
|
||||||
| forall x . t (forall, polymorphic)
|
| forall x . t (forall, polymorphic)
|
||||||
| box t (box, c.f. modular logic)
|
| box t (box, c.f. modal logic)
|
||||||
| a [t..] (type operator application)
|
| a [t..] (type operator application)
|
||||||
| x (variable)
|
| x (variable)
|
||||||
| n (nominal)
|
| n (nominal)
|
||||||
|
@ -37,23 +37,23 @@ s, γ ⊢ s, δ
|
||||||
---- [false-left]
|
---- [false-left]
|
||||||
false, γ ⊢ δ
|
false, γ ⊢ δ
|
||||||
|
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
s, t, γ ⊢ δ
|
s, t, γ ⊢ δ
|
||||||
---- [conj-left]
|
---- [conj-left]
|
||||||
s & t, γ ⊢ δ
|
s & t, γ ⊢ δ
|
||||||
|
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
γ ⊢ s, t, δ
|
γ ⊢ s, t, δ
|
||||||
---- [disj-right]
|
---- [disj-right]
|
||||||
γ ⊢ s | t, δ
|
γ ⊢ s | t, δ
|
||||||
|
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
s, γ ⊢ δ
|
s, γ ⊢ δ
|
||||||
t, γ ⊢ δ
|
t, γ ⊢ δ
|
||||||
---- [disj-left]
|
---- [disj-left]
|
||||||
s | t, γ ⊢ δ
|
s | t, γ ⊢ δ
|
||||||
|
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
γ ⊢ s, δ
|
γ ⊢ s, δ
|
||||||
γ ⊢ t, δ
|
γ ⊢ t, δ
|
||||||
---- [conj-right]
|
---- [conj-right]
|
||||||
|
@ -61,12 +61,12 @@ s | t, γ ⊢ δ
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
// remove s => t? always make progress
|
// remove s => t? always make progress
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
s => t, s, t, γ ⊢ δ
|
s => t, s, t, γ ⊢ δ
|
||||||
---- [impl-left]
|
---- [impl-left]
|
||||||
s => t, s, γ ⊢ δ
|
s => t, s, γ ⊢ δ
|
||||||
|
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
s, γ ⊢ t, δ
|
s, γ ⊢ t, δ
|
||||||
---- [impl-right]
|
---- [impl-right]
|
||||||
γ ⊢ s => t, δ
|
γ ⊢ s => t, δ
|
||||||
|
@ -89,7 +89,7 @@ box t, γ ⊢ δ
|
||||||
// to exclude typedefs like
|
// to exclude typedefs like
|
||||||
// type A = A
|
// type A = A
|
||||||
// Or that our cycle detection excludes paths between "identical" states.
|
// Or that our cycle detection excludes paths between "identical" states.
|
||||||
// trace pairs: none
|
// trace pairs: none?
|
||||||
γ ⊢ expand(a[t..]), δ
|
γ ⊢ expand(a[t..]), δ
|
||||||
----
|
----
|
||||||
γ ⊢ a[t..], δ
|
γ ⊢ a[t..], δ
|
||||||
|
@ -114,6 +114,7 @@ n fresh
|
||||||
---- [forall]
|
---- [forall]
|
||||||
γ ⊢ δ
|
γ ⊢ δ
|
||||||
|
|
||||||
|
// TODO can we choose a simpler rule instead?
|
||||||
// 1 + n! premises
|
// 1 + n! premises
|
||||||
// trace pairs: i ∈ [1..(n! + 1)], premise[i] -- conclusion
|
// trace pairs: i ∈ [1..(n! + 1)], premise[i] -- conclusion
|
||||||
c, γ* ⊢ a_1, ..., a_n, δ*
|
c, γ* ⊢ a_1, ..., a_n, δ*
|
||||||
|
@ -125,6 +126,7 @@ c, γ* ⊢ a_1, ..., a_n, δ*
|
||||||
a_1 -> b_1, ..., a_n -> b_n, γ ⊢ c -> d, δ
|
a_1 -> b_1, ..., a_n -> b_n, γ ⊢ c -> d, δ
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### context operators
|
### context operators
|
||||||
|
|
||||||
* box filtering
|
* box filtering
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
# draft of presentation
|
# sappho short
|
||||||
|
|
||||||
## sappho short
|
|
||||||
- sappho types intro
|
- sappho types intro
|
||||||
- a quick look at msph and spho
|
- a quick look at msph and spho
|
||||||
|
|
||||||
|
|
||||||
### The types
|
## The types
|
||||||
|
|
||||||
We take a look at the grammar for sappho types
|
We take a look at the grammar for sappho types
|
||||||
|
|
||||||
|
@ -15,7 +13,7 @@ s, t ::= s | t (disjunction, a.k.a. union)
|
||||||
| s => t (implication)
|
| s => t (implication)
|
||||||
| s -> t (arrow, a.k.a. function)
|
| s -> t (arrow, a.k.a. function)
|
||||||
| forall x . t (forall, polymorphic)
|
| forall x . t (forall, polymorphic)
|
||||||
| box t (box, c.f. modular logic)
|
| box t (box, c.f. modal logic)
|
||||||
| a [t..] (type operator application)
|
| a [t..] (type operator application)
|
||||||
| x (variable)
|
| x (variable)
|
||||||
| n (nominal)
|
| n (nominal)
|
||||||
|
@ -30,7 +28,7 @@ n ∈ nominal
|
||||||
a ∈ opname
|
a ∈ opname
|
||||||
```
|
```
|
||||||
|
|
||||||
The type `t <: s` would be expressive sugar for `box (t => s)`
|
The type `t <: s` would be syntactic sugar for `box (t => s)`
|
||||||
|
|
||||||
### msph and spho
|
### msph and spho
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ Thoughts
|
||||||
* maybe eventually add a basic term language and interpreter
|
* maybe eventually add a basic term language and interpreter
|
||||||
* can we use external software/libraries for proof search?
|
* can we use external software/libraries for proof search?
|
||||||
|
|
||||||
## interpretation of types
|
# interpretation of types
|
||||||
- example programs in `msph`
|
- example programs in `msph`
|
||||||
- unified syntax for types and bounded polymorphism
|
- unified syntax for types and bounded polymorphism
|
||||||
- example: self typing
|
- example: self typing
|
||||||
|
@ -75,7 +73,8 @@ Check formalities.md.
|
||||||
- simple rules
|
- simple rules
|
||||||
- type constructor rules
|
- type constructor rules
|
||||||
- recursion and cyclic proofs
|
- recursion and cyclic proofs
|
||||||
* next steps?
|
|
||||||
|
# next steps?
|
||||||
- formals:
|
- formals:
|
||||||
- formulate theorems
|
- formulate theorems
|
||||||
- if we use semantic subtyping, isn't it enough to
|
- if we use semantic subtyping, isn't it enough to
|
||||||
|
@ -85,3 +84,4 @@ Check formalities.md.
|
||||||
- simple rules, should be fairly simple
|
- simple rules, should be fairly simple
|
||||||
- type constructors, straightforward hopefully
|
- type constructors, straightforward hopefully
|
||||||
- recursion and cyclic proofs... `¯\_(ツ)_/¯`
|
- recursion and cyclic proofs... `¯\_(ツ)_/¯`
|
||||||
|
- describe use of language with type system (interpretation of types)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _MSPH_COMMON_H
|
#ifndef _MSPH_H
|
||||||
#define _MSPH_COMMON_H
|
#define _MSPH_H
|
||||||
|
|
||||||
#include "msph/err.h"
|
#include "msph/err.h"
|
||||||
#include "spho/ctx.h"
|
#include "spho/ctx.h"
|
||||||
|
@ -25,4 +25,4 @@ struct msph_text_pos {
|
||||||
unsigned int col;
|
unsigned int col;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /* ifndef _MSPH_H */
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#include "msph/common.h"
|
#include "msph/msph.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#include "msph/common.h"
|
#include "msph/msph.h"
|
||||||
#include "msph/token.h"
|
#include "msph/token.h"
|
||||||
|
|
||||||
/* tree decorations */
|
/* tree decorations */
|
||||||
|
|
|
@ -2,23 +2,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "msph/err.h"
|
#include "msph/msph.h"
|
||||||
#include "msph/token.h"
|
#include "msph/token.h"
|
||||||
#include "msph/tree.h"
|
#include "msph/tree.h"
|
||||||
#include "msph/sphophi.h"
|
#include "msph/sphophi.h"
|
||||||
|
|
||||||
struct msph_opts {
|
|
||||||
int tokenize_only;
|
|
||||||
int parser;
|
|
||||||
const char *in_path;
|
|
||||||
const char *out_path;
|
|
||||||
} run_opts = {
|
|
||||||
0,
|
|
||||||
MSPH_PARSE_INFIX,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define USAGE \
|
#define USAGE \
|
||||||
"msph: micro sappho\n" \
|
"msph: micro sappho\n" \
|
||||||
|
@ -35,6 +23,64 @@ print_usage(void)
|
||||||
printf("%s", USAGE);
|
printf("%s", USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct err_info {
|
||||||
|
int err;
|
||||||
|
const char *msg;
|
||||||
|
} errinfo[] = {
|
||||||
|
{ MSPH_ERR_SYS, "system error" },
|
||||||
|
{ MSPH_ERR_INVAL, "invalid argument" },
|
||||||
|
{ MSPH_ERR_TOOLONG, "input too long" },
|
||||||
|
|
||||||
|
{ MSPH_ERR_TOKEN_TOOLONG, "token too long" },
|
||||||
|
{ MSPH_ERR_TOKEN_EOF, "tokenizer reached end of file" },
|
||||||
|
{ MSPH_ERR_TOKEN_NOMATCH, "no matching token" },
|
||||||
|
{ MSPH_ERR_TOKEN_INVAL, "token invalid" },
|
||||||
|
|
||||||
|
{ MSPH_ERR_TREE_TOOLONG, "parsed data too long" },
|
||||||
|
{ MSPH_ERR_TREE_EOF, "parsing reached unexpected end of file" },
|
||||||
|
{ MSPH_ERR_TREE_NOMATCH, "parser matching failed" },
|
||||||
|
|
||||||
|
{ MSPH_ERR_TYPE_INVAL, "invalid type" },
|
||||||
|
|
||||||
|
{ MSPH_ERR_SPHOPHI, "spho error" },
|
||||||
|
{ -1, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
print_error(struct msph_ctx *ctx)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
const char *err_msg;
|
||||||
|
|
||||||
|
err_msg = NULL;
|
||||||
|
for (i = 0; errinfo[i].err != -1; i++) {
|
||||||
|
if (ctx->err == errinfo[i].err) {
|
||||||
|
err_msg = errinfo[i].msg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (err_msg == NULL) {
|
||||||
|
err_msg = "unknown error";
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "ERROR(%x, %d):%s\n", ctx->err, ctx->err_info, err_msg);
|
||||||
|
|
||||||
|
if (ctx->err == MSPH_ERR_SPHOPHI)
|
||||||
|
fprintf(stderr, "\t%s\n", spho_ctx_strerror(ctx->spho));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct msph_opts {
|
||||||
|
int tokenize_only;
|
||||||
|
int parser;
|
||||||
|
const char *in_path;
|
||||||
|
const char *out_path;
|
||||||
|
} run_opts = {
|
||||||
|
0,
|
||||||
|
MSPH_PARSE_INFIX,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
int run(struct msph_opts *);
|
int run(struct msph_opts *);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -98,6 +144,7 @@ run(struct msph_opts *opts)
|
||||||
struct msph_tree_root *root;
|
struct msph_tree_root *root;
|
||||||
FILE *in, *out;
|
FILE *in, *out;
|
||||||
|
|
||||||
|
|
||||||
in = out = NULL;
|
in = out = NULL;
|
||||||
s = NULL;
|
s = NULL;
|
||||||
root = NULL;
|
root = NULL;
|
||||||
|
@ -157,13 +204,7 @@ exit:
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (root != NULL && ctx.err == MSPH_ERR_SPHOPHI) {
|
print_error(&ctx);
|
||||||
fprintf(stderr, "ERROR:%s\n",
|
|
||||||
spho_ctx_strerror(ctx.spho));
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "ERROR:msph_err: %x (%d)\n", (ctx).err,
|
|
||||||
(ctx).err_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in)
|
if (in)
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
@ -173,6 +214,7 @@ err:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
msph_ctx_init(struct msph_ctx *ctx)
|
msph_ctx_init(struct msph_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "spho/spho.h"
|
#include "spho/spho.h"
|
||||||
|
|
||||||
#include "msph/err.h"
|
#include "msph/msph.h"
|
||||||
#include "msph/token.h"
|
#include "msph/token.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#define SPHO_ENABLE_DEBUG_PRINT
|
#define SPHO_ENABLE_DEBUG_PRINT
|
||||||
#include "msph/common.h"
|
|
||||||
#include "msph/common.h"
|
|
||||||
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
|
@ -10,6 +9,7 @@
|
||||||
|
|
||||||
#include "spho/spho.h"
|
#include "spho/spho.h"
|
||||||
|
|
||||||
|
#include "msph/msph.h"
|
||||||
#include "msph/tree.h"
|
#include "msph/tree.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,6 +130,8 @@ msph_tree_makeroot(struct msph_ctx *ctx)
|
||||||
return (root);
|
return (root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define __POS_FMT "line: %u, col: %u"
|
||||||
|
#define __POS_ARGS(pos) (pos).line, (pos).col
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expect to read next token, otherwise set error and do something
|
* Expect to read next token, otherwise set error and do something
|
||||||
|
@ -143,6 +145,8 @@ msph_tree_makeroot(struct msph_ctx *ctx)
|
||||||
if (((readres) = tree_parse_next_token(parse)) == -1) \
|
if (((readres) = tree_parse_next_token(parse)) == -1) \
|
||||||
on_err; \
|
on_err; \
|
||||||
if ((readres) == 0) { \
|
if ((readres) == 0) { \
|
||||||
|
fprintf(stderr, "unexpected end-of-file after " \
|
||||||
|
__POS_FMT "\n", __POS_ARGS((parse)->s->src.pos)); \
|
||||||
MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_EOF, \
|
MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_EOF, \
|
||||||
err_info); \
|
err_info); \
|
||||||
on_err; \
|
on_err; \
|
||||||
|
@ -159,6 +163,8 @@ msph_tree_makeroot(struct msph_ctx *ctx)
|
||||||
#define EXPECT_CURR_TOKEN(parse, toktype, err_info, on_err) \
|
#define EXPECT_CURR_TOKEN(parse, toktype, err_info, on_err) \
|
||||||
do { \
|
do { \
|
||||||
if (CURR_TOKEN(parse)->type != toktype) { \
|
if (CURR_TOKEN(parse)->type != toktype) { \
|
||||||
|
fprintf(stderr, "parser expected token " #toktype \
|
||||||
|
"\n"); \
|
||||||
MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_NOMATCH, \
|
MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_NOMATCH, \
|
||||||
err_info); \
|
err_info); \
|
||||||
on_err; \
|
on_err; \
|
||||||
|
@ -1062,7 +1068,6 @@ err:
|
||||||
struct msph_tree_tpexpr *
|
struct msph_tree_tpexpr *
|
||||||
tree_parse_tpname_or_tpappl(struct tree_parse *p, struct msph_tree *parent)
|
tree_parse_tpname_or_tpappl(struct tree_parse *p, struct msph_tree *parent)
|
||||||
{
|
{
|
||||||
int res;
|
|
||||||
struct msph_tree_tpname *tpname;
|
struct msph_tree_tpname *tpname;
|
||||||
struct msph_tree_tpexpr *ret;
|
struct msph_tree_tpexpr *ret;
|
||||||
struct msph_tree_nameref *nameref;
|
struct msph_tree_nameref *nameref;
|
||||||
|
@ -1074,7 +1079,6 @@ tree_parse_tpname_or_tpappl(struct tree_parse *p, struct msph_tree *parent)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (CURR_TOKEN(p)->type == TOK_LBRAK) {
|
if (CURR_TOKEN(p)->type == TOK_LBRAK) {
|
||||||
EXPECT_READ_NEXT(res, p, MSPH_TREE_TPAPPL, goto err);
|
|
||||||
if ((ret = tree_parse_tpapplargs(p, nameref, parent)) == NULL)
|
if ((ret = tree_parse_tpapplargs(p, nameref, parent)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue