I have to create a lexical and syntax analyzer for a c-like language. In this language we define as comment "everything that exists after the symbol // until the end of line". Everytime my compiler gets to the "/" it still gives me syntax errors
%%
[ \t] { }
[0-9]+ { SAVE_TOKEN; return TINTEGER; }
"main_loop" { return TOKEN(TMAIN); }
"{" { return TOKEN(TLBRACE); }
"}" { return TOKEN(TRBRACE); }
";" { return TOKEN(TSEMI); }
"(" { return TOKEN(TLPAREN); }
")" { return TOKEN(TRPAREN); }
"rotate" { return TOKEN(TROTATE); }
"forward" { return TOKEN(TFORWARD); }
%{
/* Do not add any of your own tokens below this line!!!! */
%}
"\n" { g_LineNumber++; }
This is the part the is giving me syntax errors.
"//.*" {g_LineNumber++; }
[a-zA-Z_]+ { std::cout << "ERROR: Unknown token '" << yytext << "' on line " << g_LineNumber << std::endl; yyterminate(); }
. { std::cout << "ERROR: Unknown token '" << yytext << "' on line " << g_LineNumber << std::endl; yyterminate(); }
%%