diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2024-02-19 03:42:42 -0800 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2024-02-19 03:42:42 -0800 |
commit | e133f250761c67b4465181f41909e78c272901d3 (patch) | |
tree | fc75f55dd2a3f4dddc589a8c259f887e90ef3a1e /grammars | |
parent | ffc6388571004b17e3a3dee2511ec99076ee803a (diff) |
Parse trees, dangling else, etc.
Diffstat (limited to 'grammars')
-rw-r--r-- | grammars/c/disambiguate.c | 11 | ||||
-rw-r--r-- | grammars/c/grammar.txt | 43 |
2 files changed, 48 insertions, 6 deletions
diff --git a/grammars/c/disambiguate.c b/grammars/c/disambiguate.c index 9a8bf08..a2d69d1 100644 --- a/grammars/c/disambiguate.c +++ b/grammars/c/disambiguate.c @@ -1,8 +1,8 @@ int disambiguator(struct state *old, struct state *new) { - // printf("Old tree: "); - // print_parse_tree2(old); - // printf("New tree: "); - // print_parse_tree2(new); + // printf("Old tree:\n"); + // print_parse_tree(old, 4); + // printf("New tree:\n"); + // print_parse_tree(new, 4); if (old->start_idx != new->start_idx) { // printf("\t\tIGNORING "); print_parse_tree2(old); @@ -44,6 +44,7 @@ int disambiguator(struct state *old, struct state *new) { } } } - printf("TOTALLY UNKNOWN!\n"); + + fprintf(stderr, "TOTALLY UNKNOWN!\n"); return 2; } diff --git a/grammars/c/grammar.txt b/grammars/c/grammar.txt index 486f319..7959318 100644 --- a/grammars/c/grammar.txt +++ b/grammars/c/grammar.txt @@ -7,7 +7,7 @@ IDENT regex INT regex [0-9]+ -OPS list +OP list ( ) { } [ ] ; , - + ! % * & / << >> ^ | @@ -15,3 +15,44 @@ OPS list && || ++ -- < <= > >= = . -> ? : + +EXPR nonterm + INT + IDENT + EXPR -- + EXPR ++ + EXPR OP EXPR + EXPR ? EXPR : EXPR + +IF nonterm + if ( EXPR ) BLOCK + if ( EXPR ) BLOCK else BLOCK + +WHILE nonterm + while ( EXPR ) BLOCK + +DO nonterm + do BLOCK while ( EXPR ) + +FOR nonterm + for ( EXPR ; EXPR ; EXPR ) BLOCK + +SWITCH nonterm + switch ( EXPR ) BLOCK + +STMT nonterm + IF + WHILE + DO + FOR + SWITCH + EXPR ; + +STMTS nonterm .start + STMT + STMT STMTS + +BLOCK nonterm + { } + { STMTS } + STMT |