[antlr-interest] Problem with Tree Grammar
Stefan Mätje
Stefan.Maetje at esd-electronics.com
Fri Apr 13 09:16:35 PDT 2012
Hi,
unfortunately you don't describe what your problem is. But looking at
your if_statement rule from the tree grammar I would change the pattern
from this
^(IF expression ^(THEN statement+) elsif_statement+ ^(ELSE statement+))
to that pattern
^(IF expression ^(THEN statement+) elsif_statement* ^(ELSE statement+)?)
Your version mandates that the elsif_statement must always occur at
least once (+) and that there is always an ^(ELSE ...) clause (missing ?).
If your source input doesn't deliver an elsif_statement and also an
^(ELSE ...) clause the tree parser will abort after an exception.
Greetings,
Stefan
Am 13.04.2012 14:43, schrieb Nicholas Alexander:
>
> Hi i'm building a tree grammar for my AST
>
> I have 2 rules
>
>
> if_statement :
> ^(IF expression ^(THEN statement+) elsif_statement+ ^(ELSE statement+))
> ;
>
> elsif_statement :
> ^(ELSIF expression statement+)
> ;
>
> This seems to be a problem although I can construct the AST using this
>
>
> if_statement :
> IF ifexpr=expression THEN ( thenstats+=statement SEMI )+
> ( ELSIF elseifexpr=expression THEN ( elseifstats+=statement SEMI )+ )*
> ( ELSE ( elsestats+=statement SEMI )+ )?
> END IF
> -> ^(IF $ifexpr ^(THEN $thenstats+) ^(ELSIF $elseifexpr $elseifstats*)* ^(ELSE $elsestats*)?)
> ;
>
> Which works fine.
> Does anyone have any ideas how to address this?
>
> Thanks
>
> Nick Alexander
>
>
> Discovery is an authorised financial services provider.
>
> The information in this email is confidential and may have legal privileges. We intend it only for the use of the individual or entity we've addressed the communication to. If you've received this email by mistake please delete it and tell the sender. We forbid any unauthorised use, change, disclosure or sending of the contents of this email (including its attachments), whether in part or as a whole, unless consented to in writing by the sender, as it may be unlawful.
>
> We cannot guarantee this email has no malicious coding.
>
> We reserve the right to check, intercept and block emails or take any other action according to our email etiquette.
>
> Discovery will not be liable for any delivery delay, loss, harm, disruption or data corruption that may arise from this email.
>
> A full list of company directors is available on our website at: https://www.discovery.co.za/index_login.jhtml?p_content=/investor_relations/directorate.jhtml - or to get this list by email, please email directors_list at discovery.co.za
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
--
Mit freundlichen Grüßen
Stefan Mätje
Besuchen Sie uns auf der Hannover Messe 2012
in Halle 9, Stand D24
vom 23.-27. April 2012 in Hannover !
-------------------------------------------------------------------------
Dipl.-Ing. Stefan Mätje
System-Design
esd electronic system design gmbh
Vahrenwalder Str. 207 - 30165 Hannover - GERMANY
Telefon: 0511-37298-146 - Fax: 0511-37298-68
Bitte besuchen Sie uns im Internet unter http://www.esd.eu
Quality Products - Made in Germany
-------------------------------------------------------------------------
Geschäftsführer: Klaus Detering
Amtsgericht Hannover HRB 51373 - VAT-ID DE 115672832
-------------------------------------------------------------------------
More information about the antlr-interest
mailing list