diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-18 11:27:27 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-18 11:27:27 -0800 |
commit | c564b5c4c0efc541886648ba97d69a4ad25d7464 (patch) | |
tree | c4fada68d3f6d91797489e39d901a3d5c2b7f92e /modelica-parser-lalrpop/src/parser.lalrpop | |
parent | 37dba2763441721456be50f709c38bee9f6e71f9 (diff) | |
download | modelthing-c564b5c4c0efc541886648ba97d69a4ad25d7464.tar.gz modelthing-c564b5c4c0efc541886648ba97d69a4ad25d7464.zip |
parser: support for math functions (sin, exp, log, etc)
Diffstat (limited to 'modelica-parser-lalrpop/src/parser.lalrpop')
-rw-r--r-- | modelica-parser-lalrpop/src/parser.lalrpop | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/modelica-parser-lalrpop/src/parser.lalrpop b/modelica-parser-lalrpop/src/parser.lalrpop index 8df904e..2c64889 100644 --- a/modelica-parser-lalrpop/src/parser.lalrpop +++ b/modelica-parser-lalrpop/src/parser.lalrpop @@ -1,6 +1,6 @@ use std::str::FromStr; use ast::{ModelicaModel, ComponentDeclaration, ComponentClause, ComponentPrefix, Connection, - SimpleEquation, Expr, BinOperator}; + SimpleEquation, Expr, BinOperator, MathUnaryFunc}; // This is an incomplete, non-standards-compliant, minimum-viable parser // Based on the Modelica 3.3r1 Spec @@ -104,8 +104,21 @@ term: Expr = { integer => Expr::Integer(<>), float => Expr::Float(<>), identifier => Expr::Ident(<>), - "der" "(" <e:expr> ")" => Expr::Der(Box::new(e)), - "abs" "(" <e:expr> ")" => Expr::Abs(Box::new(e)), + "der" "(" <e:expr> ")" => Expr::Der(Box::new(e)), + "abs" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Abs, Box::new(e)), + "sqrt" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Sqrt, Box::new(e)), + "sin" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Sin, Box::new(e)), + "cos" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Cos, Box::new(e)), + "tan" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Tan, Box::new(e)), + "asin" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Asin, Box::new(e)), + "acos" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Acos, Box::new(e)), + "atan" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Atan, Box::new(e)), + "sinh" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Sinh, Box::new(e)), + "cosh" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Cosh, Box::new(e)), + "tanh" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Tanh, Box::new(e)), + "exp" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Exp, Box::new(e)), + "log" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Log, Box::new(e)), + "log10" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Log10, Box::new(e)), "(" <e:expr> ")" => e, }; |