aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c99
-rw-r--r--LuaSL/src/LuaSL_lexer.l39
-rw-r--r--LuaSL/src/LuaSL_yaccer.y34
3 files changed, 118 insertions, 54 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index 9f663e5..57e639a 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -50,31 +50,31 @@ LSL_Token LSL_Tokens[] =
50 {LSL_BIT_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}, 51// {LSL_TYPECAST_CLOSE, ")", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
52// {LSL_TYPECAST_OPEN, "(", 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}, 53 {LSL_ANGLE_CLOSE, ">", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
54// {LSL_ANGLE_OPEN, "<", 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}, 55 {LSL_BRACKET_CLOSE, "]", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, evaluateOperationToken},
56// {LSL_BRACKET_OPEN, "[", 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}, 57 {LSL_PARENTHESIS_CLOSE, ")", LSL_INNER2OUTER, NULL, NULL, evaluateNoToken},
58 {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, NULL, NULL, NULL}, 58 {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, NULL, NULL, NULL},
59// {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken}, 59// {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
60// {LSL_ASSIGNMENT_ADD, "+=", 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}, 61 {LSL_ASSIGNMENT_SUBTRACT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
62// {LSL_ASSIGNMENT_MULTIPLY, "*=", 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}, 63 {LSL_ASSIGNMENT_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
64// {LSL_ASSIGNMENT_DIVIDE, "/=", 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}, 65 {LSL_ASSIGNMENT_PLAIN, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, evaluateOperationToken},
66// {LSL_DOT, ".", LSL_RIGHT2LEFT, outputOperationToken, NULL, evaluateOperationToken}, 66 {LSL_DOT, ".", LSL_RIGHT2LEFT, outputOperationToken, NULL, evaluateOperationToken},
67// {LSL_DECREMENT_POST, "--", LSL_RIGHT2LEFT | LSL_UNARY, 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}, 68 {LSL_DECREMENT_PRE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
69// {LSL_INCREMENT_POST, "++", 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}, 70 {LSL_INCREMENT_PRE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, evaluateOperationToken},
71// {LSL_COMMA, ",", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken}, 71 {LSL_COMMA, ",", LSL_LEFT2RIGHT, outputOperationToken, NULL, evaluateOperationToken},
72 72
73 {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL}, 73 {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL},
74 74
75 // Types. 75 // Types.
76 76
77// {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, 77 {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL},
78 {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken}, 78 {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken},
79// {LSL_KEY, "key", LSL_NONE, NULL, NULL, NULL}, 79// {LSL_KEY, "key", LSL_NONE, NULL, NULL, NULL},
80// {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL}, 80// {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL},
@@ -82,25 +82,35 @@ LSL_Token LSL_Tokens[] =
82// {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL}, 82// {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL},
83// {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL}, 83// {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL},
84 84
85 // Types names.
86
87 {LSL_TYPE_FLOAT, "float", LSL_NONE, NULL, NULL, NULL},
88 {LSL_TYPE_INTEGER, "integer", LSL_NONE, NULL, NULL, NULL},
89 {LSL_TYPE_KEY, "key", LSL_NONE, NULL, NULL, NULL},
90 {LSL_TYPE_LIST, "list", LSL_NONE, NULL, NULL, NULL},
91 {LSL_TYPE_ROTATION, "rotation", LSL_NONE, NULL, NULL, NULL},
92 {LSL_TYPE_STRING, "string", LSL_NONE, NULL, NULL, NULL},
93 {LSL_TYPE_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL},
94
85 // Then the rest of the syntax tokens. 95 // Then the rest of the syntax tokens.
86 96
87// {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, 97// {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL},
88 98
89// {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, 99 {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL},
90 100
91// {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL}, 101 {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL},
92// {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL}, 102 {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL},
93// {LSL_ELSE_IF, "else if", LSL_NONE, NULL, NULL, NULL}, 103// {LSL_ELSE_IF, "else if", LSL_NONE, NULL, NULL, NULL},
94// {LSL_ELSE, "else", LSL_NONE, NULL, NULL, NULL}, 104 {LSL_ELSE, "else", LSL_NONE, NULL, NULL, NULL},
95// {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL}, 105 {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL},
96// {LSL_JUMP, "jump", LSL_NONE, NULL, NULL, NULL}, 106 {LSL_JUMP, "jump", LSL_NONE, NULL, NULL, NULL},
97// {LSL_RETURN, "return", LSL_NONE, NULL, NULL, NULL}, 107 {LSL_RETURN, "return", LSL_NONE, NULL, NULL, NULL},
98// {LSL_STATE_CHANGE, "state", LSL_NONE, NULL, NULL, NULL}, 108 {LSL_STATE_CHANGE, "state", LSL_NONE, NULL, NULL, NULL},
99// {LSL_WHILE, "while", LSL_NONE, NULL, NULL, NULL}, 109 {LSL_WHILE, "while", LSL_NONE, NULL, NULL, NULL},
100 {LSL_STATEMENT, ";", LSL_NONE, outputStatementToken, NULL, evaluateStatementToken}, 110 {LSL_STATEMENT, ";", LSL_NONE, outputStatementToken, NULL, evaluateStatementToken},
101 111
102// {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL}, 112 {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL},
103// {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL}, 113 {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL},
104// {LSL_PARAMETER, "parameter", LSL_NONE, NULL, NULL, NULL}, 114// {LSL_PARAMETER, "parameter", LSL_NONE, NULL, NULL, NULL},
105// {LSL_FUNCTION, "function", LSL_NONE, NULL, NULL, NULL}, 115// {LSL_FUNCTION, "function", LSL_NONE, NULL, NULL, NULL},
106// {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL}, 116// {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL},
@@ -281,27 +291,28 @@ static void evaluateOperationToken(LSL_Leaf *content, LSL_Value *left, LSL_Value
281 291
282 switch (content->operationValue) 292 switch (content->operationValue)
283 { 293 {
284// case LSL_COMMA : 294 case LSL_COMMA :
285// case LSL_INCREMENT_PRE : 295 case LSL_INCREMENT_PRE :
286// case LSL_INCREMENT_POST : 296// case LSL_INCREMENT_POST :
287// case LSL_DECREMENT_PRE : 297 case LSL_DECREMENT_PRE :
288// case LSL_DECREMENT_POST : 298// case LSL_DECREMENT_POST :
289// case LSL_DOT : 299 case LSL_DOT :
290// case LSL_ASSIGNMENT_PLAIN : 300 case LSL_ASSIGNMENT_PLAIN :
291// case LSL_ASSIGNMENT_DIVIDE : 301 case LSL_ASSIGNMENT_DIVIDE :
292// case LSL_ASSIGNMENT_MODULO : 302 case LSL_ASSIGNMENT_MODULO :
293// case LSL_ASSIGNMENT_MULTIPLY : 303 case LSL_ASSIGNMENT_MULTIPLY :
294// case LSL_ASSIGNMENT_SUBTRACT : 304 case LSL_ASSIGNMENT_SUBTRACT :
295// case LSL_ASSIGNMENT_ADD : 305 case LSL_ASSIGNMENT_ADD :
296// case LSL_ASSIGNMENT_CONCATENATE : 306// case LSL_ASSIGNMENT_CONCATENATE :
297// case LSL_PARENTHESIS_OPEN : 307 case LSL_PARENTHESIS_OPEN :
298// case LSL_PARENTHESIS_CLOSE : 308 case LSL_PARENTHESIS_CLOSE :
299// case LSL_BRACKET_OPEN : 309 case LSL_BRACKET_OPEN :
300// case LSL_BRACKET_CLOSE : 310 case LSL_BRACKET_CLOSE :
301// case LSL_ANGLE_OPEN : 311 case LSL_ANGLE_OPEN :
302// case LSL_ANGLE_CLOSE : 312 case LSL_ANGLE_CLOSE :
303// case LSL_TYPECAST : 313// case LSL_TYPECAST_OPEN :
304// break; 314// case LSL_TYPECAST_CLOSE :
315 break;
305 case LSL_BIT_NOT : left->content.integerValue = ~ right->content.integerValue; break; 316 case LSL_BIT_NOT : left->content.integerValue = ~ right->content.integerValue; break;
306 case LSL_BOOL_NOT : left->content.integerValue = ! right->content.integerValue; break; 317 case LSL_BOOL_NOT : left->content.integerValue = ! right->content.integerValue; break;
307 case LSL_NEGATION : left->content.integerValue = 0 - right->content.integerValue; break; 318 case LSL_NEGATION : left->content.integerValue = 0 - right->content.integerValue; break;
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index 9753a57..8628ca4 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -53,15 +53,52 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])*
53"/" { ECHO; return LSL_DIVIDE; } 53"/" { ECHO; return LSL_DIVIDE; }
54"!" { ECHO; return LSL_BOOL_NOT; } 54"!" { ECHO; return LSL_BOOL_NOT; }
55"~" { ECHO; return LSL_BIT_NOT; } 55"~" { ECHO; return LSL_BIT_NOT; }
56 /* "<" { ECHO; return LSL_ANGLE_OPEN; } */
57 /* ">" { ECHO; return LSL_ANGLE_CLOSE; } */
58"[" { ECHO; return LSL_BRACKET_OPEN; }
59"]" { ECHO; return LSL_BRACKET_CLOSE; }
56"(" { ECHO; return LSL_PARENTHESIS_OPEN; } 60"(" { ECHO; return LSL_PARENTHESIS_OPEN; }
57")" { ECHO; return LSL_PARENTHESIS_CLOSE; } 61")" { ECHO; return LSL_PARENTHESIS_CLOSE; }
62"+=" { ECHO; return LSL_ASSIGNMENT_ADD; }
63"-=" { ECHO; return LSL_ASSIGNMENT_SUBTRACT; }
64"*=" { ECHO; return LSL_ASSIGNMENT_MULTIPLY; }
65"%=" { ECHO; return LSL_ASSIGNMENT_MODULO; }
66"/=" { ECHO; return LSL_ASSIGNMENT_DIVIDE; }
67"=" { ECHO; return LSL_ASSIGNMENT_PLAIN; }
68"." { ECHO; return LSL_DOT; }
69"--" { ECHO; return LSL_DECREMENT_PRE; }
70"++" { ECHO; return LSL_INCREMENT_PRE; }
71"," { ECHO; return LSL_COMMA; }
58 72
59 /* Types. */ 73 /* Types. */
60{INTEGER} %{ ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; %} 74{INTEGER} %{ ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; %}
61{FLOAT} %{ ECHO; /* yylval->floatValue = atof(yytext); return LSL_FLOAT; */ %} 75{FLOAT} %{ ECHO; yylval->floatValue = atof(yytext); return LSL_FLOAT; %}
76
77 /* Type keywords. */
78"float" %{ ECHO; return LSL_TYPE_FLOAT; %}
79"integer" %{ ECHO; return LSL_TYPE_INTEGER; %}
80"key" %{ ECHO; return LSL_TYPE_KEY; %}
81"list" %{ ECHO; return LSL_TYPE_LIST; %}
82"rotation" %{ ECHO; return LSL_TYPE_ROTATION; %}
83"string" %{ ECHO; return LSL_TYPE_STRING; %}
84"vector" %{ ECHO; return LSL_TYPE_VECTOR; %}
85
86 /* Statement keywords. */
87"do" %{ ECHO; return LSL_DO; %}
88"for" %{ ECHO; return LSL_FOR; %}
89"else" %{ ECHO; return LSL_ELSE; %}
90"if" %{ ECHO; return LSL_IF; %}
91"jump" %{ ECHO; return LSL_JUMP; %}
92"return" %{ ECHO; return LSL_RETURN; %}
93"state" %{ ECHO; return LSL_STATE_CHANGE; %}
94"while" %{ ECHO; return LSL_WHILE; %}
62 95
63{NAME} %{ ECHO; /* yylval->nameValue = strdup(yytext); return LSL_NAME; */ %} 96{NAME} %{ ECHO; /* yylval->nameValue = strdup(yytext); return LSL_NAME; */ %}
64 97
98 /* Other symbols. */
99"@" %{ ECHO; return LSL_LABEL; %}
100"{" %{ ECHO; return LSL_BLOCK_OPEN; %}
101"}" %{ ECHO; return LSL_BLOCK_CLOSE; %}
65";" { ECHO; return LSL_STATEMENT; } 102";" { ECHO; return LSL_STATEMENT; }
66 103
67<<EOF>> { yyterminate(); } 104<<EOF>> { yyterminate(); }
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y
index 7f873c2..b9721f8 100644
--- a/LuaSL/src/LuaSL_yaccer.y
+++ b/LuaSL/src/LuaSL_yaccer.y
@@ -13,19 +13,35 @@
13%type <spaceValue> ignorable 13%type <spaceValue> ignorable
14%token <spaceValue> LSL_SPACE 14%token <spaceValue> LSL_SPACE
15 15
16%type <expressionValue> expr 16%type <expressionValue> expr
17%left LSL_BOOL_AND 17%left LSL_BOOL_AND
18%left LSL_BOOL_OR 18%left LSL_BOOL_OR
19%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR 19%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR
20%left LSL_EQUAL LSL_NOT_EQUAL 20%left LSL_EQUAL LSL_NOT_EQUAL
21%left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL 21%left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL
22%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT 22%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT
23%left LSL_SUBTRACT LSL_ADD 23%left LSL_SUBTRACT LSL_ADD
24%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY 24%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY
25%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION 25%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION
26%left LSL_ANGLE_OPEN LSL_ANGLE_CLOSE
27%token LSL_BRACKET_OPEN LSL_BRACKET_CLOSE
26%token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION 28%token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION
29%right LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN
30%right LSL_DOT
31%right LSL_DECREMENT_PRE LSL_INCREMENT_PRE
32%token LSL_COMMA
33
34%token <floatValue> LSL_FLOAT
27%token <integerValue> LSL_INTEGER 35%token <integerValue> LSL_INTEGER
28 36
37%nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR
38
39%nonassoc LSL_DO LSL_FOR LSL_ELSE LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE
40
41%nonassoc LSL_LABEL
42
43%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE
44
29%type <statementValue> statement 45%type <statementValue> statement
30%nonassoc LSL_STATEMENT 46%nonassoc LSL_STATEMENT
31 47