flex+bison, sections with different syntaxes -


i working on parser in flex & bison supposed parse source codes have different sections have different syntaxes.

think of php, "stupidly" dumps until finds <?php, goes syntactic part parses stuff , when finds ?> goes dumping.

so while in "dumping" section, scanner should provide raw strings. meaningful tokens (while, openparenthesis, identifier, etc.) should provided in syntactic sections , \ starts syntactic section.

i have found can give flex rules different "start conditions", can switch between different scanners like

%x semantic %x dump %% <dump>"\\"        { begin(semantic); } <dump>.           { (*yylval).stringvalue = yytext; return yy::parser::token::char;} <semantic>"while" {return yy::parser::token::while;} 

which need here.

my problem end of syntactic section cannot described regular expression, decision cannot done within scanner, has made parser. want go dump mode "in between rules". want like

codeelement: open statement semicolon bool semicolon statement close <<go dump mode>> element 

you can tell, supposed become rule for-loop in c, "body" (the element) supposed read dump again (this deliver single character, unless grouped multiple characters { , } again)

i know bison can execute code "in between rules", tried declare global variable (ugh) "dumpmode", put {dumpmode = true;} rule this

codeelement: open statement semicolon bool semicolon statement close {dumpmode = true;} element 

and put

if(dumpmode) {     begin(dump);     dumpmode = false; } 

in front of flex rules (this similar example on page have linked above)

but not work , makes sense - afaik bison needs final element token decide use rule (so code won't executed before token comes), token produced dump mode, not active @ point in process.

do know way this? switching start-condition of flexer bison code in between rules? maybe i'd need break bison rules apart like

codeelement: for1 for2     ; for1: open statement semicolon bool semicolon statement close {dumpmode = true;}     ; for2: element     ; 

but don't think approach work if-then-else constructs...

did try function void yy_pop_state (), calling bison part ?


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -