[antlr-interest] Passing information into the parser

Gokulakannan Somasundaram gokul007 at gmail.com
Sun Dec 28 22:31:18 PST 2008


Hi Gavin,
           Can you also give me some pointers on how to pass arguments into
the parser from external code?

Thanks,
Gokul.

On Mon, Dec 29, 2008 at 11:51 AM, Gavin Lambert <antlr at mirality.co.nz>wrote:

> At 19:13 29/12/2008, Gokulakannan Somasundaram wrote:
>
>>         I have a requirement, where in before starting the parsing, i need
>> to tell the parser whether the first token is T_FUNCTION / T_TRIGGER(say
>> callType). (i.e) this token is not available as part of the text to be
>> parsed. In Bison, it is just declared with %token T_FUNCTION and %token
>> T_TRIGGER. The scanner makes sure that it emits the callType token before it
>> emits the tokens to be parsed. Although, i am able to come up with some ways
>> to do this, they are too ugly.
>>            Can someone provide me a clean way of passing information into
>> the parser and make the scanner emit that as the first token, even before
>> the actual tokens are emitted? I am trying to do this in C-Language target.
>>
>
> If you want to emit custom tokens from the lexer due to arbitrary
> conditions then you need to override the lexer's nextToken method.
>
> You can see an example of doing this (albeit for a different reason) here:
>  <http://www.antlr.org/wiki/pages/viewpage.action?pageId=3604497>
>
> That should hopefully get you started.  (Basically, the first time
> nextToken is called you should create and return your extra token, and then
> on all subsequent calls just call the base method.)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081229/9cf76956/attachment.html 


More information about the antlr-interest mailing list