From 40e08192a08f55b5090d5ef28f48c74613e2e5a0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 27 Dec 2011 00:32:12 -0700 Subject: Wow, a whole lot of code builds now. --- src/parser.y | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index 7993927..fbada5a 100644 --- a/src/parser.y +++ b/src/parser.y @@ -80,10 +80,10 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, GameBuilder &, const char *err %right tokNot %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign -%right tokLtEq tokGtEq tokCmp %left '-' '+' %left '*' '/' %left tokIn tokAnd tokOr +%right '<' '>' tokLtEq tokGtEq tokCmp %left '(' ')' '[' ']' %% @@ -146,17 +146,40 @@ cmpltExprList: cmpltExpr: expr ';' | tokGoto '(' expr ')' ';' - | tokIf expr tokThen '{' cmpltExprList '}' ifnext + | ifbase | tokFor tokEach forIterator tokIn expr tokDo '{' cmpltExprList '}' - | tokWhile expr tokDo '{' cmpltExprList '}' + | tokWhile { + bld.addNode( AstNode::tWhile ); + bld.addNode( AstNode::tScope ); + } expr { + bld.closeNode(); + bld.addNode( AstNode::tScope ); + } tokDo '{' cmpltExprList '}' { + bld.closeNode(); bld.closeNode(); + } ; forIterator: tokIdent | tokIdent ':' tokIdent +ifbase: tokIf { + bld.addNode( AstNode::tIf ); + bld.addNode( AstNode::tScope ); + } expr { + bld.closeNode(); + bld.addNode( AstNode::tScope ); + } tokThen '{' cmpltExprList '}' { + bld.closeNode(); + } ifnext { + bld.closeNode(); + } + ; + ifnext: - | tokElse '{' cmpltExprList '}' - | tokElse tokIf '{' cmpltExprList '}' ifnext + | tokElse { bld.addNode( AstNode::tScope ); } '{' cmpltExprList '}' { + bld.closeNode(); + } + | tokElse { bld.addNode( AstNode::tScope ); } ifbase ; varRef: tokIdent { bld.addVarRef( *($1) ); } @@ -177,17 +200,22 @@ expr: literal | tokIdent '(' listValues ')' | varRef | varRef '=' expr { bld.addNode( AstNode::tStore ); } - | varRef tokPlusAssign expr + | varRef tokPlusAssign expr | varRef tokMinusAssign expr | varRef tokTimesAssign expr | varRef tokDivideAssign expr - | expr '+' expr { printf(" + plus\n"); } - | expr '-' expr { printf(" + minus\n"); } - | expr '/' expr { printf(" + divide\n"); } - | expr '*' expr { printf(" + times\n"); } + | expr '+' expr { bld.addNode( AstNode::tPlus ); } + | expr '-' expr { bld.addNode( AstNode::tMinus ); } + | expr '/' expr { bld.addNode( AstNode::tDivide ); } + | expr '*' expr { bld.addNode( AstNode::tMultiply ); } | expr tokAnd expr | expr tokOr expr | expr tokIn expr + | expr tokCmp expr { bld.addNode( AstNode::tComp ); } + | expr '<' expr { bld.addNode( AstNode::tCompLt ); } + | expr '>' expr { bld.addNode( AstNode::tCompGt ); } + | expr tokLtEq expr { bld.addNode( AstNode::tCompLtEq ); } + | expr tokGtEq expr { bld.addNode( AstNode::tCompGtEq ); } | '(' expr ')' | expr '[' expr ']' | '[' ']' -- cgit v1.2.3