aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_lemon_yaccer.y
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_lemon_yaccer.y')
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y86
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
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. 17program ::= 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.
20script ::= script state. 26script ::= script state.
21script ::= script function. 27script ::= script function.
22script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; } 28script ::= script statement(A). { if (NULL != A) A->left = param->ast; param->ast = A; }
23script ::= . 29script ::= .
24 30
31// State definitions.
32
33%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE.
25stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE. 34stateBlock ::= LSL_BLOCK_OPEN functionList LSL_BLOCK_CLOSE.
26state ::= LSL_IDENTIFIER stateBlock. 35state ::= LSL_IDENTIFIER stateBlock.
27 36
28%nonassoc LSL_PARAMETER LSL_FUNCTION LSL_STATE. 37// Function definitions.
38
39%nonassoc LSL_PARAMETER LSL_FUNCTION.
40functionList ::= functionList function.
41functionList ::= .
42
29parameter ::= type LSL_IDENTIFIER. 43parameter ::= type LSL_IDENTIFIER.
30parameterList ::= parameterList LSL_COMMA parameter. 44parameterList ::= parameterList LSL_COMMA parameter.
31parameterList ::= parameter. 45parameterList ::= parameter.
32parameterList ::= . 46parameterList ::= .
33function ::= LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. 47function ::= 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.
34function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock. 48function ::= type LSL_IDENTIFIER LSL_PARENTHESIS_OPEN parameterList LSL_PARENTHESIS_CLOSE funcBlock.
35functionList ::= functionList function.
36functionList ::= .
37 49
38%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. 50// Blocks.
39funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE. 51
40block ::= funcBlock. 52block ::= funcBlock.
41block ::= statement. 53block ::= statement.
54funcBlock ::= LSL_BLOCK_OPEN statementList LSL_BLOCK_CLOSE.
55
56// Various forms of statement.
57
58%nonassoc LSL_STATEMENT.
59statementList ::= statementList statement.
60statementList ::= .
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
48ifBlock ::= ifBlock LSL_ELSE block. 67ifBlock ::= ifBlock LSL_ELSE block.
49ifBlock ::= block. 68ifBlock ::= block.
50statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. //[LSL_ELSE] 69statement ::= LSL_IF LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE ifBlock. [LSL_ELSE] // The [LSL_ELSE] part causes a conflict.
51 70
52statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT. 71statement ::= LSL_JUMP LSL_IDENTIFIER LSL_STATEMENT.
53statement ::= LSL_RETURN expr LSL_STATEMENT. 72statement ::= LSL_RETURN expr LSL_STATEMENT.
54statement ::= LSL_RETURN LSL_STATEMENT. 73statement ::= LSL_RETURN LSL_STATEMENT.
55statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT. 74statement ::= LSL_STATE_CHANGE LSL_IDENTIFIER LSL_STATEMENT.
56statement ::= LSL_WHILE LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block. 75statement ::= LSL_WHILE LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE block.
57 76
58%nonassoc LSL_LABEL. 77%nonassoc LSL_LABEL.
59target ::= LSL_LABEL LSL_IDENTIFIER LSL_STATEMENT. 78statement ::= 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.
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); } 81statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); }
66 82
67statementList ::= statementList statement. 83// Various forms of expression.
68statementList ::= . 84
85exprList ::= exprList LSL_COMMA expr.
86exprList ::= expr.
87exprList ::= .
69 88
70%right LSL_BOOL_AND. 89%right LSL_BOOL_AND.
71expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } 90expr(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); }
103expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } 122expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); }
104expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } 123expr(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.
108type ::= LSL_TYPE_FLOAT. 129type ::= LSL_TYPE_FLOAT.
@@ -120,9 +141,11 @@ type ::= LSL_TYPE_VECTOR.
120expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } 141expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); }
121expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } 142expr(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.
124identifier ::= identifier LSL_DOT LSL_IDENTIFIER. 145
125identifier ::= LSL_IDENTIFIER. 146expr ::= 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
127expr ::= identifier. 150expr ::= identifier.
128 151
@@ -135,12 +158,24 @@ expr ::= identifier LSL_ASSIGNMENT_MODULO expr.
135expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr. 158expr ::= identifier LSL_ASSIGNMENT_DIVIDE expr.
136expr ::= identifier LSL_ASSIGNMENT_PLAIN expr. 159expr ::= identifier LSL_ASSIGNMENT_PLAIN expr.
137 160
161// Hmm think this can have commas seperating the assignment parts.
162statement ::= type LSL_IDENTIFIER LSL_ASSIGNMENT_PLAIN expr LSL_STATEMENT.
163statement ::= type LSL_IDENTIFIER LSL_STATEMENT.
164
165%right LSL_DOT LSL_IDENTIFIER.
166identifier ::= identifier LSL_DOT LSL_IDENTIFIER.
167identifier ::= 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.
139expr ::= identifier LSL_DECREMENT_PRE. 170expr ::= identifier LSL_DECREMENT_PRE.
140expr ::= identifier LSL_INCREMENT_PRE. 171expr ::= identifier LSL_INCREMENT_PRE.
141expr ::= LSL_DECREMENT_PRE identifier. 172expr ::= LSL_DECREMENT_PRE identifier.
142expr ::= LSL_INCREMENT_PRE identifier. 173expr ::= LSL_INCREMENT_PRE identifier.
143 174
175%nonassoc LSL_COMMA.
176
177// Values.
178
144%nonassoc LSL_FLOAT. 179%nonassoc LSL_FLOAT.
145expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } 180expr(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.
149expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } 184expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; }
150%nonassoc LSL_LIST. 185%nonassoc LSL_LIST.
151expr ::= LSL_BRACKET_OPEN exprList LSL_BRACKET_CLOSE. 186expr ::= LSL_BRACKET_OPEN exprList LSL_BRACKET_CLOSE. [LSL_BRACKET_OPEN]
152%nonassoc LSL_ROTATION. 187%nonassoc LSL_ROTATION.
153expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. 188expr ::= 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.
155expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } 190expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; }
156%nonassoc LSL_VECTOR. 191%nonassoc LSL_VECTOR.
157expr ::= LSL_VECTOR. 192expr ::= LSL_VECTOR.
158expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. 193expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [LSL_ANGLE_OPEN]
159 194
160%nonassoc LSL_COMMA.
161
162exprList ::= exprList LSL_COMMA expr.
163exprList ::= expr.
164exprList ::= .
165expr ::= 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