bison - Flex lexer start condition not being recognized -
i have scanner maintains 2 exclusive states (word , defn)
%option noyywrap %s word %s defn %% %{ begin(word); %} <word>{ "|" { begin(defn); return ws_pipe; } } <defn>{ [^;]+ { printf("ds: %s\n", yytext); return wd_string; } ";" { return wd_semicolon; } } \n|. { printf("u: %s\n", yytext); } %%
but simple input "| text;", when pipe parsed state not being changed, parsing of "some text;" fails.
the state being changed defn
when |
encountered in state word
. however, next time yylex
called (to token following pipe), state reset word
block
%{ begin(word); %}
from flex manual (emphasis added):
in rules section, indented or %{ %} enclosed text appearing before first rule may used declare variables local scanning routine , (after declarations) code executed whenever scanning routine entered.
you're better off using initial
start condition represent the, well, initial start condition.
Comments
Post a Comment