diff options
author | David Walter Seikel | 2012-01-16 08:09:38 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-16 08:09:38 +1000 |
commit | d4f11607844b2a8f68e7060dedbebc20c90bec6b (patch) | |
tree | f456c3440473db02e13d0021a3f185afc73849c1 | |
parent | Add a proper LSL file for easy testing. (diff) | |
download | SledjHamr-d4f11607844b2a8f68e7060dedbebc20c90bec6b.zip SledjHamr-d4f11607844b2a8f68e7060dedbebc20c90bec6b.tar.gz SledjHamr-d4f11607844b2a8f68e7060dedbebc20c90bec6b.tar.bz2 SledjHamr-d4f11607844b2a8f68e7060dedbebc20c90bec6b.tar.xz |
Parser now parses a real script to completion with no syntax errors! B-)
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 160 |
1 files changed, 88 insertions, 72 deletions
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 83aff23..06c534d 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -4,15 +4,69 @@ | |||
4 | 4 | ||
5 | %extra_argument {LuaSL_yyparseParam *param} | 5 | %extra_argument {LuaSL_yyparseParam *param} |
6 | 6 | ||
7 | %stack_size 256 | 7 | %stack_size 1024 |
8 | 8 | ||
9 | %token_type {LSL_Leaf *} | 9 | %token_type {LSL_Leaf *} |
10 | %default_type {LSL_Leaf *} | 10 | %default_type {LSL_Leaf *} |
11 | %token_destructor {burnLeaf($$);} | 11 | %token_destructor {burnLeaf($$);} |
12 | %default_destructor {burnLeaf($$);} | ||
12 | 13 | ||
13 | 14 | ||
14 | program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } // Lemon does not like the start symbol to be on the RHS, so give it a dummy one. | 15 | program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } // Lemon does not like the start symbol to be on the RHS, so give it a dummy one. |
15 | 16 | ||
17 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_UNKNOWN. | ||
18 | |||
19 | %nonassoc LSL_SCRIPT. | ||
20 | script ::= script state. | ||
21 | script ::= script function. | ||
22 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | ||
23 | script ::= . | ||
24 | |||
25 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. | ||
26 | state ::= LSL_IDENTIFIER stateBlock. | ||
27 | |||
28 | %nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE. | ||
29 | parameter ::= type LSL_IDENTIFIER. | ||
30 | parameterList ::= parameterList LSL_COMMA parameter. | ||
31 | parameterList ::= parameter. | ||
32 | parameterList ::= . | ||
33 | function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. | ||
34 | function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. | ||
35 | functionList ::= functionList function. | ||
36 | functionList ::= . | ||
37 | |||
38 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. | ||
39 | funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. | ||
40 | block ::= funcBlock. | ||
41 | block ::= statement. | ||
42 | |||
43 | %nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. | ||
44 | %nonassoc LSL_ELSE. | ||
45 | statement ::= LSL_DO block LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE LSL_STATEMENT. | ||
46 | statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_STATEMENT expr LSL_STATEMENT expr LSL_PARENTHESIS_CLOSE block. | ||
47 | |||
48 | ifBlock ::= ifBlock LSL_ELSE block. | ||
49 | ifBlock ::= block. | ||
50 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE] | ||
51 | |||
52 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. | ||
53 | statement ::= LSL_RETURN expr LSL_STATEMENT. | ||
54 | statement ::= LSL_RETURN LSL_STATEMENT. | ||
55 | statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT. | ||
56 | statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block. | ||
57 | |||
58 | %nonassoc LSL_LABEL. | ||
59 | target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT. | ||
60 | |||
61 | %nonassoc LSL_STATEMENT. | ||
62 | statement ::= target LSL_STATEMENT. | ||
63 | statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT. | ||
64 | statement ::= type LSL_IDENTIFIER LSL_STATEMENT. | ||
65 | statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); } | ||
66 | |||
67 | statementList ::= statementList statement. | ||
68 | statementList ::= . | ||
69 | |||
16 | %right LSL_BOOL_AND. | 70 | %right LSL_BOOL_AND. |
17 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } | 71 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } |
18 | %right LSL_BOOL_OR. | 72 | %right LSL_BOOL_OR. |
@@ -63,30 +117,29 @@ type ::= LSL_TYPE_VECTOR. | |||
63 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. | 117 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. |
64 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. | 118 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. |
65 | 119 | ||
66 | exprList ::= exprList LSL_COMMA expr. | ||
67 | exprList ::= expr. | ||
68 | exprList ::= . | ||
69 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. | ||
70 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } | 120 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } |
71 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } | 121 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } |
72 | 122 | ||
123 | %right LSL_DOT LSL_IDENTIFIER. | ||
124 | identifier ::= identifier LSL_DOT LSL_IDENTIFIER. | ||
125 | identifier ::= LSL_IDENTIFIER. | ||
126 | |||
127 | expr ::= identifier. | ||
128 | |||
73 | %right LSL_ASSIGNMENT_CONCATENATE LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. | 129 | %right LSL_ASSIGNMENT_CONCATENATE LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. |
74 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_CONCATENATE expr. | 130 | expr ::= identifier LSL_ASSIGNMENT_CONCATENATE expr. |
75 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_ADD expr. | 131 | expr ::= identifier LSL_ASSIGNMENT_ADD expr. |
76 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_SUBTRACT expr. | 132 | expr ::= identifier LSL_ASSIGNMENT_SUBTRACT expr. |
77 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_MULTIPLY expr. | 133 | expr ::= identifier LSL_ASSIGNMENT_MULTIPLY expr. |
78 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_MODULO expr. | 134 | expr ::= identifier LSL_ASSIGNMENT_MODULO expr. |
79 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_DIVIDE expr. | 135 | expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr. |
80 | expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr. | 136 | expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. |
81 | %right LSL_DOT. | ||
82 | expr ::= LSL_IDENTIFIER LSL_DOT LSL_IDENTIFIER. | ||
83 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. | ||
84 | expr ::= LSL_IDENTIFIER LSL_DECREMENT_PRE. | ||
85 | expr ::= LSL_IDENTIFIER LSL_INCREMENT_PRE. | ||
86 | expr ::= LSL_DECREMENT_PRE LSL_IDENTIFIER. | ||
87 | expr ::= LSL_INCREMENT_PRE LSL_IDENTIFIER. | ||
88 | 137 | ||
89 | %nonassoc LSL_COMMA. | 138 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. |
139 | expr ::= identifier LSL_DECREMENT_PRE. | ||
140 | expr ::= identifier LSL_INCREMENT_PRE. | ||
141 | expr ::= LSL_DECREMENT_PRE identifier. | ||
142 | expr ::= LSL_INCREMENT_PRE identifier. | ||
90 | 143 | ||
91 | %nonassoc LSL_FLOAT. | 144 | %nonassoc LSL_FLOAT. |
92 | expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } | 145 | expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } |
@@ -104,66 +157,21 @@ expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } | |||
104 | expr ::= LSL_VECTOR. | 157 | expr ::= LSL_VECTOR. |
105 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. | 158 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. |
106 | 159 | ||
107 | %nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. | 160 | %nonassoc LSL_COMMA. |
108 | %nonassoc LSL_ELSE. | ||
109 | statement ::= LSL_DO block LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE LSL_STATEMENT. | ||
110 | statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_PARENTHESIS_CLOSE block. | ||
111 | |||
112 | ifBlock ::= ifBlock LSL_ELSE block. | ||
113 | ifBlock ::= block. | ||
114 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE] | ||
115 | |||
116 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. | ||
117 | statement ::= LSL_RETURN expr LSL_STATEMENT. | ||
118 | statement ::= LSL_RETURN LSL_STATEMENT. | ||
119 | statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT. | ||
120 | statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block. | ||
121 | |||
122 | %nonassoc LSL_LABEL. | ||
123 | target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT. | ||
124 | |||
125 | %nonassoc LSL_IDENTIFIER LSL_STATEMENT. | ||
126 | statement ::= target LSL_STATEMENT. | ||
127 | statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT. | ||
128 | statement ::= type LSL_IDENTIFIER LSL_STATEMENT. | ||
129 | statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); } | ||
130 | |||
131 | statementList ::= statementList statement. | ||
132 | statementList ::= . | ||
133 | |||
134 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. | ||
135 | block ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. | ||
136 | block ::= statement. | ||
137 | |||
138 | %nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE. | ||
139 | parameter ::= type LSL_IDENTIFIER. | ||
140 | parameterList ::= parameterList LSL_COMMA parameter. | ||
141 | parameterList ::= parameter. | ||
142 | parameterList ::= . | ||
143 | //function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE block. | ||
144 | function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE block. | ||
145 | functionList ::= functionList function. | ||
146 | functionList ::= . | ||
147 | |||
148 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. | ||
149 | state ::= LSL_IDENTIFIER stateBlock. | ||
150 | |||
151 | %nonassoc LSL_SCRIPT. | ||
152 | script ::= script state. | ||
153 | script ::= script function. | ||
154 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | ||
155 | script ::= . | ||
156 | 161 | ||
157 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_UNKNOWN. | 162 | exprList ::= exprList LSL_COMMA expr. |
163 | exprList ::= expr. | ||
164 | exprList ::= . | ||
165 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. | ||
158 | 166 | ||
159 | 167 | ||
160 | %parse_accept {printf("Parsing complete.\n");} | 168 | %parse_accept {printf("Parsing complete.\n");} |
161 | 169 | ||
162 | %parse_failure {fprintf(stderr,"Giving up. Parser is hopelessly lost!\n");} | 170 | %parse_failure {fprintf(stderr,"Giving up. Parser is hopelessly lost!\n");} |
163 | 171 | ||
164 | %stack_overflow {fprintf(stderr,"Giving up. Parser stack overflow @ line %04d column %04d\n", yypMinor->yy0->line, yypMinor->yy0->column);} // Gotta love consistancy, if it ever happens. | 172 | %stack_overflow {fprintf(stderr,"*******************************************************************Giving up. Parser stack overflow @ line %04d column %04d\n", yypMinor->yy0->line, yypMinor->yy0->column);} // Gotta love consistancy, if it ever happens. |
165 | 173 | ||
166 | %syntax_error {fprintf(stderr,"Syntax error @ line %04d column %04d\n", yyminor.yy0->line, yyminor.yy0->column);} | 174 | %syntax_error {fprintf(stderr,"*******************************************************************Syntax error @ line %04d column %04d\n", yyminor.yy0->line, yyminor.yy0->column);} |
167 | 175 | ||
168 | 176 | ||
169 | /* Undocumented shit that might be useful later. Pffft | 177 | /* Undocumented shit that might be useful later. Pffft |
@@ -178,5 +186,13 @@ script ::= . | |||
178 | ** but it does not parse, the type of the token is changed to ID and | 186 | ** but it does not parse, the type of the token is changed to ID and |
179 | ** the parse is retried before an error is thrown. | 187 | ** the parse is retried before an error is thrown. |
180 | 188 | ||
189 | %wildcard | ||
190 | %code | ||
191 | |||
192 | %ifdef | ||
193 | %endif | ||
194 | %ifndef | ||
195 | %endif | ||
196 | |||
181 | */ | 197 | */ |
182 | 198 | ||