diff options
Diffstat (limited to 'src/parser.y')
-rw-r--r-- | src/parser.y | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/parser.y b/src/parser.y index e2f8b6d..95bd00d 100644 --- a/src/parser.y +++ b/src/parser.y | |||
@@ -37,6 +37,8 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
37 | %token tokGame | 37 | %token tokGame |
38 | %token tokFunction | 38 | %token tokFunction |
39 | %token tokSituation | 39 | %token tokSituation |
40 | %token tokSetup | ||
41 | %token tokEnter | ||
40 | %token tokWhile | 42 | %token tokWhile |
41 | %token tokFor | 43 | %token tokFor |
42 | %token tokEach | 44 | %token tokEach |
@@ -47,6 +49,13 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
47 | %token tokNot | 49 | %token tokNot |
48 | %token tokCommand | 50 | %token tokCommand |
49 | %token tokPlayer | 51 | %token tokPlayer |
52 | %token tokLtEq | ||
53 | %token tokGtEq | ||
54 | %token tokCmp | ||
55 | %token tokPlusAssign | ||
56 | %token tokMinusAssign | ||
57 | %token tokTimesAssign | ||
58 | %token tokDivideAssign | ||
50 | %token <sValue> tokSituationName | 59 | %token <sValue> tokSituationName |
51 | %token <sValue> tokIdent | 60 | %token <sValue> tokIdent |
52 | %token tokGoto | 61 | %token tokGoto |
@@ -60,7 +69,9 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
60 | 69 | ||
61 | %token eos 0 "end of stream" | 70 | %token eos 0 "end of stream" |
62 | 71 | ||
63 | %right '=' | 72 | %right tokNot |
73 | %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign | ||
74 | %right tokLtEq tokGtEq tokCmp | ||
64 | %left tokIn | 75 | %left tokIn |
65 | %left '(' ')' '[' ']' | 76 | %left '(' ')' '[' ']' |
66 | %left '*' '/' | 77 | %left '*' '/' |
@@ -89,9 +100,21 @@ bodyDecl: | |||
89 | | bodyDecl function | 100 | | bodyDecl function |
90 | ; | 101 | ; |
91 | 102 | ||
92 | situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' cmpltExprList '}' | 103 | situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' situationMembers '}' |
93 | ; | 104 | ; |
94 | 105 | ||
106 | situationMembers: | ||
107 | | situationMembers situationModeFunc | ||
108 | | situationMembers commandDecl | ||
109 | ; | ||
110 | |||
111 | situationModeFunc: situationMode '{' cmpltExprList '}' | ||
112 | ; | ||
113 | |||
114 | situationMode: tokSetup | ||
115 | | tokEnter | ||
116 | ; | ||
117 | |||
95 | function: tokFunction tokIdent '(' ')' '{' '}' | 118 | function: tokFunction tokIdent '(' ')' '{' '}' |
96 | ; | 119 | ; |
97 | 120 | ||
@@ -109,15 +132,24 @@ ifnext: | |||
109 | | tokElse tokIf '{' cmpltExprList '}' ifnext | 132 | | tokElse tokIf '{' cmpltExprList '}' ifnext |
110 | ; | 133 | ; |
111 | 134 | ||
135 | varRef: tokIdent | ||
136 | | tokPlayer '.' tokIdent | ||
137 | | tokSituation '.' tokIdent | ||
138 | ; | ||
139 | |||
112 | expr: tokInt | 140 | expr: tokInt |
113 | | tokFloat | 141 | | tokFloat |
114 | | tokString | 142 | | tokString |
115 | | tokBool | 143 | | tokBool |
116 | | tokNull | 144 | | tokNull |
117 | | tokIdent | 145 | | tokIdent '(' listValues ')' |
146 | | varRef | ||
147 | | varRef '=' expr | ||
148 | | varRef tokPlusAssign expr | ||
149 | | varRef tokMinusAssign expr | ||
150 | | varRef tokTimesAssign expr | ||
151 | | varRef tokDivideAssign expr | ||
118 | | tokSituationName | 152 | | tokSituationName |
119 | | tokSituation '.' tokIdent | ||
120 | | tokPlayer '.' tokIdent | ||
121 | | expr '+' expr | 153 | | expr '+' expr |
122 | | expr '-' expr | 154 | | expr '-' expr |
123 | | expr '/' expr | 155 | | expr '/' expr |
@@ -129,7 +161,7 @@ expr: tokInt | |||
129 | | '[' listValues ']' | 161 | | '[' listValues ']' |
130 | | '{' '}' | 162 | | '{' '}' |
131 | | '{' dictValues '}' | 163 | | '{' dictValues '}' |
132 | /* | tokNot expr */ | 164 | | tokNot expr |
133 | ; | 165 | ; |
134 | 166 | ||
135 | listValues: expr | 167 | listValues: expr |