[antlr-interest] Passing information into the parser

Jim Idle jimi at temporal-wave.com
Tue Dec 30 09:39:24 PST 2008


Gokulakannan Somasundaram wrote:
> Hi Jim,
>         In this case, the problem goes like this
> The client will request
> -- Execute this Object.
>
> The object has a type and a text(to be parsed). So the parsing depends 
> on the type of the object. So in the code, external to the parser, i 
> have to find out the type of the object. In Bison, this type is being 
> sent as the first token. After attempting at it for sometime, i 
> decided to store it as one of the variables inside the Parser Scope(as 
> this is a C-language Target and requires thread-safety).  So there 
> will be a function in members that will set this variable, before 
> parsing starts and i will query it during parsing.
>  
> Please let me know, whether my approach is right.
>
> I have just completed the grammar part.I will post the entire source 
> after completing it. I also would like to know, if i can post the 
> grammar in the "Grammars section".
There is nothing wrong with that approach really. Other ways would be to 
declare the invocation rule as having an input parameter and set the 
flag in the invocation rule. This keeps the parser scope variables 
isolated from external code. This is really just pretending to be 
objects though and there is no  requirement to do it that way.

Anyone can submit a grammar for posting to the grammars section. Make 
sure you add the license you want it to be covered by. If you just want 
anyone to use it for anything, then you can use the BSD license that 
ANTLR uses.

Jim


More information about the antlr-interest mailing list