.free = array_free,
};
+###### declare terminals
+ $TERM [ ]
+
###### type grammar
| [ NUMBER ] Type ${
free(e);
break;
+###### declare terminals
+ $TERM struct .
+
###### variable grammar
| Variable . IDENTIFIER ${ {
###### Grammar
+ $TERM True False
+
$*val
Value -> True ${
$0 = new_val(Tbool, $1);
###### Grammar
+ $TERM : ::
+
$*var
VariableDecl -> IDENTIFIER : ${ {
struct variable *v = var_decl(c, $1.txt);
###### Binode types
Block,
-###### expr precedence
- $TERM pass
-
###### Grammar
+ $TERM { } ;
+
$*binode
Block -> { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
| { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
$0->right = $<1;
}$
+ $TERM pass
SimpleStatement -> pass ${ $0 = NULL; }$
| ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$
## SimpleStatement Grammar
Assign,
Declare,
+###### declare terminals
+ $TERM =
+
###### SimpleStatement Grammar
| Variable = Expression ${
$0 = new(binode);
$void
Ocean -> OptNL DeclarationList
+ ## declare terminals
+
OptNL ->
| OptNL NEWLINE
Newlines -> NEWLINE
###### top level grammar
+ $TERM const
+
DeclareConstant -> const { IN OptNL ConstList OUT OptNL } Newlines
| const { SimpleConstList } Newlines
| const IN OptNL ConstList OUT Newlines
c->prog = $<1;
} }$
+ $TERM program
+
$*binode
Program -> program OpenScope Varlist ColonBlock Newlines ${
$0 = new(binode);
tk = token_next(state);
while (tk.num == TK_ident || tk.num == TK_mark) {
struct symbol *bs = sym_find(g, tk.txt);
- if (bs->type == Unknown) {
- if (!g->terminals_declared)
- bs->type = Terminal;
- }
if (bs->type == Virtual) {
err = "Virtual symbol not permitted in production";
goto abort;
goto abort;
}
token_close(state);
- if (g->terminals_declared) {
- struct symbol *s;
- int errs = 0;
- for (s = g->syms; s; s = s->next) {
- if (s->type != Unknown)
- continue;
- errs += 1;
- fprintf(stderr, "Token %.*s not declared\n",
- s->name.len, s->name.txt);
- }
- if (errs) {
- free(g); // FIXME free content
- g = NULL;
+
+ struct symbol *s;
+ for (s = g->syms; s; s = s->next) {
+ if (s->type != Unknown)
+ continue;
+ if (!g->terminals_declared) {
+ s->type = Terminal;
+ continue;
}
+ err = "not declared";
+ fprintf(stderr, "Token %.*s not declared\n",
+ s->name.len, s->name.txt);
+ }
+ if (err) {
+ free(g); // FIXME free content
+ g = NULL;
}
return g;
abort: