aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c133
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h180
-rw-r--r--LuaSL/src/LuaSL_lexer.l20
-rw-r--r--LuaSL/src/LuaSL_yaccer.y25
4 files changed, 193 insertions, 165 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index 11a481d..9f663e5 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -13,94 +13,103 @@ static void outputStatementToken(LSL_Leaf *content);
13 13
14LSL_Token LSL_Tokens[] = 14LSL_Token LSL_Tokens[] =
15{ 15{
16 // Start with expression operators. 16// {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL},
17 // In order of precedence, high to low. 17// {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL},
18 {LSL_SPACE, " ", LSL_NONE, NULL, NULL, NULL},
19
20 // Operators, in order of precedence, low to high
18 // Left to right, unless oterwise stated. 21 // Left to right, unless oterwise stated.
19 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators 22 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators
20 23
21// {LSL_COMMA, ",", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken}, 24 {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
22// {LSL_INCREMENT_PRE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
23// {LSL_INCREMENT_POST, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
24// {LSL_DECREMENT_PRE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
25// {LSL_DECREMENT_POST, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
26// {LSL_DOT, ".", LSL_RIGHT2LEFT, outputOperationToken, NULL, evaluateOperationToken},
27// {LSL_ASSIGNMENT_PLAIN, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
28// {LSL_ASSIGNMENT_DIVIDE, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
29// {LSL_ASSIGNMENT_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
30// {LSL_ASSIGNMENT_MULTIPLY, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
31// {LSL_ASSIGNMENT_SUBTRACT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
32// {LSL_ASSIGNMENT_ADD, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
33// {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
34 {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, NULL, NULL, NULL},
35 {LSL_PARENTHESIS_CLOSE, ")", LSL_INNER2OUTER, NULL, NULL, evaluateNoToken},
36// {LSL_BRACKET_OPEN, "[", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
37// {LSL_BRACKET_CLOSE, "]", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
38// {LSL_ANGLE_OPEN, "<", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
39// {LSL_ANGLE_CLOSE, ">", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
40// {LSL_TYPECAST_OPEN, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
41// {LSL_TYPECAST_CLOSE, ")", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
42 {LSL_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
43 {LSL_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
44 {LSL_NEGATION, "-", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
45 {LSL_DIVIDE, "/", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
46 {LSL_MODULO, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
47 {LSL_MULTIPLY, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
48// {LSL_DOT_PRODUCT, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
49// {LSL_CROSS_PRODUCT, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
50 {LSL_SUBTRACT, "-", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
51 {LSL_ADD, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
52// {LSL_CONCATENATE, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
53 {LSL_LEFT_SHIFT, "<<", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
54 {LSL_RIGHT_SHIFT, ">>", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
55// QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol
56 {LSL_LESS_THAN, "<", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
57 {LSL_GREATER_THAN, ">", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
58 {LSL_LESS_EQUAL, "<=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
59 {LSL_GREATER_EQUAL, ">=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
60 {LSL_EQUAL, "==", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
61 {LSL_NOT_EQUAL, "!=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
62 {LSL_BIT_AND, "&", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
63 {LSL_BIT_XOR, "^", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
64 {LSL_BIT_OR, "|", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
65// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. 25// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher.
66// QUIRK - No boolean short circuiting. 26// QUIRK - No boolean short circuiting.
67 {LSL_BOOL_OR, "||", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken}, 27 {LSL_BOOL_OR, "||", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
68 {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken}, 28 {LSL_BIT_OR, "|", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
29 {LSL_BIT_XOR, "^", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
30 {LSL_BIT_AND, "&", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
31// QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol
32 {LSL_NOT_EQUAL, "!=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
33 {LSL_EQUAL, "==", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
34 {LSL_GREATER_EQUAL, ">=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
35 {LSL_LESS_EQUAL, "<=", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
36 {LSL_GREATER_THAN, ">", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
37 {LSL_LESS_THAN, "<", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
38 {LSL_RIGHT_SHIFT, ">>", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
39 {LSL_LEFT_SHIFT, "<<", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
40// {LSL_CONCATENATE, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
41 {LSL_ADD, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
42 {LSL_SUBTRACT, "-", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
43// {LSL_CROSS_PRODUCT, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
44// {LSL_DOT_PRODUCT, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
45 {LSL_MULTIPLY, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
46 {LSL_MODULO, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
47 {LSL_DIVIDE, "/", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
48 {LSL_NEGATION, "-", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
49 {LSL_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
50 {LSL_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
51// {LSL_TYPECAST_CLOSE, ")", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
52// {LSL_TYPECAST_OPEN, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
53// {LSL_ANGLE_CLOSE, ">", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
54// {LSL_ANGLE_OPEN, "<", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
55// {LSL_BRACKET_CLOSE, "]", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
56// {LSL_BRACKET_OPEN, "[", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
57 {LSL_PARENTHESIS_CLOSE, ")", LSL_INNER2OUTER, NULL, NULL, evaluateNoToken},
58 {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, NULL, NULL, NULL},
59// {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
60// {LSL_ASSIGNMENT_ADD, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
61// {LSL_ASSIGNMENT_SUBTRACT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
62// {LSL_ASSIGNMENT_MULTIPLY, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
63// {LSL_ASSIGNMENT_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
64// {LSL_ASSIGNMENT_DIVIDE, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
65// {LSL_ASSIGNMENT_PLAIN, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
66// {LSL_DOT, ".", LSL_RIGHT2LEFT, outputOperationToken, NULL, evaluateOperationToken},
67// {LSL_DECREMENT_POST, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
68// {LSL_DECREMENT_PRE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
69// {LSL_INCREMENT_POST, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
70// {LSL_INCREMENT_PRE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
71// {LSL_COMMA, ",", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
69 72
70 // Then the rest of the syntax tokens. 73 {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL},
74
75 // Types.
71 76
72 {LSL_SPACE, " ", LSL_NONE, NULL, NULL, NULL},
73// {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL},
74// {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL},
75// {LSL_TYPE, "type", LSL_NONE, NULL, NULL, NULL},
76// {LSL_NAME, "name", LSL_NONE, NULL, NULL, NULL},
77// {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL},
78// {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, 77// {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL},
79 {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken}, 78 {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken},
80// {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL},
81// {LSL_KEY, "key", LSL_NONE, NULL, NULL, NULL}, 79// {LSL_KEY, "key", LSL_NONE, NULL, NULL, NULL},
82// {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL},
83// {LSL_ROTATION, "rotation", LSL_NONE, NULL, NULL, NULL},
84// {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL}, 80// {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL},
81// {LSL_ROTATION, "rotation", LSL_NONE, NULL, NULL, NULL},
82// {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL},
83// {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL},
84
85 // Then the rest of the syntax tokens.
86
87// {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL},
88
85// {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, 89// {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL},
86 {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL}, 90
87// {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL}, 91// {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL},
88// {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL}, 92// {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL},
89// {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL},
90// {LSL_ELSE, "else", LSL_NONE, NULL, NULL, NULL},
91// {LSL_ELSE_IF, "else if", LSL_NONE, NULL, NULL, NULL}, 93// {LSL_ELSE_IF, "else if", LSL_NONE, NULL, NULL, NULL},
94// {LSL_ELSE, "else", LSL_NONE, NULL, NULL, NULL},
95// {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL},
92// {LSL_JUMP, "jump", LSL_NONE, NULL, NULL, NULL}, 96// {LSL_JUMP, "jump", LSL_NONE, NULL, NULL, NULL},
97// {LSL_RETURN, "return", LSL_NONE, NULL, NULL, NULL},
93// {LSL_STATE_CHANGE, "state", LSL_NONE, NULL, NULL, NULL}, 98// {LSL_STATE_CHANGE, "state", LSL_NONE, NULL, NULL, NULL},
94// {LSL_WHILE, "while", LSL_NONE, NULL, NULL, NULL}, 99// {LSL_WHILE, "while", LSL_NONE, NULL, NULL, NULL},
95// {LSL_RETURN, "return", LSL_NONE, NULL, NULL, NULL},
96 {LSL_STATEMENT, ";", LSL_NONE, outputStatementToken, NULL, evaluateStatementToken}, 100 {LSL_STATEMENT, ";", LSL_NONE, outputStatementToken, NULL, evaluateStatementToken},
97// {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL}, 101
98// {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL}, 102// {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL},
103// {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL},
99// {LSL_PARAMETER, "parameter", LSL_NONE, NULL, NULL, NULL}, 104// {LSL_PARAMETER, "parameter", LSL_NONE, NULL, NULL, NULL},
100// {LSL_FUNCTION, "function", LSL_NONE, NULL, NULL, NULL}, 105// {LSL_FUNCTION, "function", LSL_NONE, NULL, NULL, NULL},
101// {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL}, 106// {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL},
102// {LSL_SCRIPT, "script", LSL_NONE, NULL, NULL, NULL}, 107// {LSL_SCRIPT, "script", LSL_NONE, NULL, NULL, NULL},
108
103// {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, 109// {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL},
110
111 // A sentinal.
112
104 {999999, NULL, LSL_NONE, NULL, NULL, NULL} 113 {999999, NULL, LSL_NONE, NULL, NULL, NULL}
105}; 114};
106 115
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 257f18b..adefa07 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -19,8 +19,24 @@ extern int yydebug;
19 19
20// http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser. 20// http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser.
21 21
22
23typedef union _LSL_Leaf LSL_Leaf;
24typedef struct _LSL_Value LSL_Value;
25typedef struct _LSL_Identifier LSL_Identifier;
26typedef struct _LSL_Statement LSL_Statement;
27typedef struct _LSL_Block LSL_Block;
28typedef struct _LSL_Function LSL_Function;
29typedef struct _LSL_State LSL_State;
30typedef struct _LSL_Script LSL_Script;
31typedef struct _LSL_AST LSL_AST;
32
33typedef int LSL_Type;
34
35typedef void (*convertToken2Lua) (LSL_Leaf *content);
36typedef void (*outputToken) (LSL_Leaf *content);
37typedef void (*evaluateToken) (LSL_Leaf *content, LSL_Value *left, LSL_Value *right);
38
22#ifndef FALSE 39#ifndef FALSE
23// NEVER change this
24typedef enum 40typedef enum
25{ 41{
26 FALSE = 0, 42 FALSE = 0,
@@ -39,111 +55,111 @@ typedef enum
39 LSL_CREATION = 32 55 LSL_CREATION = 32
40} LSL_Flags; 56} LSL_Flags;
41 57
42typedef int LSL_Type;
43
44typedef struct 58typedef struct
45{ 59{
46 LSL_Type type; 60 LSL_Type type;
47 struct LSL_AST *expression; 61 char *token;
48} LSL_Statement; 62 LSL_Flags flags;
63 outputToken output;
64 convertToken2Lua convert;
65 evaluateToken evaluate;
66} LSL_Token;
49 67
50typedef struct 68union _LSL_Leaf
51{ 69{
52 LSL_Statement *statements; 70 char *commentValue;
53} LSL_Block; 71 char *spaceValue;
54 72
55typedef struct 73 LSL_Type operationValue;
74 LSL_AST *expressionValue;
75
76 float floatValue;
77 int integerValue;
78 char *keyValue;
79 LSL_Leaf *listValue;
80 char *stringValue;
81 float vectorValue[3];
82 float rotationValue[4];
83
84 LSL_Identifier *variableValue;
85
86 char *labelValue;
87 LSL_Statement *doValue;
88 LSL_Statement *forValue;
89 LSL_Statement *elseIfValue;
90 LSL_Statement *elseValue;
91 LSL_Statement *ifValue;
92 char *jumpValue;
93 LSL_Statement *returnValue;
94 char *stateChangeValue;
95 LSL_Statement *whileValue;
96 LSL_Statement *statementValue;
97
98 LSL_Block *blockValue;
99 LSL_Identifier *parameterValue;
100 LSL_Function *functionValue;
101 LSL_State *stateValue;
102 LSL_Script *scriptValue;
103
104 char *unknownValue;
105};
106
107struct _LSL_Value
56{ 108{
57 char *name; 109 LSL_Leaf content;
58 struct LSL_Identifier *parameters; 110 LSL_Type type;
59 LSL_Block block; 111};
60 LSL_Type type;
61} LSL_Function;
62 112
63typedef struct 113struct _LSL_Identifier // For variables and function parameters.
64{ 114{
65 char *name; 115 char *name;
66 LSL_Function *handlers; 116 LSL_Value value;
67} LSL_State; 117};
68 118
69typedef struct 119struct _LSL_Statement
70{ 120{
71 char *name; 121 LSL_AST *expression;
72 struct LSL_Identifier *variables; 122 LSL_Type type;
73 LSL_Function *functions; 123};
74 LSL_State *states;
75} LSL_Script;
76 124
77typedef union LSL_Leaf 125struct _LSL_Block
78{ 126{
79 char *spaceValue; 127 LSL_Statement *statements;
80 char *commentValue; 128};
81 LSL_Type typeValue;
82 char *nameValue;
83 struct LSL_Identifier *identifierValue;
84 float floatValue;
85 int integerValue;
86 char *stringValue;
87 char *keyValue;
88 float vectorValue[3];
89 float rotationValue[4];
90 union LSL_Leaf *listValue;
91 char *labelValue;
92 LSL_Type operationValue;
93 struct LSL_AST *expressionValue;
94 LSL_Statement *doValue;
95 LSL_Statement *forValue;
96 LSL_Statement *ifValue;
97 LSL_Statement *elseValue;
98 LSL_Statement *elseIfValue;
99 char *jumpValue;
100 char *stateChangeValue;
101 LSL_Statement *statementValue;
102 struct LSL_Identifier *parameterValue;
103 LSL_Function *functionValue;
104 LSL_State *stateValue;
105 LSL_Script *scriptValue;
106 char *unknownValue;
107} LSL_Leaf;
108 129
109typedef struct 130struct _LSL_Function
110{ 131{
132 char *name;
133 LSL_Block block;
134 LSL_Identifier *parameters;
111 LSL_Type type; 135 LSL_Type type;
112 LSL_Leaf content; 136};
113} LSL_Value;
114
115typedef void (*convertToken2Lua) (LSL_Leaf *content);
116typedef void (*outputToken) (LSL_Leaf *content);
117typedef void (*evaluateToken) (LSL_Leaf *content, LSL_Value *left, LSL_Value *right);
118 137
119typedef struct 138struct _LSL_State
120{ 139{
121 LSL_Type type; 140 char *name;
122 char *token; 141 LSL_Function *handlers;
123 LSL_Flags flags; 142};
124 outputToken output;
125 convertToken2Lua convert;
126 evaluateToken evaluate;
127} LSL_Token;
128 143
129typedef struct 144struct _LSL_Script
130{ 145{
131 char *name; 146 char *name;
132 LSL_Type type; 147 LSL_Function *functions;
133 LSL_Leaf content; 148 LSL_State *states;
134} LSL_Identifier; 149 LSL_Identifier *variables;
150};
135 151
136typedef struct LSL_AST 152struct _LSL_AST
137{ 153{
138 struct LSL_AST *left; 154 LSL_AST *left;
139 struct LSL_AST *right; 155 LSL_AST *right;
140 int line;
141 int character;
142 LSL_Token *token; 156 LSL_Token *token;
143 LSL_Leaf content; 157 LSL_Leaf content;
144} LSL_AST; 158 int line;
159 int character;
160};
161
145 162
146
147// define the type for flex and bison 163// define the type for flex and bison
148#define YYSTYPE LSL_Leaf 164#define YYSTYPE LSL_Leaf
149 165
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index 2166743..9753a57 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -20,21 +20,19 @@
20%option align full 20%option align full
21 21
22HEX [[:xdigit:]] 22HEX [[:xdigit:]]
23NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])*
24INTEGER [[:digit:]]+ 23INTEGER [[:digit:]]+
25EXPONANT [eE][+-]?{INTEGER} 24EXPONANT [eE][+-]?{INTEGER}
26FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? 25FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}?
26NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])*
27 27
28%% 28%%
29 29
30 /* Basic tokens */ 30 /* The order here is important, in mysterious ways. The more specific the lower in case of ambiguities like "floats contain integers". I think, not tested that well yet. */
31
32 /* White space. */
31[[:space:]]+ %{ /* ECHO; yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %} 33[[:space:]]+ %{ /* ECHO; yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %}
32{NAME} %{ ECHO; /* yylval->nameValue = strdup(yytext); return LSL_NAME; */ %}
33{INTEGER} %{ ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; %}
34{FLOAT} %{ ECHO; /* yylval->floatValue = atof(yytext); return LSL_FLOAT; */ %}
35 34
36 /* Expression tokens */ 35 /* Operations. */
37";" { ECHO; return LSL_STATEMENT; }
38"&&" { ECHO; return LSL_BOOL_AND; } 36"&&" { ECHO; return LSL_BOOL_AND; }
39"||" { ECHO; return LSL_BOOL_OR; } 37"||" { ECHO; return LSL_BOOL_OR; }
40"|" { ECHO; return LSL_BIT_OR; } 38"|" { ECHO; return LSL_BIT_OR; }
@@ -58,6 +56,14 @@ FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}?
58"(" { ECHO; return LSL_PARENTHESIS_OPEN; } 56"(" { ECHO; return LSL_PARENTHESIS_OPEN; }
59")" { ECHO; return LSL_PARENTHESIS_CLOSE; } 57")" { ECHO; return LSL_PARENTHESIS_CLOSE; }
60 58
59 /* Types. */
60{INTEGER} %{ ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; %}
61{FLOAT} %{ ECHO; /* yylval->floatValue = atof(yytext); return LSL_FLOAT; */ %}
62
63{NAME} %{ ECHO; /* yylval->nameValue = strdup(yytext); return LSL_NAME; */ %}
64
65";" { ECHO; return LSL_STATEMENT; }
66
61<<EOF>> { yyterminate(); } 67<<EOF>> { yyterminate(); }
62 68
63 /* Everything else */ 69 /* Everything else */
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y
index 0b87df4..7f873c2 100644
--- a/LuaSL/src/LuaSL_yaccer.y
+++ b/LuaSL/src/LuaSL_yaccer.y
@@ -9,12 +9,11 @@
9 9
10%define api.pure 10%define api.pure
11 11
12%token <spaceValue> LSL_SPACE
13
14%nonassoc LSL_STATEMENT
15 12
16%token <integerValue> LSL_INTEGER 13%type <spaceValue> ignorable
14%token <spaceValue> LSL_SPACE
17 15
16%type <expressionValue> expr
18%left LSL_BOOL_AND 17%left LSL_BOOL_AND
19%left LSL_BOOL_OR 18%left LSL_BOOL_OR
20%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR 19%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR
@@ -23,21 +22,23 @@
23%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT 22%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT
24%left LSL_SUBTRACT LSL_ADD 23%left LSL_SUBTRACT LSL_ADD
25%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY 24%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY
26
27%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION 25%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION
28
29%token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION 26%token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION
27%token <integerValue> LSL_INTEGER
30 28
31%type <expressionValue> expr
32%type <statementValue> statement 29%type <statementValue> statement
33%type <spaceValue> ignorable 30%nonassoc LSL_STATEMENT
34 31
35%% 32%%
36 33
37input : 34input :
38 expr { ((LuaSL_yyparseParam*)data)->ast = addOperation(LSL_EXPRESSION, $1, $1); } 35 ignorable { ((LuaSL_yyparseParam*)data)->ast = addSpace($1, ((LuaSL_yyparseParam*)data)->ast); }
36 | expr { ((LuaSL_yyparseParam*)data)->ast = addOperation(LSL_EXPRESSION, $1, $1); }
39 | statement { ((LuaSL_yyparseParam*)data)->ast = addStatement($1, ((LuaSL_yyparseParam*)data)->ast); } 37 | statement { ((LuaSL_yyparseParam*)data)->ast = addStatement($1, ((LuaSL_yyparseParam*)data)->ast); }
40 | ignorable { ((LuaSL_yyparseParam*)data)->ast = addSpace($1, ((LuaSL_yyparseParam*)data)->ast); } 38;
39
40ignorable :
41 LSL_SPACE { $$ = strdup($1); }
41; 42;
42 43
43expr : 44expr :
@@ -70,9 +71,5 @@ statement :
70 expr LSL_STATEMENT { $$ = createStatement(LSL_EXPRESSION, $1); } 71 expr LSL_STATEMENT { $$ = createStatement(LSL_EXPRESSION, $1); }
71; 72;
72 73
73ignorable :
74 LSL_SPACE { $$ = strdup($1); }
75;
76
77%% 74%%
78 75