我正在处理PHP语法,我想传递给我的函数我有类似的行号:internal_functions_in_yacc:
T_ISSET '(' isset_variables ')'
| T_EMPTY '(' variable ')'
| T_INCLUDE expr { observers.IncludeFound($2); }
| T_INCLUDE_ONCE expr { observers.IncludeFound($2); }
| T_EVAL '(' expr ')'
| T_REQUIRE expr { observers.IncludeFound($2); }
| T_REQUIRE_ONCE expr { observers.IncludeFound($2); }
;
Run Code Online (Sandbox Code Playgroud)
现在我想通过行号,比如
T_REQUIRE_ONCE expr { observers.IncludeFound($2,$line_number_here); }
Run Code Online (Sandbox Code Playgroud)
有没有办法知道野牛解析的令牌的行号?或者它是否需要在lexing中完成?
编辑
我发现lexing是用rec2c而不是lex完成的.
T_REQUIRE_ONCE expr { observers.IncludeFound($2,@2.first_line); }
Run Code Online (Sandbox Code Playgroud)
编辑:
为了扩展答案%locations,链接中的指令启用了野牛中的行号.词法分析器仍然负责增加行号和要求%option yylineno.
Lex档案:
\n { yylloc->lines(yyleng); yylloc->step(); }
Run Code Online (Sandbox Code Playgroud)