Search code examples
c++cregexflex-lexerlex

Catching the error and continue back to the calling function


I am building a scanner/lexical_analyser using decaf language in flex/lex tool.

To check for identifiers I implemented regular expression id [A-Za-z][A-Za-z0-9_]*

{id} { matchedID(); return T_Identifier; }

I also like to check for bad identifiers so I wrote a method to handle it:

    * Checking ID validness */
static void matchedID()
{
  strncpy(yylval.identifier,yytext,MaxIdentLen);
  if (yyleng > MaxIdentLen)
  {
    ReportError::LongIdentifier(&yylloc,yytext);
    return;
  }
}

Now when I run my scanner over a test_file that contains:

vari.able, 3variable, variable/123, var-123, variable_whose_name_is_much_too_long

the scanner escapes checking all variables and reports error about last long variable (decaf var max_size_is 31 so it truncates it accordingly). If I take out the variable with long name, the scanner scans the rest of file perfectly! Can anyone tell me how to fix it so when scanner finds a long variable and reports error, it should also scan other statement in the file ?


Solution

  • So I noticed that somehow the scanner script was not syncing with my server and the changes I made were local to client side only, as soon as the server started synchronizing with client files everything started working back a like a charm.

    I wanted to delete my question, but then I thought someone else might face the same problem in the future :)