# ambiguous grammar for online calculator, enum Expr defined in exprtrees.rs
!use crate::exprtrees::*;
!use crate::exprtrees::Expr::*;
!use rustlr::{LBox,makelbox};
absyntype Expr
nonterminal E
nonterminal ES
terminal + - * / ( ) ;
terminal int
topsym ES
resync ;
left * 500
left / 500
left + 400
left - 400
E --> int:m {m /* should be a Val(n) */}
E --> E:e1 + E:e2 { Plus(makelbox!(_e1_,e1),makelbox!(_e2_,e2)) }
E --> E:e1 - E:e2 { Minus(makelbox!(_e1_,e1),makelbox!(_e2_,e2)) }
E --> E:e1 / E:e2 { Divide(makelbox!(_e1_,e1),makelbox!(_e2_,e2)) }
E --> E:e1 * E:e2 { Times(makelbox!(_e1_,e1),makelbox!(_e2_,e2)) }
E --> - E:e { Negative(makelbox!(_e_,e)) }
E --> ( E:e ) { e }
ES --> E:n ; { Seq(vec![parser.lb(n)]) }
ES ==> ES:es@Seq(ref mut v)@ E:e ; {
v.push( makelbox!(_e_,e) );
es
} <==
# ==> and <== are required for rules spanning multiple lines
EOF
What could be better syntax than makelbox! ?
Plus(parser.lbox(0,e1), parser.lbox(2,e2)) ??
ZCParser can have a vector of (line,col) values popped off from the
stack in a separate vector that's clearly before each reduce. - the vector
will be in reverse.