Oh, and thanks. I've put your code through a bunch of crazy scenarios after adapting it to my full needs and it works perfectly. I can now move forward with changes to the tree parser and interpreter. Thanks again.
On Wed, May 4, 2011 at 6:19 PM, John B. Brodie <[email protected]> wrote: > I think that basically you want Application (I come from the lambda > calculus and function invocation is called Application therein) to be a > post-fix operator. > > If you look at grammars for Java or C or other C-like languages you will > see (I believe) that indexing into an array and/or projecting a field > out of a tuple (record) and probably others-like-them are post-fix > operators. > > So I would recommend the following (tested, but not using your > incomplete gist framework) --- replacing your term rule with: > > //Expressions > primary > : IDENT > | '('! expression ')'! > | INTEGER > | DOUBLE > | BOOLEAN > ; > > term > : (primary -> primary) ( suffix[$term.tree] -> suffix )* > ; > > suffix [CommonTree term] : > ( x='(' modifiers? ')' -> ^(APPLICATION[$x,"A"] {$term} modifiers?) ) > | ( x='[' modifiers ']' -> ^(INDEXING[$x,"I"] {$term} modifiers) ) > | ( x='.' (p=IDENT|p=INTEGER) -> ^(PROJECTION[$x,"P"] {$term} $p) ) > ; > > modifiers : expression (','! expression)* ; > > > > with an appropriate tokens{} section defining the APPLICATION; > INDEXING; and PROJECTION imaginary tokens. > > the above is a little complicated in order to get the imaginary token > representing the suffix operator to be a tree root. > > note that the stuff in the []'s after the imaginary token name is for > error reporting and/or tree pretty printing. keep the $x but change the > string to suite your need. > > hope this helps > -jbb > > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- 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.
