aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-09 10:51:58 +1000
committerDavid Walter Seikel2012-01-09 10:51:58 +1000
commit9ad38f79de2255256a45b82efe3d8924a52d659f (patch)
tree2fc3280795c54283e4912b4a62ea8e4efff5fde7 /LuaSL
parentMissed this. (diff)
downloadSledjHamr-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
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c6
-rw-r--r--LuaSL/src/LuaSL_lexer.l36
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
407int yyerror(const char *msg)
408{
409 fprintf(stderr, "Parser error: %s\n", msg);
410 return 0;
411}
412
413int main(int argc, char **argv) 407int 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
7void 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:]]
23INTEGER [[:digit:]]+ 26INTEGER [[:digit:]]+
24EXPONANT [eE][+-]?{INTEGER} 27EXPONANT [eE][+-]?{INTEGER}
25FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? 28FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}?
29CHAR '(\\.|[^\\'\n])+'
30STRING \"(\\.|[^\\"\n])*\"
26NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* 31NAME [[: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
119int column = 0;
120int line = 0;
121
122void 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
138int 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
112int yywrap(yyscan_t yyscanner) 144int yywrap(yyscan_t yyscanner)
113{ 145{
114#ifdef FLEX_SCANNER 146#ifdef FLEX_SCANNER