[antlr-interest] Parsing Operators as Atoms?

DJB MASTER DJBall05 at hotmail.co.uk
Wed Nov 14 14:22:06 PST 2012


Given a list...

+
+
2
+
3
+
4
+
+
6
+

...How can I parse it so that it picks out all the infix trees (eg ^(+ ^(+ 2
3) 4)) and keeps the rest as single trees?

I've tried this rule...

expr: (a=atom -> $a)
(op='+' b=atom-> {$a.text != "+" && $b.text != "+"}? ^($op $expr $b) //
infix
-> {$b.text != "+"}? // HAVING TROUBLE COMING UP WITH THIS CORRECT REWRITE!
-> $expr $op $b)*; // simple list

atom: INT | '+';
INT : '0'..'9'+;

...and I think I'm almost there. I've been working on this for a couple of
days with no luck. 



--
View this message in context: http://antlr.1301665.n2.nabble.com/Parsing-Operators-as-Atoms-tp7579199.html
Sent from the ANTLR mailing list archive at Nabble.com.


More information about the antlr-interest mailing list