2010/4/20 William <[email protected]>: >> The rule would look something like (not actually tested, but the >> guru's say it will solve my problem): >> equality_expr : relational_expr (('<' | '>' | '<=' | '>=' ) >> relational_expr)* ->^(OPERATOR relational_expr (('<' | '>' | '<=' | >> '>=' ) relational_expr )*) ; >> >> This is easy to scan (just one node to detect) and allows generic >> processing (which is useful in this case but I don't know if it >> universal useful). It does however add an other level to the tree >> which is not very neat. >> > > OK, so I'm liking this better and better. Go with #3 or #4, or even a > combination is OK with me. >
What is it you like? The rewrite style? >From the original posting: equality_expr : relational_expr ((LESS| MORE | GREATER_EQUAL | GREATER_EQUAL )^ relational_expr)* ; could also be written to something like (not test!!): equality_expr : relational_expr ((LESS| MORE | GREATER_EQUAL | GREATER_EQUAL ) relational_expr)* -> ^( LESS| MORE | GREATER_EQUAL | GREATER_EQUAL relational_expr+) ; This way you don't have the caret in the original expression. An other advantage of using lex tokens in stead of litterals (LESS vs '=') is the difference between the actual language operators (LESS, MORE, LPAREN) and rule operators (|, ), *, +) becomes clearer. And about combining 3 and 4: the extra node is a hack to provide a node with a known type. If each operator node has a known type, there is no need for this extra level. Joep Joep -- You received this message because you are subscribed to the Google Groups "jallib" 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/jallib?hl=en.
