From 550d4f13ace49e3d442e43d46cd066f174709400 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 27 Dec 2011 00:50:23 -0700 Subject: more and more making it into the Ast. --- src/astnode.cpp | 54 ++++++++++++++++++++++++++++++------------------------ src/astnode.h | 6 ++++++ src/parser.y | 20 +++++++++++--------- test.stage | 14 +------------- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/astnode.cpp b/src/astnode.cpp index 18ce122..6e59ab6 100644 --- a/src/astnode.cpp +++ b/src/astnode.cpp @@ -19,33 +19,39 @@ Bu::Formatter &operator<<( Bu::Formatter &f, AstNode::Type t ) { switch( t ) { - case AstNode::tLeaf: return f << "!tLeaf!"; - case AstNode::tNot: return f << "tNot"; - case AstNode::tComp: return f << "tComp"; - case AstNode::tCompGt: return f << "tCompGt"; - case AstNode::tCompLt: return f << "tCompLt"; - case AstNode::tCompGtEq: return f << "tCompGtEq"; - case AstNode::tCompLtEq: return f << "tCompLtEq"; - case AstNode::tStore: return f << "tStore"; - case AstNode::tAnd: return f << "tAnd"; - case AstNode::tOr: return f << "tOr"; - case AstNode::tPlus: return f << "tPlus"; - case AstNode::tMinus: return f << "tMinus"; - case AstNode::tDivide: return f << "tDivide"; - case AstNode::tMultiply: return f << "tMultiply"; + case AstNode::tLeaf: return f << "!tLeaf!"; + case AstNode::tNot: return f << "tNot"; + case AstNode::tComp: return f << "tComp"; + case AstNode::tCompGt: return f << "tCompGt"; + case AstNode::tCompLt: return f << "tCompLt"; + case AstNode::tCompGtEq: return f << "tCompGtEq"; + case AstNode::tCompLtEq: return f << "tCompLtEq"; + case AstNode::tStore: return f << "tStore"; + case AstNode::tAnd: return f << "tAnd"; + case AstNode::tOr: return f << "tOr"; + case AstNode::tPlus: return f << "tPlus"; + case AstNode::tMinus: return f << "tMinus"; + case AstNode::tDivide: return f << "tDivide"; + case AstNode::tMultiply: return f << "tMultiply"; + case AstNode::tPlusStore: return f << "tPlusStore"; + case AstNode::tMinusStore: return f << "tMinusStore"; + case AstNode::tDivideStore: return f << "tDivideStore"; + case AstNode::tMultiplyStore: return f << "tMultiplyStore"; + case AstNode::tNegate: return f << "tNegate"; + case AstNode::tIn: return f << "tIn"; - case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; - case AstNode::tVarName: return f << "tVarName"; - case AstNode::tLiteral: return f << "tLiteral"; - case AstNode::tFuncName: return f << "tFuncName"; + case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; + case AstNode::tVarName: return f << "tVarName"; + case AstNode::tLiteral: return f << "tLiteral"; + case AstNode::tFuncName: return f << "tFuncName"; - case AstNode::tBranch: return f << "!tBranch!"; - case AstNode::tScope: return f << "tScope"; - case AstNode::tIf: return f << "tIf"; - case AstNode::tForEach: return f << "tForEach"; - case AstNode::tWhile: return f << "tWhile"; + case AstNode::tBranch: return f << "!tBranch!"; + case AstNode::tScope: return f << "tScope"; + case AstNode::tIf: return f << "tIf"; + case AstNode::tForEach: return f << "tForEach"; + case AstNode::tWhile: return f << "tWhile"; - case AstNode::tTypeMask: return f << "!tTypeMask!"; + case AstNode::tTypeMask: return f << "!tTypeMask!"; } return f << "???"; diff --git a/src/astnode.h b/src/astnode.h index abbcaaf..b38b895 100644 --- a/src/astnode.h +++ b/src/astnode.h @@ -23,6 +23,12 @@ public: tMinus = 0x0100000B, tDivide = 0x0100000C, tMultiply = 0x0100000D, + tPlusStore = 0x0100000E, + tMinusStore = 0x0100000F, + tDivideStore = 0x01000010, + tMultiplyStore = 0x01000011, + tNegate = 0x01000012, + tIn = 0x01000013, tLeafLiteral = 0x02000000, tVarName = 0x02000001, diff --git a/src/parser.y b/src/parser.y index fbada5a..90c771d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -78,13 +78,14 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, GameBuilder &, const char *err %token eos 0 "end of stream" -%right tokNot +%left NOT %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign %left '-' '+' %left '*' '/' %left tokIn tokAnd tokOr %right '<' '>' tokLtEq tokGtEq tokCmp %left '(' ')' '[' ']' +%left NEG %% input: gameDecls globalDecl bodyDecl @@ -200,17 +201,17 @@ expr: literal | tokIdent '(' listValues ')' | varRef | varRef '=' expr { bld.addNode( AstNode::tStore ); } - | varRef tokPlusAssign expr - | varRef tokMinusAssign expr - | varRef tokTimesAssign expr - | varRef tokDivideAssign expr + | varRef tokPlusAssign expr { bld.addNode( AstNode::tPlusStore ); } + | varRef tokMinusAssign expr { bld.addNode( AstNode::tMinusStore ); } + | varRef tokTimesAssign expr { bld.addNode( AstNode::tMultiplyStore ); } + | varRef tokDivideAssign expr { bld.addNode( AstNode::tDivideStore ); } | 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 tokAnd expr { bld.addNode( AstNode::tAnd ); } + | expr tokOr expr { bld.addNode( AstNode::tOr ); } + | expr tokIn expr { bld.addNode( AstNode::tIn ); } | expr tokCmp expr { bld.addNode( AstNode::tComp ); } | expr '<' expr { bld.addNode( AstNode::tCompLt ); } | expr '>' expr { bld.addNode( AstNode::tCompGt ); } @@ -222,7 +223,8 @@ expr: literal | '[' listValues ']' | '{' '}' | '{' dictValues '}' - | tokNot expr + | tokNot expr %prec NOT { bld.addNode( AstNode::tNot ); } + | '-' expr %prec NEG { bld.addNode( AstNode::tNegate ); } ; listValues: expr diff --git a/test.stage b/test.stage index a1c6ab3..a705c93 100644 --- a/test.stage +++ b/test.stage @@ -11,18 +11,6 @@ global function hello( a, b, c ) { - joe = a; - if b < c then - { - sam = b * c + 1; - } - else if something <= c then - { - x * 43; - } - while true do - { - bob = 5 + 55 * 2 + 1; - } + a[x][y]; } -- cgit v1.2.3