summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo.stage10
-rw-r--r--src/parser.l5
-rw-r--r--src/parser.y40
3 files changed, 36 insertions, 19 deletions
diff --git a/demo.stage b/demo.stage
index 58aee3e..e51c160 100644
--- a/demo.stage
+++ b/demo.stage
@@ -1,8 +1,12 @@
1 1
2game 2game.title = "Demo game";
3{ 3game.author = "Mike Buland";
4 title = "Demo game"; 4game.version = 1;
5game.revision = 0;
6game.start = <<start>>;
5 7
8global
9{
6 command: "take" item 10 command: "take" item
7 { 11 {
8 if item in situation.items then 12 if item in situation.items then
diff --git a/src/parser.l b/src/parser.l
index 841c5e6..9e031eb 100644
--- a/src/parser.l
+++ b/src/parser.l
@@ -29,6 +29,7 @@
29[-{}<>=+/*,();:.[\]] { return yytext[0]; } 29[-{}<>=+/*,();:.[\]] { return yytext[0]; }
30 30
31game { return tokGame; } 31game { return tokGame; }
32global { return tokGlobal; }
32function { return tokFunction; } 33function { return tokFunction; }
33situation { return tokSituation; } 34situation { return tokSituation; }
34player { return tokPlayer; } 35player { return tokPlayer; }
@@ -66,6 +67,10 @@ null { return tokNull; }
66 yylval->iValue = strtoll( yytext, NULL, 10 ); 67 yylval->iValue = strtoll( yytext, NULL, 10 );
67 return tokInt; 68 return tokInt;
68} 69}
700 {
71 yylval->iValue = 0;
72 return tokInt;
73}
69 74
70([1-9][0-9]*)?\.[0-9]* { 75([1-9][0-9]*)?\.[0-9]* {
71 yylval->dValue = strtod( yytext, NULL ); 76 yylval->dValue = strtod( yytext, NULL );
diff --git a/src/parser.y b/src/parser.y
index 95bd00d..ef9d10b 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -35,6 +35,7 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error )
35%} 35%}
36 36
37%token tokGame 37%token tokGame
38%token tokGlobal
38%token tokFunction 39%token tokFunction
39%token tokSituation 40%token tokSituation
40%token tokSetup 41%token tokSetup
@@ -78,22 +79,26 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error )
78%left '-' '+' 79%left '-' '+'
79 80
80%% 81%%
81input: gameDecl bodyDecl 82input: gameDecls globalDecl bodyDecl
82 ; 83 ;
83 84
84gameDecl: tokGame '{' gameExprList '}' 85gameDecls:
86 | gameDecls tokGame '.' tokIdent '=' literal ';'
87 ;
88
89globalDecl: tokGlobal '{' globalExprList '}'
85 ; 90 ;
86 91
87gameExprList: 92globalExprList:
88 | gameExprList cmpltGameExpr 93 | globalExprList cmpltGlobalExpr
89 ; 94 ;
90 95
91cmpltGameExpr: gameExpr ';' 96cmpltGlobalExpr: globalExpr ';'
92 | commandDecl 97 | commandDecl
93 ; 98 ;
94 99
95gameExpr: tokIdent '=' expr 100globalExpr: tokIdent '=' expr
96 ; 101 ;
97 102
98bodyDecl: 103bodyDecl:
99 | bodyDecl situation 104 | bodyDecl situation
@@ -137,11 +142,15 @@ varRef: tokIdent
137 | tokSituation '.' tokIdent 142 | tokSituation '.' tokIdent
138 ; 143 ;
139 144
140expr: tokInt 145literal: tokInt
141 | tokFloat 146 | tokFloat
142 | tokString 147 | tokString
143 | tokBool 148 | tokBool
144 | tokNull 149 | tokNull
150 | tokSituationName
151 ;
152
153expr: literal
145 | tokIdent '(' listValues ')' 154 | tokIdent '(' listValues ')'
146 | varRef 155 | varRef
147 | varRef '=' expr 156 | varRef '=' expr
@@ -149,7 +158,6 @@ expr: tokInt
149 | varRef tokMinusAssign expr 158 | varRef tokMinusAssign expr
150 | varRef tokTimesAssign expr 159 | varRef tokTimesAssign expr
151 | varRef tokDivideAssign expr 160 | varRef tokDivideAssign expr
152 | tokSituationName
153 | expr '+' expr 161 | expr '+' expr
154 | expr '-' expr 162 | expr '-' expr
155 | expr '/' expr 163 | expr '/' expr