[antlr-interest] Re : antlr v3 C target EOF PUSHSTREAM

Rampon Jerome ramponjerome at yahoo.fr
Thu Jan 12 14:55:17 PST 2012



Hi Jim, Gavin

Thanks for your quick answers.
I agree with your feedbacks to overload nextToken in C interface
but just two remarks:

-this obliges to redefine nextToken, nextTokenStr and emit 

from antlr3lexer.c as they are all static. Not so good in term of maintenance
for the grammar.


-In my case, I just need to pop some data structure when 

popstream is invoked in nextToken on EOF 

(DS were pushed just before calling PUSHSTREAM)
I originally had in mind some simpler redefinition if nextToken from antlr3lexer 

was not static as ... would avoid any maintenance work on nextToken, nextTokenStr and emit
redefinition ...


Init

lexer->rec->state->tokSource->nextToken = myNextToken

and
myNextToken (...tokSource) ...

  lxr = (pANTLR3_LEXER) tokSource->super;
  state = lxr ? lxr->rec->state : NULL;
  stackSizeInit = (state && (state->streams)) ? state->streams->size(state->streams) : 0;


  tok = nextToken ... /* original */

  stackSize = (state && (state->streams)) ? state->streams->size(state->streams) : 0;

  while (stackSizeInit-- > stackSize)
     popMyDataStructure;

return tok;

Jerome



________________________________
 De : Jim Idle <jimi at temporal-wave.com>
À : antlr-interest at antlr.org 
Envoyé le : Jeudi 12 Janvier 2012 0h00
Objet : Re: [antlr-interest] antlr v3 C target EOF PUSHSTREAM
 
You can override nexttoken - I have explained how to do it on here before,
so you should find it antlr.markmail.org  basically you make a copy of the
functions you need and install your own pointers.

Jim


At 11:29 12/01/2012, Rampon Jerome wrote:
>I do not see how to do a similar job with C target as nextToken
>redefinition is not possible

It's
 been a while since I played with the C target, but IIRC most of the 
"methods" (probably including nextToken) are defined as function 
pointers within the structure data.  So you should be able to subclass 
the lexer and reassign the pointer to your override method -- you just 
have to handle the recasting and base pointer preservation yourself.


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Rampon Jerome
> Sent: Wednesday, January 11, 2012 2:30 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] antlr v3 C target EOF PUSHSTREAM
>
>
>
>
> Hi,
>
>
> I already used PUSHSTREAM macro on C target to switch input streams
> with v3.
>
> I did similar work on Java with personal stack of stream and nextToken
> redefinition (someway close to some example found later in antlr wiki
> pages)
>
> I need to manipulate(push/pop) some additional data structures all
> along the stack of input streams.
> It is simple to add in my own stack of stream with extension and
> nextToken redefinition in Java.
>
> I do not see how to do a similar job with C target as nextToken
> redefinition is not possible
>
> Is there one way to redefine EOF token to add specific actions ? or
> anything that would permit expected
>
> actions ...
>
> I just want to manage data structures in a parallel stack and pop on
> EOF in v3 in C !!!
>
> Thanks for any idea
>
>
> Jerome
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list