예제 #1
0
파일: Parser.cs 프로젝트: pixelport/NetLua
        Ast.UnaryExpression ParseUnaryExpr(ParseTreeNode node)
        {
            if (node.Term.Name == "UnaryExpr")
            {
                Ast.IExpression expr   = ParseExpression(node.ChildNodes[1]);
                var             opNode = node.ChildNodes[0].ChildNodes[0];
                Ast.UnaryOp     op     = Ast.UnaryOp.Invert;
                switch (opNode.Token.ValueString)
                {
                case "not":
                    op = Ast.UnaryOp.Negate; break;

                case "-":
                    op = Ast.UnaryOp.Invert; break;

                case "#":
                    op = Ast.UnaryOp.Length; break;
                }
                return(new Ast.UnaryExpression()
                {
                    Expression = expr,
                    Operation = op
                });
            }
            throw new Exception("Invalid UnaryExpr node");
        }
예제 #2
0
 public UnaryOp(Ast.UnaryOp operation, Expression operand)
 {
     Operation = operation;
     Operand   = operand;
 }