From 9ad38f79de2255256a45b82efe3d8924a52d659f Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 9 Jan 2012 10:51:58 +1000 Subject: 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 --- LuaSL/src/LuaSL_LSL_tree.c | 6 ------ LuaSL/src/LuaSL_lexer.l | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) (limited to 'LuaSL') 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) } } -int yyerror(const char *msg) -{ - fprintf(stderr, "Parser error: %s\n", msg); - return 0; -} - int main(int argc, char **argv) { 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 @@ #define excludeLexer #include "LuaSL_LSL_tree.h" +#include + +void count(char *text); #ifdef LUASL_DEBUG #undef ECHO - #define ECHO printf ("[%s]\n", yytext) + #define ECHO count(yytext); printf ("[%s]\n", yytext) #else #undef ECHO - #define ECHO {} + #define ECHO count(yytext) #endif %} @@ -23,6 +26,8 @@ HEX [[:xdigit:]] INTEGER [[:digit:]]+ EXPONANT [eE][+-]?{INTEGER} FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? +CHAR '(\\.|[^\\'\n])+' +STRING \"(\\.|[^\\"\n])*\" NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* %% @@ -31,6 +36,8 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* /* White space. */ [[:space:]]+ %{ ECHO; /* yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %} +"/*" %{ /* count(); comment(); */ %} +"//"[^\n]* %{ /* consume //-comment */ %} /* Operations. */ "&&" { ECHO; return LSL_BOOL_AND; } @@ -109,6 +116,31 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])* %% +int column = 0; +int line = 0; + +void count(char *text) +{ + int i; + + for (i = 0; text[i] != '\0'; i++) + if (text[i] == '\n') + { + column = 0; + line++; + } + else if (text[i] == '\t') + column += 8 - (column % 8); + else + column++; +} + +int yyerror(const char *msg) +{ + fprintf(stderr, "Parser error on line %d, column %d: %s\n", line, column, msg); + return 0; +} + int yywrap(yyscan_t yyscanner) { #ifdef FLEX_SCANNER -- cgit v1.1