[antlr-interest] [C Target] User custom context handling, and parallel parsing.

Jim Idle jimi at temporal-wave.com
Mon Aug 18 14:35:03 PDT 2008


On Mon, 2008-08-18 at 16:49 -0400, Garry Iglesias wrote:
> Hi Jim,
>  
>   I've encounter a reccurent problem using ANTLR with the C target
> language. Maybe it's just that
> I don't know the way to solve it but here it is:
>  
>   I need to be able to have some 'custom context' in my parser (and
> also in my pure lexer filters...). This is important
> because I might want to run several concurent parsings, and in my
> grammar I need to be sure to have an isolated context
> per thread.
>   Using Java target it's simple : @lexer::members or @parser::members
> is ok as it merges the target code inside the class.
>   When I first used the C target I was disapointed not being able to
> find how to do the same thing. 


Please read the API documentation for the C target, where all the
@sections are explained in detail. You can add your own members to the
lexer or parser context pointer that is supplied to every rule.


>  
>   I would also add, about the concurrent parsing, that it would also
> benefit from 'real streams' in input, I mean streamed input
> instead of having the whole stuff 'ready'. This is not really
> mandatory but it would improve greatly when a concurrent parser
> component would have as input a translated output from another
> concurrent parser.


>  
>   Sorry if they are already existing solutions to solve my problems, I
> was just unable to find any clue in the documentation.

This should be in the API documentation under the "Using sections in
grammar files", however it seems that something in the annotation is
making it stop after the @postinclude section. I notice that there are
other pieces that I have documented that are not there too. I hope I
have not lost something here as it was quite a bit of effort! :-( 

Anyway, what you want is:

@parser::context
{
  struct _mystruct * mystruct;
}

There is also 
@lexer::context
{
    int myLexerThang;
}

There is also a (void * userp) available in the shared state for each
instance of the recognizer (which is free threading). In lexer tokens
there are 3 integer fields you can use and one void * field you can use;
in lexer grammars you can access them via the pre-defined MACROS: USER1
USER2 USER3 CUSTOM (see API docs for the other macros).


Jim

> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080818/6838d6fe/attachment.html 


More information about the antlr-interest mailing list