help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing filled AST to yyparse() caller after successful parse


From: Jeannot Langlois
Subject: Re: Passing filled AST to yyparse() caller after successful parse
Date: Sun, 08 May 2005 12:11:31 -0400
User-agent: Mozilla Thunderbird 0.8 (X11/20040913)

In a reentrant GLR parser, how must the yyparse() caller proceed to 
>access the filled AST after a successful parse?  I was expecting 
>yyparse() to return a pointer (whose type could be custom-defined by 
>the user just like the yylex() and yyparse() input parameters) to 
>the properly-filled AST, but it seems that this is not the case and 
>the yyparse() return value is only used to return a parse status 
>code.
>
>Any ideas or documentation pointers about that?
  

I am not sure the %glr parser currently works in pure mode. Let's cc 
Paul Hilfinger, who wrote it, to see if he can let us know.
-- Hans Aberg Hi Hans (and Hi all), Just a few minutes after I posted the question to the mailing list, I found what I was looking for. It works. Apparently, when using a reentrant GLR parser, I need to define an (additional) %parse-param { ... } so I can pass the resulting AST pointer to yyparse(), expect it will be filled properly and then, once yyparse() returns, get access to the AST as expected from the yyparse() caller. Here's a summary of what I did. I am using structs rather than a single pointer directly -- in case I need to add more parameters in the future it will only be a matter of adding a struct member rather than changing a lot of code (I was already using a ScannerContext struct pointer as a yyparse() param [that gets passed to yylex() later on, but that is not our main point of interest for now]; so I just added another yyparse() parameter called "ParserContext*"): In the C-declarations section : (...) typedef struct _ParserContext { GNode* ast; } ParserContext; (...) Then in the Bison Declarations section: (...) %parse-param { ScannerContext* sctx } %parse-param { ParserContext* pctx } (...) Also in all the user actions of all the productions of my grammar rules's start symbol I need to pass the AST pointer (as this is where the parse should end with a filled AST): (...) STARTSYMBOL: RULE1 { pctx->ast = $$; } RULE2 { pctx->ast = $$; } ...etc... ; (...) And finally in the Additional C Code section: (...) int yyerror(ScannerContext* sctx, ParserContext* pctx, char *s) { ... } (...) The yyparse() caller does this: ScannerContext sctx; ParserContext pctx; pctx.ast = NULL; yyparse(&sctx, &pctx); if (pctx.ast != NULL) { ....process AST here... } And that solved my problem. I hope this might help others too... :) Regards,
--
Jeannot Langlois - Signature Jeannot Langlois
B. Sc.  Computer Science / B. Sc.  Informatique
Software Developer / Programmeur-Analyste
System/Network Administrator / Administrateur Système/Réseau
jeannot12 AT linuxmail DOT org
icq : 1-5-2-6-2-8-9-1
msn : jeannot12 AT hotmail DOT com

LINUX_LOGO




reply via email to

[Prev in Thread] Current Thread [Next in Thread]