java - Javacc How can i make a variable accessible to scanner and parser -


im trying create map containing function names. can in scanning phase or parsing phase can't seem same variable accessible both.

what need have function names saved in map before begins parsing, function can declared below point called. need check that function exists.

i have tried using token mgr declarations allows me add tokens map each time seen. need funcs variable seen parser can check function exists.

    token_mgr_decls : {         public static map funcs = new hashmap();     }     token : {         <fname: (["a"-"z"])+ > { funcs.put(matchedtoken.image, "..");}     } 

this closest have got, have tried global variable in .jj file, below parser_begin(..), , declared within main function. both of lead 'symbol can't found' error when trying add function names map.

thanks help.

first have recommend against having variables shared between parser , lexer. because lexer can ahead of parser meaning that:

  • if variable written lexer , read parser, information might out of date (i.e. overwritten) time parser reads it.

  • if variable written parser , read lexer, information lexer needs might not have been written parser when lexer needs it.

that said. if need it. here 1 way. declare variable in token manager this

token_mgr_decls : {     map funcs = new hashmap(); } 

then, in parser, can access variable token_source.funcs.

if use static=true option, variable should static.


Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -