aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y160
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
14program ::= 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. 15program ::= 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.
20script ::= script state.
21script ::= script function.
22script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; }
23script ::= .
24
25stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE.
26state ::= LSL_IDENTIFIER stateBlock.
27
28%nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE.
29parameter ::= type LSL_IDENTIFIER.
30parameterList ::= parameterList LSL_COMMA parameter.
31parameterList ::= parameter.
32parameterList ::= .
33function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock.
34function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock.
35functionList ::= functionList function.
36functionList ::= .
37
38%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE.
39funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE.
40block ::= funcBlock.
41block ::= 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.
45statement ::= LSL_DO block LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE LSL_STATEMENT.
46statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_STATEMENT expr LSL_STATEMENT expr LSL_PARENTHESIS_CLOSE block.
47
48ifBlock ::= ifBlock LSL_ELSE block.
49ifBlock ::= block.
50statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE]
51
52statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT.
53statement ::= LSL_RETURN expr LSL_STATEMENT.
54statement ::= LSL_RETURN LSL_STATEMENT.
55statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT.
56statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block.
57
58%nonassoc LSL_LABEL.
59target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT.
60
61%nonassoc LSL_STATEMENT.
62statement ::= target LSL_STATEMENT.
63statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT.
64statement ::= type LSL_IDENTIFIER LSL_STATEMENT.
65statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); }
66
67statementList ::= statementList statement.
68statementList ::= .
69
16%right LSL_BOOL_AND. 70%right LSL_BOOL_AND.
17expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } 71expr(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
66exprList ::= exprList LSL_COMMA expr.
67exprList ::= expr.
68exprList ::= .
69expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE.
70expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } 120expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); }
71expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } 121expr(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.
124identifier ::= identifier LSL_DOT LSL_IDENTIFIER.
125identifier ::= LSL_IDENTIFIER.
126
127expr ::= 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.
74expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_CONCATENATE expr. 130expr ::= identifier LSL_ASSIGNMENT_CONCATENATE expr.
75expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_ADD expr. 131expr ::= identifier LSL_ASSIGNMENT_ADD expr.
76expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_SUBTRACT expr. 132expr ::= identifier LSL_ASSIGNMENT_SUBTRACT expr.
77expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_MULTIPLY expr. 133expr ::= identifier LSL_ASSIGNMENT_MULTIPLY expr.
78expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_MODULO expr. 134expr ::= identifier LSL_ASSIGNMENT_MODULO expr.
79expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_DIVIDE expr. 135expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr.
80expr ::= LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr. 136expr ::= identifier LSL_ASSIGNMENT_PLAIN expr.
81%right LSL_DOT.
82expr ::= LSL_IDENTIFIER LSL_DOT LSL_IDENTIFIER.
83%right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST.
84expr ::= LSL_IDENTIFIER LSL_DECREMENT_PRE.
85expr ::= LSL_IDENTIFIER LSL_INCREMENT_PRE.
86expr ::= LSL_DECREMENT_PRE LSL_IDENTIFIER.
87expr ::= 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.
139expr ::= identifier LSL_DECREMENT_PRE.
140expr ::= identifier LSL_INCREMENT_PRE.
141expr ::= LSL_DECREMENT_PRE identifier.
142expr ::= LSL_INCREMENT_PRE identifier.
90 143
91%nonassoc LSL_FLOAT. 144%nonassoc LSL_FLOAT.
92expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } 145expr(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; }
104expr ::= LSL_VECTOR. 157expr ::= LSL_VECTOR.
105expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. 158expr ::= 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.
109statement ::= LSL_DO block LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE LSL_STATEMENT.
110statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_PARENTHESIS_CLOSE block.
111
112ifBlock ::= ifBlock LSL_ELSE block.
113ifBlock ::= block.
114statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE]
115
116statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT.
117statement ::= LSL_RETURN expr LSL_STATEMENT.
118statement ::= LSL_RETURN LSL_STATEMENT.
119statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT.
120statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block.
121
122%nonassoc LSL_LABEL.
123target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT.
124
125%nonassoc LSL_IDENTIFIER LSL_STATEMENT.
126statement ::= target LSL_STATEMENT.
127statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT.
128statement ::= type LSL_IDENTIFIER LSL_STATEMENT.
129statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); }
130
131statementList ::= statementList statement.
132statementList ::= .
133
134%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE.
135block ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE.
136block ::= statement.
137
138%nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE.
139parameter ::= type LSL_IDENTIFIER.
140parameterList ::= parameterList LSL_COMMA parameter.
141parameterList ::= parameter.
142parameterList ::= .
143//function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE block.
144function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE block.
145functionList ::= functionList function.
146functionList ::= .
147
148stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE.
149state ::= LSL_IDENTIFIER stateBlock.
150
151%nonassoc LSL_SCRIPT.
152script ::= script state.
153script ::= script function.
154script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; }
155script ::= .
156 161
157%nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_UNKNOWN. 162exprList ::= exprList LSL_COMMA expr.
163exprList ::= expr.
164exprList ::= .
165expr ::= 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