summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/astnode.cpp54
-rw-r--r--src/astnode.h6
-rw-r--r--src/parser.y20
-rw-r--r--test.stage14
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 )
19{ 19{
20 switch( t ) 20 switch( t )
21 { 21 {
22 case AstNode::tLeaf: return f << "!tLeaf!"; 22 case AstNode::tLeaf: return f << "!tLeaf!";
23 case AstNode::tNot: return f << "tNot"; 23 case AstNode::tNot: return f << "tNot";
24 case AstNode::tComp: return f << "tComp"; 24 case AstNode::tComp: return f << "tComp";
25 case AstNode::tCompGt: return f << "tCompGt"; 25 case AstNode::tCompGt: return f << "tCompGt";
26 case AstNode::tCompLt: return f << "tCompLt"; 26 case AstNode::tCompLt: return f << "tCompLt";
27 case AstNode::tCompGtEq: return f << "tCompGtEq"; 27 case AstNode::tCompGtEq: return f << "tCompGtEq";
28 case AstNode::tCompLtEq: return f << "tCompLtEq"; 28 case AstNode::tCompLtEq: return f << "tCompLtEq";
29 case AstNode::tStore: return f << "tStore"; 29 case AstNode::tStore: return f << "tStore";
30 case AstNode::tAnd: return f << "tAnd"; 30 case AstNode::tAnd: return f << "tAnd";
31 case AstNode::tOr: return f << "tOr"; 31 case AstNode::tOr: return f << "tOr";
32 case AstNode::tPlus: return f << "tPlus"; 32 case AstNode::tPlus: return f << "tPlus";
33 case AstNode::tMinus: return f << "tMinus"; 33 case AstNode::tMinus: return f << "tMinus";
34 case AstNode::tDivide: return f << "tDivide"; 34 case AstNode::tDivide: return f << "tDivide";
35 case AstNode::tMultiply: return f << "tMultiply"; 35 case AstNode::tMultiply: return f << "tMultiply";
36 case AstNode::tPlusStore: return f << "tPlusStore";
37 case AstNode::tMinusStore: return f << "tMinusStore";
38 case AstNode::tDivideStore: return f << "tDivideStore";
39 case AstNode::tMultiplyStore: return f << "tMultiplyStore";
40 case AstNode::tNegate: return f << "tNegate";
41 case AstNode::tIn: return f << "tIn";
36 42
37 case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; 43 case AstNode::tLeafLiteral: return f << "!tLeafLiteral!";
38 case AstNode::tVarName: return f << "tVarName"; 44 case AstNode::tVarName: return f << "tVarName";
39 case AstNode::tLiteral: return f << "tLiteral"; 45 case AstNode::tLiteral: return f << "tLiteral";
40 case AstNode::tFuncName: return f << "tFuncName"; 46 case AstNode::tFuncName: return f << "tFuncName";
41 47
42 case AstNode::tBranch: return f << "!tBranch!"; 48 case AstNode::tBranch: return f << "!tBranch!";
43 case AstNode::tScope: return f << "tScope"; 49 case AstNode::tScope: return f << "tScope";
44 case AstNode::tIf: return f << "tIf"; 50 case AstNode::tIf: return f << "tIf";
45 case AstNode::tForEach: return f << "tForEach"; 51 case AstNode::tForEach: return f << "tForEach";
46 case AstNode::tWhile: return f << "tWhile"; 52 case AstNode::tWhile: return f << "tWhile";
47 53
48 case AstNode::tTypeMask: return f << "!tTypeMask!"; 54 case AstNode::tTypeMask: return f << "!tTypeMask!";
49 } 55 }
50 56
51 return f << "???"; 57 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:
23 tMinus = 0x0100000B, 23 tMinus = 0x0100000B,
24 tDivide = 0x0100000C, 24 tDivide = 0x0100000C,
25 tMultiply = 0x0100000D, 25 tMultiply = 0x0100000D,
26 tPlusStore = 0x0100000E,
27 tMinusStore = 0x0100000F,
28 tDivideStore = 0x01000010,
29 tMultiplyStore = 0x01000011,
30 tNegate = 0x01000012,
31 tIn = 0x01000013,
26 32
27 tLeafLiteral = 0x02000000, 33 tLeafLiteral = 0x02000000,
28 tVarName = 0x02000001, 34 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
78 78
79%token eos 0 "end of stream" 79%token eos 0 "end of stream"
80 80
81%right tokNot 81%left NOT
82%right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign 82%right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign
83%left '-' '+' 83%left '-' '+'
84%left '*' '/' 84%left '*' '/'
85%left tokIn tokAnd tokOr 85%left tokIn tokAnd tokOr
86%right '<' '>' tokLtEq tokGtEq tokCmp 86%right '<' '>' tokLtEq tokGtEq tokCmp
87%left '(' ')' '[' ']' 87%left '(' ')' '[' ']'
88%left NEG
88 89
89%% 90%%
90input: gameDecls globalDecl bodyDecl 91input: gameDecls globalDecl bodyDecl
@@ -200,17 +201,17 @@ expr: literal
200 | tokIdent '(' listValues ')' 201 | tokIdent '(' listValues ')'
201 | varRef 202 | varRef
202 | varRef '=' expr { bld.addNode( AstNode::tStore ); } 203 | varRef '=' expr { bld.addNode( AstNode::tStore ); }
203 | varRef tokPlusAssign expr 204 | varRef tokPlusAssign expr { bld.addNode( AstNode::tPlusStore ); }
204 | varRef tokMinusAssign expr 205 | varRef tokMinusAssign expr { bld.addNode( AstNode::tMinusStore ); }
205 | varRef tokTimesAssign expr 206 | varRef tokTimesAssign expr { bld.addNode( AstNode::tMultiplyStore ); }
206 | varRef tokDivideAssign expr 207 | varRef tokDivideAssign expr { bld.addNode( AstNode::tDivideStore ); }
207 | expr '+' expr { bld.addNode( AstNode::tPlus ); } 208 | expr '+' expr { bld.addNode( AstNode::tPlus ); }
208 | expr '-' expr { bld.addNode( AstNode::tMinus ); } 209 | expr '-' expr { bld.addNode( AstNode::tMinus ); }
209 | expr '/' expr { bld.addNode( AstNode::tDivide ); } 210 | expr '/' expr { bld.addNode( AstNode::tDivide ); }
210 | expr '*' expr { bld.addNode( AstNode::tMultiply ); } 211 | expr '*' expr { bld.addNode( AstNode::tMultiply ); }
211 | expr tokAnd expr 212 | expr tokAnd expr { bld.addNode( AstNode::tAnd ); }
212 | expr tokOr expr 213 | expr tokOr expr { bld.addNode( AstNode::tOr ); }
213 | expr tokIn expr 214 | expr tokIn expr { bld.addNode( AstNode::tIn ); }
214 | expr tokCmp expr { bld.addNode( AstNode::tComp ); } 215 | expr tokCmp expr { bld.addNode( AstNode::tComp ); }
215 | expr '<' expr { bld.addNode( AstNode::tCompLt ); } 216 | expr '<' expr { bld.addNode( AstNode::tCompLt ); }
216 | expr '>' expr { bld.addNode( AstNode::tCompGt ); } 217 | expr '>' expr { bld.addNode( AstNode::tCompGt ); }
@@ -222,7 +223,8 @@ expr: literal
222 | '[' listValues ']' 223 | '[' listValues ']'
223 | '{' '}' 224 | '{' '}'
224 | '{' dictValues '}' 225 | '{' dictValues '}'
225 | tokNot expr 226 | tokNot expr %prec NOT { bld.addNode( AstNode::tNot ); }
227 | '-' expr %prec NEG { bld.addNode( AstNode::tNegate ); }
226 ; 228 ;
227 229
228listValues: expr 230listValues: expr
diff --git a/test.stage b/test.stage
index a1c6ab3..a705c93 100644
--- a/test.stage
+++ b/test.stage
@@ -11,18 +11,6 @@ global
11 11
12function hello( a, b, c ) 12function hello( a, b, c )
13{ 13{
14 joe = a; 14 a[x][y];
15 if b < c then
16 {
17 sam = b * c + 1;
18 }
19 else if something <= c then
20 {
21 x * 43;
22 }
23 while true do
24 {
25 bob = 5 + 55 * 2 + 1;
26 }
27} 15}
28 16