diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 06c534d..d24f1a9 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -11,34 +11,53 @@ | |||
11 | %token_destructor {burnLeaf($$);} | 11 | %token_destructor {burnLeaf($$);} |
12 | %default_destructor {burnLeaf($$);} | 12 | %default_destructor {burnLeaf($$);} |
13 | 13 | ||
14 | // The start symbol, just coz we need one. | ||
15 | // Lemon does not like the start symbol to be on the RHS, so give it a dummy start symbol. | ||
14 | 16 | ||
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. | 17 | program ::= script LSL_SCRIPT(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
18 | |||
19 | // Various forms of "space". The lexer takes care of them for us. | ||
16 | 20 | ||
17 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_UNKNOWN. | 21 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_UNKNOWN. |
18 | 22 | ||
23 | // Basic script structure. | ||
24 | |||
19 | %nonassoc LSL_SCRIPT. | 25 | %nonassoc LSL_SCRIPT. |
20 | script ::= script state. | 26 | script ::= script state. |
21 | script ::= script function. | 27 | script ::= script function. |
22 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } | 28 | script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } |
23 | script ::= . | 29 | script ::= . |
24 | 30 | ||
31 | // State definitions. | ||
32 | |||
33 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. | ||
25 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. | 34 | stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. |
26 | state ::= LSL_IDENTIFIER stateBlock. | 35 | state ::= LSL_IDENTIFIER stateBlock. |
27 | 36 | ||
28 | %nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE. | 37 | // Function definitions. |
38 | |||
39 | %nonassoc LSL_PARAMETER LSL_FUNCTION. | ||
40 | functionList ::= functionList function. | ||
41 | functionList ::= . | ||
42 | |||
29 | parameter ::= type LSL_IDENTIFIER. | 43 | parameter ::= type LSL_IDENTIFIER. |
30 | parameterList ::= parameterList LSL_COMMA parameter. | 44 | parameterList ::= parameterList LSL_COMMA parameter. |
31 | parameterList ::= parameter. | 45 | parameterList ::= parameter. |
32 | parameterList ::= . | 46 | parameterList ::= . |
33 | function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. | 47 | function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. // Causes a conflict when it's an empty parameterList with calling the same type of function. |
34 | function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. | 48 | function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. |
35 | functionList ::= functionList function. | ||
36 | functionList ::= . | ||
37 | 49 | ||
38 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. | 50 | // Blocks. |
39 | funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. | 51 | |
40 | block ::= funcBlock. | 52 | block ::= funcBlock. |
41 | block ::= statement. | 53 | block ::= statement. |
54 | funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. | ||
55 | |||
56 | // Various forms of statement. | ||
57 | |||
58 | %nonassoc LSL_STATEMENT. | ||
59 | statementList ::= statementList statement. | ||
60 | statementList ::= . | ||
42 | 61 | ||
43 | %nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. | 62 | %nonassoc LSL_DO LSL_FOR LSL_ELSE_IF LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. |
44 | %nonassoc LSL_ELSE. | 63 | %nonassoc LSL_ELSE. |
@@ -47,25 +66,25 @@ statement ::= LSL_FOR LSL_PARENTHESIS_OPEN expr LSL_STATEMENT expr LSL_STATEMENT | |||
47 | 66 | ||
48 | ifBlock ::= ifBlock LSL_ELSE block. | 67 | ifBlock ::= ifBlock LSL_ELSE block. |
49 | ifBlock ::= block. | 68 | ifBlock ::= block. |
50 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE] | 69 | statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. [LSL_ELSE] // The [LSL_ELSE] part causes a conflict. |
51 | 70 | ||
52 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. | 71 | statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. |
53 | statement ::= LSL_RETURN expr LSL_STATEMENT. | 72 | statement ::= LSL_RETURN expr LSL_STATEMENT. |
54 | statement ::= LSL_RETURN LSL_STATEMENT. | 73 | statement ::= LSL_RETURN LSL_STATEMENT. |
55 | statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT. | 74 | statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT. |
56 | statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block. | 75 | statement ::= LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block. |
57 | 76 | ||
58 | %nonassoc LSL_LABEL. | 77 | %nonassoc LSL_LABEL. |
59 | target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT. | 78 | statement ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT. |
60 | 79 | ||
61 | %nonassoc LSL_STATEMENT. | 80 | // This might be bogus, or might be valid LSL, but it let us test the expression parser by evaluating them. |
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); } | 81 | statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); } |
66 | 82 | ||
67 | statementList ::= statementList statement. | 83 | // Various forms of expression. |
68 | statementList ::= . | 84 | |
85 | exprList ::= exprList LSL_COMMA expr. | ||
86 | exprList ::= expr. | ||
87 | exprList ::= . | ||
69 | 88 | ||
70 | %right LSL_BOOL_AND. | 89 | %right LSL_BOOL_AND. |
71 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } | 90 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } |
@@ -103,6 +122,8 @@ expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(NULL, B, C); } | |||
103 | expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } | 122 | expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } |
104 | expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } | 123 | expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } |
105 | 124 | ||
125 | // Types, typecasts, and expression reordering. | ||
126 | |||
106 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. | 127 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. |
107 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. | 128 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. |
108 | type ::= LSL_TYPE_FLOAT. | 129 | type ::= LSL_TYPE_FLOAT. |
@@ -120,9 +141,11 @@ type ::= LSL_TYPE_VECTOR. | |||
120 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } | 141 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } |
121 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } | 142 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } |
122 | 143 | ||
123 | %right LSL_DOT LSL_IDENTIFIER. | 144 | // Function call. |
124 | identifier ::= identifier LSL_DOT LSL_IDENTIFIER. | 145 | |
125 | identifier ::= LSL_IDENTIFIER. | 146 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. // Casuses a conflict when exprList is empty with a function definition with no type and no parameters. |
147 | |||
148 | // Variables and dealing with them. | ||
126 | 149 | ||
127 | expr ::= identifier. | 150 | expr ::= identifier. |
128 | 151 | ||
@@ -135,12 +158,24 @@ expr ::= identifier LSL_ASSIGNMENT_MODULO expr. | |||
135 | expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr. | 158 | expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr. |
136 | expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. | 159 | expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. |
137 | 160 | ||
161 | // Hmm think this can have commas seperating the assignment parts. | ||
162 | statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT. | ||
163 | statement ::= type LSL_IDENTIFIER LSL_STATEMENT. | ||
164 | |||
165 | %right LSL_DOT LSL_IDENTIFIER. | ||
166 | identifier ::= identifier LSL_DOT LSL_IDENTIFIER. | ||
167 | identifier ::= LSL_IDENTIFIER. | ||
168 | |||
138 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. | 169 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. |
139 | expr ::= identifier LSL_DECREMENT_PRE. | 170 | expr ::= identifier LSL_DECREMENT_PRE. |
140 | expr ::= identifier LSL_INCREMENT_PRE. | 171 | expr ::= identifier LSL_INCREMENT_PRE. |
141 | expr ::= LSL_DECREMENT_PRE identifier. | 172 | expr ::= LSL_DECREMENT_PRE identifier. |
142 | expr ::= LSL_INCREMENT_PRE identifier. | 173 | expr ::= LSL_INCREMENT_PRE identifier. |
143 | 174 | ||
175 | %nonassoc LSL_COMMA. | ||
176 | |||
177 | // Values. | ||
178 | |||
144 | %nonassoc LSL_FLOAT. | 179 | %nonassoc LSL_FLOAT. |
145 | expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } | 180 | expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } |
146 | %nonassoc LSL_INTEGER. | 181 | %nonassoc LSL_INTEGER. |
@@ -148,22 +183,17 @@ expr(A) ::= LSL_INTEGER(B). { B->basicType = OT_integer; A = B; } | |||
148 | %nonassoc LSL_KEY. | 183 | %nonassoc LSL_KEY. |
149 | expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } | 184 | expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } |
150 | %nonassoc LSL_LIST. | 185 | %nonassoc LSL_LIST. |
151 | expr ::= LSL_BRACKET_OPEN exprList LSL_BRACKET_CLOSE. | 186 | expr ::= LSL_BRACKET_OPEN exprList LSL_BRACKET_CLOSE. [LSL_BRACKET_OPEN] |
152 | %nonassoc LSL_ROTATION. | 187 | %nonassoc LSL_ROTATION. |
153 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. | 188 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [LSL_ANGLE_OPEN] |
154 | %nonassoc LSL_STRING. | 189 | %nonassoc LSL_STRING. |
155 | expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } | 190 | expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } |
156 | %nonassoc LSL_VECTOR. | 191 | %nonassoc LSL_VECTOR. |
157 | expr ::= LSL_VECTOR. | 192 | expr ::= LSL_VECTOR. |
158 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. | 193 | expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [LSL_ANGLE_OPEN] |
159 | 194 | ||
160 | %nonassoc LSL_COMMA. | ||
161 | |||
162 | exprList ::= exprList LSL_COMMA expr. | ||
163 | exprList ::= expr. | ||
164 | exprList ::= . | ||
165 | expr ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN exprList LSL_PARENTHESIS_CLOSE. | ||
166 | 195 | ||
196 | // Parser callbacks. | ||
167 | 197 | ||
168 | %parse_accept {printf("Parsing complete.\n");} | 198 | %parse_accept {printf("Parsing complete.\n");} |
169 | 199 | ||