[antlr-interest] Setting Lexer (Was: Please HELP!!!)

Craig Main craig at palantir.co.za
Thu Feb 6 23:40:59 PST 2003


Hi All,

Is there any way of getting the lexer to restart from a particular point,
and consequently, to get the current position of the lexer.

If I need to parse a section of code several times, how would I do it.

Given 
[foreach 10]
this 
test
[endfor]

I want to parse this section 10 times. I would use some sort of artificial
stack to keep track of the sections for nesting purposes. I need the parser
to remember where it is at [foreach 10] and re-parse from there 10 times
when it gets to [endfor].

Thanks
Regards
Craig

On Thu, Feb 06, 2003 at 02:17:17AM -0000, rmsanjivp <rmsanjivp at yahoo.com>
wrote:
> MyLexer lexer(some istream object);
>
> then there is no way for me to specify the lexer to read from
> different input stream.
>
> Is there a way to change the input to lexer while I am parsing? Like
> telling lexer to read from one file initially and then from another
> file without re-instantiating the lexer?

a) check the includeFile example (if you want include file like behaviour)
b) check LexerSharedInputState.hpp (if you just want to reinitialize after
   a parse run) something like this:

   ifstream file;

	....

   antlr::LexerSharedInputState lex_input = lexer->getInputState();
   lex_input->initialize(file, filename);

   // and reset parser (antlr) internal state
   parser->getInputState()->reset();
   parser->setFilename(filename);

   // start parsing at the 'start' rule
   parser->start();

   setFilename's are necessary to get correct errormessages. The
   inputstates need resets to prevent 'funny' things.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++----
---
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++----
---
     "Evil will always triumph, because Good is dumb." ---  Spaceballs


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list