I am translating from one languague to another. My grammar is basically working; however, I just discovered an error in translating a unary negative expression: "- b * 2 - c / 20". My incorrect translation is "- (b * 2 - c / 20)." The relavant parts of the combined grammar are:
factor
: ...
| '(' expr ')' -> ^(PAREN expr)
| '+' expr -> expr // unary '+'
| '-' expr -> ^(NEG expr) // unary '-'
;
The relevant parts of the tree grammar are:
expr
: ...
| ^(NEG neg_expr=expr) -> negate(expr={$neg_expr.st})
// emits "- (expr)"
| ^(PAREN paren_expr=expr) -> paren(expr={$paren_expr.st})
// emits "(expr)"
;
In addition, in the combined grammar, I used the "arithmetic expression
pattern" of encoding precedence in an expression, term, factor "tree"
and collapsing that tree into a single expression in the tree grammar.
I have two questions that I think are related. First, when tranlating
parenthesized expressions, I had to encode the parentheses (see the
PAREN imaginary token in my combined grammar) in order to emit the
correct parenthesized expression in the translated grammar. I'm
wondering if another technique exists to emit the correct translated
expression.
Second, as I mentioned at the beginning of the note, I translate unary
negative expressions incorrectly. Any examples on how to perform these
translations correctly?
Thanks.
--
Lawrence Allan Jones
Senior Developer / Technical Advisor
Aspen Technology, Inc.
2500 CityWest Blvd. Suite 1500
Houston, Texas 77042
USA
281-504-3324 (work)
281-504-3395 (fax)
[EMAIL PROTECTED]
www.aspentech.com <http://www.aspentech.com/>
This e-mail and any attachments are intended only for use by the addressee(s)
named herein and may contain legally privileged and/or confidential
information. If you are not the intended recipient of this e-mail, you are
hereby notified any dissemination, distribution or copying of this email, and
any attachments thereto, is strictly prohibited. If you receive this email in
error please immediately notify the sender and permanently delete the original
copy and any copy of any e-mail, and any printout thereof.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
<<inline: email_2_03.gif>>
<<inline: email_2_04.gif>>
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
