[antlr-interest] NullPointerException in actions for recurring rules
Dariusz Dwornikowski
dariusz.dwornikowski at cs.put.poznan.pl
Sun Jun 26 10:14:56 PDT 2011
Yes i did.
I am getting close to (I think) the cause of that. I think this is because
the rule is recurrent.
I changed it to something like that and works now. Maybe it is not great
grammar, but hey I that is my third day :)
expression returns [String op]
: ^(COOP a=expression b=expression) {
if (a!=null && b!=null) op = a+b ;
print("COOP "+op);
}
| ^(PREFIX a=expression b=expression) {
if (a!=null && b!=null) op = a+"->"+b ;
print("PREFIX "+op);
}
| ^(CHOICE a=expression b=expression) {
if (a!=null && b!=null) op = a+"+"+b ;
print("CHOICE "+op);
}
| IDENT {op=$IDENT.text;}
;
PS: Is there a way to force += return List of custom type ? I would like to
return a list of my custom objects, so later (higher in rule processing) I
could assign this list to my container. I've got many such containers
(components), for each of them many rules can be present.
component {
something ( foo bar);
something2 (foo bar);
}
rule2 return [List list]
: ^( list+=otherrule*)
{ list=$list; }
;
otherrule return [MyCustomClass c]
: foo bar
;
On 26 June 2011 18:57, Terence Parr <parrt at cs.usfca.edu> wrote:
> did you give token stream to the tree parser?
> Ter
> On Jun 26, 2011, at 6:03 AM, Dariusz Dwornikowski wrote:
>
> > Hello Again,
> >
> > What is the proper way to handle expression on abstract symbols (instead
> of
> > 1+2+3+4, ive got only a+b+c etc)
> >
> >
> > rmdef returns [ProcessDef process]
> > : ^(PEPADEF pan=IDENT a=expression)
> > {
> > process = new ProcessDef();
> > process.setLHS($pan.text);
> > }
> > ;
> >
> > expression
> > : ^(COOP a=expression b=expression)
> > | ^(PREFIX a=expression b=expression) { print($a.text); }
> > | ^(CHOICE a=expression b=expression)
> > | procek=IDENT
> > ;
> >
> >
> >
> > In this case print($a.text); causes NullPointerException,
> >
> >
> > --
> > Pozdrawiam,
> >
> -----------------------------------------------------------------------------
> > Dariusz Dwornikowski,
> > Institute of Computing Science, Poznań University of Technology
> > www.cs.put.poznan.pl/ddwornikowski/
> > room 421 WE | tel. +48 61 665 21 24 | mobile: +48 533 890 600
> >
> -----------------------------------------------------------------------------
> >
> > 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
>
--
Pozdrawiam,
-----------------------------------------------------------------------------
Dariusz Dwornikowski,
Institute of Computing Science, Poznań University of Technology
www.cs.put.poznan.pl/ddwornikowski/
room 421 WE | tel. +48 61 665 21 24 | mobile: +48 533 890 600
-----------------------------------------------------------------------------
More information about the antlr-interest
mailing list