diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-01-14 19:41:51 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-01-14 19:52:56 -0800 |
commit | 11569fdec123e9c7aeaf38d8a122842c4c758fdf (patch) | |
tree | 2940f78906772581812211e00f93228a63ac30de | |
parent | f8b7d9d7e936bb53db3f978b54592b7af791d1ec (diff) | |
download | modelthing-11569fdec123e9c7aeaf38d8a122842c4c758fdf.tar.gz modelthing-11569fdec123e9c7aeaf38d8a122842c4c758fdf.zip |
parse out exponentiation
-rw-r--r-- | modelica-parser-lalrpop/helper_macros.txt | 24 | ||||
-rw-r--r-- | modelica-parser-lalrpop/src/ast.rs | 3 | ||||
-rw-r--r-- | modelica-parser-lalrpop/src/parser.lalrpop | 3 |
3 files changed, 29 insertions, 1 deletions
diff --git a/modelica-parser-lalrpop/helper_macros.txt b/modelica-parser-lalrpop/helper_macros.txt new file mode 100644 index 0000000..957586e --- /dev/null +++ b/modelica-parser-lalrpop/helper_macros.txt @@ -0,0 +1,24 @@ + +// === Helper Macros == + +Comma<T>: Vec<T> = { + <v:(<T> ",")*> <e:T?> => match e { + None=> v, + Some(e) => { + let mut v = v; + v.push(e); + v + } + } +}; + +Dotted<T>: Vec<T> = { + <v:(<T> ".")*> <e:T?> => match e { + None=> v, + Some(e) => { + let mut v = v; + v.push(e); + v + } + } +}; diff --git a/modelica-parser-lalrpop/src/ast.rs b/modelica-parser-lalrpop/src/ast.rs index f1e7d93..317944b 100644 --- a/modelica-parser-lalrpop/src/ast.rs +++ b/modelica-parser-lalrpop/src/ast.rs @@ -103,6 +103,7 @@ pub enum MathUnaryFunc { pub enum BinOperator { Multiply, Divide, + Exponentiate, Add, Subtract, } @@ -313,6 +314,8 @@ impl Debug for BinOperator { match *self { Multiply => write!(fmt, "*"), Divide => write!(fmt, "/"), + // TODO: this doesn't really work here + Exponentiate => write!(fmt, "^"), Add => write!(fmt, "+"), Subtract => write!(fmt, "-"), } diff --git a/modelica-parser-lalrpop/src/parser.lalrpop b/modelica-parser-lalrpop/src/parser.lalrpop index cb59a82..2d2469c 100644 --- a/modelica-parser-lalrpop/src/parser.lalrpop +++ b/modelica-parser-lalrpop/src/parser.lalrpop @@ -161,7 +161,8 @@ factor: Expr = { <lhs:factor> "/" <rhs:term> => Expr::BinExpr(BinOperator::Divide, Box::new(lhs), Box::new(rhs)), <lhs:factor> "^" <rhs:term> => - Expr::BinExpr(BinOperator::Divide, Box::new(lhs), Box::new(rhs)), + Expr::BinExpr(BinOperator::Exponentiate, Box::new(lhs), Box::new(rhs)), + // TODO: this could be a "negate" unary op? "-" <t:term> => Expr::BinExpr(BinOperator::Multiply, Box::new(Expr::Integer(-1)), Box::new(t)), term, |