diff options
author | David Walter Seikel | 2012-01-09 10:51:58 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-09 10:51:58 +1000 |
commit | 9ad38f79de2255256a45b82efe3d8924a52d659f (patch) | |
tree | 2fc3280795c54283e4912b4a62ea8e4efff5fde7 | |
parent | Missed this. (diff) | |
download | SledjHamr-9ad38f79de2255256a45b82efe3d8924a52d659f.zip SledjHamr-9ad38f79de2255256a45b82efe3d8924a52d659f.tar.gz SledjHamr-9ad38f79de2255256a45b82efe3d8924a52d659f.tar.bz2 SledjHamr-9ad38f79de2255256a45b82efe3d8924a52d659f.tar.xz |
Moved yyerror() into the flex source. Added a count function, CHAR, STRING, and comment stripping.
Well, half of comment stripping, it will fail without the other half. lol
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 6 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lexer.l | 36 |
2 files changed, 34 insertions, 8 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index 48415fc..76dd433 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -404,12 +404,6 @@ static void convertAST2Lua(LSL_AST *ast) | |||
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
407 | int yyerror(const char *msg) | ||
408 | { | ||
409 | fprintf(stderr, "Parser error: %s\n", msg); | ||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | int main(int argc, char **argv) | 407 | int main(int argc, char **argv) |
414 | { | 408 | { |
415 | char *programName = argv[0]; | 409 | char *programName = argv[0]; |
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index 631a44b..291d0c9 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l | |||
@@ -2,13 +2,16 @@ | |||
2 | 2 | ||
3 | #define excludeLexer | 3 | #define excludeLexer |
4 | #include "LuaSL_LSL_tree.h" | 4 | #include "LuaSL_LSL_tree.h" |
5 | #include <stdio.h> | ||
6 | |||
7 | void count(char *text); | ||
5 | 8 | ||
6 | #ifdef LUASL_DEBUG | 9 | #ifdef LUASL_DEBUG |
7 | #undef ECHO | 10 | #undef ECHO |
8 | #define ECHO printf ("[%s]\n", yytext) | 11 | #define ECHO count(yytext); printf ("[%s]\n", yytext) |
9 | #else | 12 | #else |
10 | #undef ECHO | 13 | #undef ECHO |
11 | #define ECHO {} | 14 | #define ECHO count(yytext) |
12 | #endif | 15 | #endif |
13 | 16 | ||
14 | %} | 17 | %} |
@@ -23,6 +26,8 @@ HEX [[:xdigit:]] | |||
23 | INTEGER [[:digit:]]+ | 26 | INTEGER [[:digit:]]+ |
24 | EXPONANT [eE][+-]?{INTEGER} | 27 | EXPONANT [eE][+-]?{INTEGER} |
25 | FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? | 28 | FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? |
29 | CHAR '(\\.|[^\\'\n])+' | ||
30 | STRING \"(\\.|[^\\"\n])*\" | ||
26 | NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* | 31 | NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* |
27 | 32 | ||
28 | %% | 33 | %% |
@@ -31,6 +36,8 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* | |||
31 | 36 | ||
32 | /* White space. */ | 37 | /* White space. */ |
33 | [[:space:]]+ %{ ECHO; /* yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %} | 38 | [[:space:]]+ %{ ECHO; /* yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %} |
39 | "/*" %{ /* count(); comment(); */ %} | ||
40 | "//"[^\n]* %{ /* consume //-comment */ %} | ||
34 | 41 | ||
35 | /* Operations. */ | 42 | /* Operations. */ |
36 | "&&" { ECHO; return LSL_BOOL_AND; } | 43 | "&&" { ECHO; return LSL_BOOL_AND; } |
@@ -109,6 +116,31 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* | |||
109 | 116 | ||
110 | %% | 117 | %% |
111 | 118 | ||
119 | int column = 0; | ||
120 | int line = 0; | ||
121 | |||
122 | void count(char *text) | ||
123 | { | ||
124 | int i; | ||
125 | |||
126 | for (i = 0; text[i] != '\0'; i++) | ||
127 | if (text[i] == '\n') | ||
128 | { | ||
129 | column = 0; | ||
130 | line++; | ||
131 | } | ||
132 | else if (text[i] == '\t') | ||
133 | column += 8 - (column % 8); | ||
134 | else | ||
135 | column++; | ||
136 | } | ||
137 | |||
138 | int yyerror(const char *msg) | ||
139 | { | ||
140 | fprintf(stderr, "Parser error on line %d, column %d: %s\n", line, column, msg); | ||
141 | return 0; | ||
142 | } | ||
143 | |||
112 | int yywrap(yyscan_t yyscanner) | 144 | int yywrap(yyscan_t yyscanner) |
113 | { | 145 | { |
114 | #ifdef FLEX_SCANNER | 146 | #ifdef FLEX_SCANNER |