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_lexer.l | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'LuaSL/src/LuaSL_lexer.l') 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