Bison Defining Comments in Flex -


i have create lexical , syntax analyzer c-like language. in language define comment "everything exists after symbol // until end of line". everytime compiler gets "/" 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); }  %{ /* not add of own tokens below line!!!! */ %}  "\n"                     { g_linenumber++; } 

this part 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(); }  %% 

the pattern comments should this

"//".*"\n"  {g_linenumber++;} 

your pattern expects .* occur literally in input, inside double quotes. considering increase line-number want have new-line matched part of comment.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -