From 79144dfebb2680ce8863dd1717e3adade53f8aaf Mon Sep 17 00:00:00 2001 From: mtardy Date: Wed, 5 Aug 2020 14:38:14 +0200 Subject: [PATCH] Move statement rule and fix identation --- object.c | 6 +++--- parse.leg | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/object.c b/object.c index 62b3de7..f5f34e2 100644 --- a/object.c +++ b/object.c @@ -219,9 +219,9 @@ int oopcmp(oop a, oop b) case String: return strcmp(get(a, String, value), get(b, String, value)); default: - if (a < b) return -1; - if (a > b) return 1; - return 0; + if (a < b) return -1; + if (a > b) return 1; + return 0; } } return ta - tb; diff --git a/parse.leg b/parse.leg index 3248f84..5491af5 100644 --- a/parse.leg +++ b/parse.leg @@ -299,7 +299,8 @@ YYSTYPE yylval; start = - e:stmt { yylval = e } -stmt = e:exp SEMICOLON* { $$= e } +stmt = e:exp SEMICOLON* { $$ = e } + | s:compoundStatement { $$ = newCompoundStatement(s) } exp = VAR l:IDENT ASSIGN e:exp { $$ = newDeclaration(l, e) } | VAR l:IDENT { $$ = newDeclaration(l, null) } @@ -308,14 +309,13 @@ exp = VAR l:IDENT ASSIGN e:exp { $$ = newDeclarati | IF LPAREN c:exp RPAREN t:stmt ELSE f:stmt { $$ = newIf(c, t, f ) } | IF LPAREN c:exp RPAREN t:stmt { $$ = newIf(c, t, null) } | WHILE LPAREN c:exp RPAREN e:stmt { $$ = newWhile(c, e) } - | s:compoundStatement { $$ = newCompoundStatement(s) } | l:IDENT ASSIGN e:exp { $$ = newAssign(l, e) } | l:postfix DOT i:IDENT ASSIGN e:exp { $$ = newSetMember(l, i, e) } | l:postfix LBRAC i:exp RBRAC ASSIGN e:exp { $$ = newSetIndex(l, i, e) } | c:cond { $$ = c } compoundStatement = LCB m:makeMap - ( e:exp { map_append(m, e) } + ( s:stmt { map_append(m, s) } ) * RCB { $$ = m } @@ -707,10 +707,8 @@ oop prim_exit(oop params) oop prim_print(oop params) { assert(is(Map, params)); - for (int i= 0; i < get(params, Map, size); ++i) { - oop key= get(params, Map, elements)[i].key; - if (!is(Integer, key) || (i != get(key, Integer, value))) break; - print(get(params, Map, elements)[i].value); + for (int i= 0; map_hasIntegerKey(params, i); ++i) { + print(get(params, Map, elements)[i].value); } printf("\n"); return params;