[antlr-interest] antlr3 C-Target ever used in reality?

Johannes Luber jaluber at gmx.de
Sat Nov 29 09:10:29 PST 2008


Christian Hoffmann schrieb:
> What's wrong below????
> antlr error:  reference to rewrite element unaryExpression1 without reference on left of ->
> 
> 
> unaryExpression1     // (level 1)
>   : a=INC        -> ^(TOK_PREINC[$a]) unaryExpression1
>   | a=DEC        -> ^(TOK_PREDEC[$a]) unaryExpression1
>   | unaryExpression2
>   ;

I'm not sure if you made a mistake here - "^(TOK_PREINC[$a])
unaryExpression1" may need to be "^(TOK_PREINC[$a] unaryExpression1)".
At least the resulting AST would make more sense to me. In fact,
thinking about your intent you probably want

 unaryExpression1     // (level 1)
   : a=INC unaryExpression1 -> ^(TOK_PREINC[$a] unaryExpression1)
   | a=DEC unaryExpression1 -> ^(TOK_PREINC[$a] unaryExpression1)
   | unaryExpression2
   ;

> 
> rewriting rules doesn't work, if you write something like:
> rule : expr -> ^(TOK_SLIST (statement)*)
>             { pVMCompiler->m_Symbols.PopScope(); }
>      ;
> cause C-Target code results in:
>       ADAPTOR->addChild(ADAPTOR, root_0,  pVMCompiler->m_Symbols.PopScope(); );
>                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> the inlined code is inside the addChild(...) call

That is a mistake by you. Actions after "->" are only supposed to create
nodes and aren't supposed to contain complete statements.

rule : expr  { pVMCompiler->m_Symbols.PopScope(); } -> ^(TOK_SLIST
(statement)*)

or

rule : expr -> ^(TOK_SLIST (statement)*) {
pVMCompiler->m_Symbols.PopScope() }

may be your intent.

> 
> It seems the c-target is developped without beeing used in reality.
> I'll go back to antlr2, at this stage, antlr3 is nonviable...

Please don't rant about problems unless you are sure you aren't the
cause. While the second cause isn't obvious to newbies, I suspect you
haven't looked through the available grammars for better examples.
Although the C target requires special treatment - Jim always advises to
look at the C specific examples available on the wiki - the wrong
grammar syntax would have caused the same problems on any target.

Johannes
> 
> 
> ---
> Christian Hoffmann
> D-38118 Braunschweig
> 
> 
> 
> 
> 
> 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