public static dynamic EvaluateConstExpr(Node expr, SymTable symTable) { try { switch (expr) { case ConstNode _: return(expr.Value); case CastOperator _: return(EvaluateConstExpr(expr.Childs[0], symTable)); case DesignatorNode _: var temp = symTable.LookUp(expr.Value.ToString()); if (temp is ConstSymbol) { return(((SimpleConstant)(temp as ConstSymbol).Value).Value); } throw new EvaluatorException("Illegal operation"); case BinOpNode _: return(BinaryOps[(Tokenizer.TokenSubType)expr.Value](EvaluateConstExpr(expr.Childs[0], symTable), EvaluateConstExpr(expr.Childs[1], symTable))); case UnOpNode _: return(UnaryOps[(Tokenizer.TokenSubType)expr.Value](EvaluateConstExpr(expr.Childs[0], symTable))); } } catch (RuntimeBinderException) { throw new ParserException("Invalid operation in constant expression", expr.Line, expr.Position); } throw new InvalidOperationException($"Node of type {expr.GetType()} met in expression"); }
public ExprItem(BinaryOps op) { this.Op = op; this.Priority = _priorityByOp[op]; this.Expr = null; }