diff options
author | David Walter Seikel | 2012-01-12 05:05:03 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-12 05:05:03 +1000 |
commit | d343ceea759a437e9fd0b506f03046318ce9e1fe (patch) | |
tree | 175ef12855babde69e922c9d78d3d2567a019801 | |
parent | Some general cleanup. (diff) | |
download | SledjHamr-d343ceea759a437e9fd0b506f03046318ce9e1fe.zip SledjHamr-d343ceea759a437e9fd0b506f03046318ce9e1fe.tar.gz SledjHamr-d343ceea759a437e9fd0b506f03046318ce9e1fe.tar.bz2 SledjHamr-d343ceea759a437e9fd0b506f03046318ce9e1fe.tar.xz |
More clean up.
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 16 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 13 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 10 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lexer.l | 5 |
4 files changed, 16 insertions, 28 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index beae756..b441f0b 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -14,6 +14,7 @@ static void outputStatementToken(LSL_Leaf *content); | |||
14 | 14 | ||
15 | LSL_Token LSL_Tokens[] = | 15 | LSL_Token LSL_Tokens[] = |
16 | { | 16 | { |
17 | // Various forms of "space". | ||
17 | {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, | 18 | {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, |
18 | {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, | 19 | {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, |
19 | {LSL_SPACE, " ", LSL_NONE, NULL, NULL, NULL}, | 20 | {LSL_SPACE, " ", LSL_NONE, NULL, NULL, NULL}, |
@@ -21,7 +22,6 @@ LSL_Token LSL_Tokens[] = | |||
21 | // Operators, in order of precedence, low to high | 22 | // Operators, in order of precedence, low to high |
22 | // Left to right, unless oterwise stated. | 23 | // Left to right, unless oterwise stated. |
23 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators | 24 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators |
24 | |||
25 | {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, | 25 | {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, |
26 | // QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. | 26 | // QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. |
27 | // QUIRK - No boolean short circuiting. | 27 | // QUIRK - No boolean short circuiting. |
@@ -74,7 +74,6 @@ LSL_Token LSL_Tokens[] = | |||
74 | {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL}, | 74 | {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, NULL}, |
75 | 75 | ||
76 | // Types. | 76 | // Types. |
77 | |||
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_KEY, "key", LSL_NONE, NULL, NULL, NULL}, | 79 | // {LSL_KEY, "key", LSL_NONE, NULL, NULL, NULL}, |
@@ -84,7 +83,6 @@ LSL_Token LSL_Tokens[] = | |||
84 | // {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL}, | 83 | // {LSL_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL}, |
85 | 84 | ||
86 | // Types names. | 85 | // Types names. |
87 | |||
88 | {LSL_TYPE_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, | 86 | {LSL_TYPE_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, |
89 | {LSL_TYPE_INTEGER, "integer", LSL_NONE, NULL, NULL, NULL}, | 87 | {LSL_TYPE_INTEGER, "integer", LSL_NONE, NULL, NULL, NULL}, |
90 | {LSL_TYPE_KEY, "key", LSL_NONE, NULL, NULL, NULL}, | 88 | {LSL_TYPE_KEY, "key", LSL_NONE, NULL, NULL, NULL}, |
@@ -94,7 +92,6 @@ LSL_Token LSL_Tokens[] = | |||
94 | {LSL_TYPE_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL}, | 92 | {LSL_TYPE_VECTOR, "vector", LSL_NONE, NULL, NULL, NULL}, |
95 | 93 | ||
96 | // Then the rest of the syntax tokens. | 94 | // Then the rest of the syntax tokens. |
97 | |||
98 | {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, | 95 | {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, |
99 | 96 | ||
100 | {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, | 97 | {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, |
@@ -120,7 +117,6 @@ LSL_Token LSL_Tokens[] = | |||
120 | {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, | 117 | {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, |
121 | 118 | ||
122 | // A sentinal. | 119 | // A sentinal. |
123 | |||
124 | {999999, NULL, LSL_NONE, NULL, NULL, NULL} | 120 | {999999, NULL, LSL_NONE, NULL, NULL, NULL} |
125 | }; | 121 | }; |
126 | 122 | ||
@@ -415,6 +411,7 @@ int main(int argc, char **argv) | |||
415 | char buffer[4096]; | 411 | char buffer[4096]; |
416 | LuaSL_yyparseParam param; | 412 | LuaSL_yyparseParam param; |
417 | int file; | 413 | int file; |
414 | int count; | ||
418 | boolean badArgs = FALSE; | 415 | boolean badArgs = FALSE; |
419 | 416 | ||
420 | // Sort the token table. | 417 | // Sort the token table. |
@@ -461,13 +458,13 @@ int main(int argc, char **argv) | |||
461 | printf("Usage: %s [-f filename]\n", programName); | 458 | printf("Usage: %s [-f filename]\n", programName); |
462 | printf(" -f: Script file to run.\n"); | 459 | printf(" -f: Script file to run.\n"); |
463 | printf("Or pass filenames in stdin.\n"); | 460 | printf("Or pass filenames in stdin.\n"); |
464 | // return 1; | 461 | return 1; |
465 | } | 462 | } |
466 | 463 | ||
467 | if ('\0' == buffer[0]) | 464 | if ('\0' == buffer[0]) |
468 | { | 465 | { |
469 | strcpy(buffer, "test.lsl"); | 466 | //strcpy(buffer, "test.lsl"); |
470 | /* | 467 | |
471 | count = read(STDIN_FILENO, buffer, sizeof(buffer)); | 468 | count = read(STDIN_FILENO, buffer, sizeof(buffer)); |
472 | if (0 > count) | 469 | if (0 > count) |
473 | { | 470 | { |
@@ -484,7 +481,7 @@ strcpy(buffer, "test.lsl"); | |||
484 | buffer[count] = '\0'; | 481 | buffer[count] = '\0'; |
485 | printf("Filename %s in stdin.\n", buffer); | 482 | printf("Filename %s in stdin.\n", buffer); |
486 | } | 483 | } |
487 | */ | 484 | |
488 | } | 485 | } |
489 | else | 486 | else |
490 | printf("Filename %s in argument.\n", buffer); | 487 | printf("Filename %s in argument.\n", buffer); |
@@ -522,7 +519,6 @@ strcpy(buffer, "test.lsl"); | |||
522 | // on EOF yylex will return 0 | 519 | // on EOF yylex will return 0 |
523 | while((yv = yylex(param.lval, param.scanner)) != 0) | 520 | while((yv = yylex(param.lval, param.scanner)) != 0) |
524 | { | 521 | { |
525 | printf("******************************PARSING - %d %s\n", yv, param.lval->token->token); | ||
526 | Parse(pParser, yv, param.lval, ¶m); | 522 | Parse(pParser, yv, param.lval, ¶m); |
527 | if (LSL_SCRIPT == yv) | 523 | if (LSL_SCRIPT == yv) |
528 | break; | 524 | break; |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 9493552..35d0470 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | #ifndef __EXPRESSION_H__ | 2 | #ifndef __LSL_TREE_H__ |
3 | #define __EXPRESSION_H__ | 3 | #define __LSL_TREE_H__ |
4 | 4 | ||
5 | #define LUASL_DEBUG | 5 | #define LUASL_DEBUG |
6 | 6 | ||
@@ -10,17 +10,12 @@ | |||
10 | #include <sys/stat.h> | 10 | #include <sys/stat.h> |
11 | #include <fcntl.h> | 11 | #include <fcntl.h> |
12 | 12 | ||
13 | //#include <iostream> | ||
14 | //#include <cstdlib> | ||
15 | #include "assert.h" | 13 | #include "assert.h" |
16 | //#include "ex5def.h" | ||
17 | //#include "example5.h" | ||
18 | #include <unistd.h> | 14 | #include <unistd.h> |
19 | #include <sys/types.h> | 15 | #include <sys/types.h> |
20 | #include <sys/stat.h> | 16 | #include <sys/stat.h> |
21 | #include <fcntl.h> | 17 | #include <fcntl.h> |
22 | #include <stdlib.h> | 18 | #include <stdlib.h> |
23 | //#include "lexglobal.h" | ||
24 | //#define BUFS 1024 | 19 | //#define BUFS 1024 |
25 | 20 | ||
26 | #include "LuaSL_lemon_yaccer.h" | 21 | #include "LuaSL_lemon_yaccer.h" |
@@ -173,7 +168,7 @@ struct _LSL_Script | |||
173 | }; | 168 | }; |
174 | 169 | ||
175 | 170 | ||
176 | // define the type for flex and bison | 171 | // define the type for flex and lemon3 |
177 | #define YYSTYPE LSL_Leaf | 172 | #define YYSTYPE LSL_Leaf |
178 | 173 | ||
179 | 174 | ||
@@ -212,5 +207,5 @@ void Parse(void *yyp, int yymajor, LSL_Leaf *yyminor, LuaSL_yyparseParam *param) | |||
212 | void ParseFree(void *p, void (*freeProc)(void*)); | 207 | void ParseFree(void *p, void (*freeProc)(void*)); |
213 | 208 | ||
214 | 209 | ||
215 | #endif // __EXPRESSION_H__ | 210 | #endif // __LSL_TREE_H__ |
216 | 211 | ||
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 2427456..49d2fe1 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -11,7 +11,7 @@ | |||
11 | %token_destructor { burnLeaf($$); } | 11 | %token_destructor { burnLeaf($$); } |
12 | 12 | ||
13 | 13 | ||
14 | program ::= script LSL_SCRIPT(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. | 14 | program ::= script LSL_SCRIPT(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 | 15 | ||
16 | 16 | ||
17 | %left LSL_BOOL_AND. | 17 | %left LSL_BOOL_AND. |
@@ -62,7 +62,7 @@ expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addP | |||
62 | 62 | ||
63 | %nonassoc LSL_FLOAT. | 63 | %nonassoc LSL_FLOAT. |
64 | %nonassoc LSL_INTEGER. | 64 | %nonassoc LSL_INTEGER. |
65 | expr(A) ::= LSL_INTEGER(B). { A = B; } | 65 | expr(A) ::= LSL_INTEGER(B). { A = B; } |
66 | 66 | ||
67 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. | 67 | %nonassoc LSL_TYPE_FLOAT LSL_TYPE_INTEGER LSL_TYPE_KEY LSL_TYPE_LIST LSL_TYPE_ROTATION LSL_TYPE_STRING LSL_TYPE_VECTOR. |
68 | 68 | ||
@@ -73,11 +73,11 @@ expr(A) ::= LSL_INTEGER(B). { A = B; } | |||
73 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. | 73 | %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE. |
74 | 74 | ||
75 | %nonassoc LSL_STATEMENT. | 75 | %nonassoc LSL_STATEMENT. |
76 | statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); } | 76 | statement(A) ::= expr(B) LSL_STATEMENT(D). { A = addStatement(D, LSL_EXPRESSION, B); } |
77 | 77 | ||
78 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_IDENTIFIER LSL_SCRIPT LSL_UNKNOWN. | 78 | %nonassoc LSL_SPACE LSL_COMMENT LSL_COMMENT_LINE LSL_IDENTIFIER LSL_SCRIPT LSL_UNKNOWN. |
79 | script ::= script statement(A). { A->left = param->ast; param->ast = A; } | 79 | script ::= script statement(A). { A->left = param->ast; param->ast = A; } |
80 | script ::= statement(A). { A->left = param->ast; param->ast = A; } | 80 | script ::= statement(A). { A->left = param->ast; param->ast = A; } |
81 | 81 | ||
82 | 82 | ||
83 | %parse_accept {printf("Parsing complete.\n");} | 83 | %parse_accept {printf("Parsing complete.\n");} |
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index ddcb520..50f2624 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l | |||
@@ -107,6 +107,7 @@ IDENTIFIER [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* | |||
107 | 107 | ||
108 | %% | 108 | %% |
109 | 109 | ||
110 | // TODO - this is not reentrant, should make it so. | ||
110 | static char *ignorableText = NULL; | 111 | static char *ignorableText = NULL; |
111 | static int column = 0; | 112 | static int column = 0; |
112 | static int line = 0; | 113 | static int line = 0; |
@@ -149,10 +150,6 @@ int common(YYSTYPE *lval, char *text, boolean checkIgnorable, int type) | |||
149 | ignorableText = strdup(text); | 150 | ignorableText = strdup(text); |
150 | } | 151 | } |
151 | 152 | ||
152 | #ifdef LUASL_DEBUG | ||
153 | printf ("******************************common(%s, \"%s\", , %d) %04d, %04d\n", lval->token->token, text, type, line, column); | ||
154 | #endif | ||
155 | |||
156 | return type; | 153 | return type; |
157 | } | 154 | } |
158 | 155 | ||