コード例 #1
0
        private Expression Expr()
        {
            Expression expr = new Expression ("expr", currentToken.Row, currentToken.Column);
            if ((Token.Types)currentToken.Type == Token.Types.LeftParenthesis ||
                (Token.Types)currentToken.Type == Token.Types.IntLiteral ||
                (Token.Types)currentToken.Type == Token.Types.StringLiteral ||
                (Token.Types)currentToken.Type == Token.Types.Identifier ||
                (Token.Types)currentToken.Type == Token.Types.BoolLiteral) {

                Expression left = Conjuct ();
                Expression right = ExprLogical ();

                if (right.Name != null) {
                    right.AddChild (left);
                    expr.AddChild (right);
                    return expr;
                } else {
                    expr.AddChild (left);
                    return expr;
                }
            } else if ((Token.Types)currentToken.Type == Token.Types.Not) {
                NotExpr notExpr = new NotExpr ("!", currentToken.Row, currentToken.Column);
                Match (Token.Types.Not);
                notExpr.AddChild (Expr ());
                return notExpr;
            }

            throw new SyntaxError ("invalid token to start expression " + currentToken.Type,
            currentToken.Row, currentToken.Column);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: jimxshaw/samples-csharp
        private Expression GetNextExpression(List<string> Parts, Expression FirstExpression)
        {
            if (Parts.Count < 2)
            {
                return FirstExpression;
            }

            Expression secondExpression = new ValueExpression(Parts[1]);
            string part = Parts[0];
            Parts.RemoveAt(0);
            Parts.RemoveAt(0);
            if (part.ToUpper().Equals("OR"))
            {
                return new OrExpression(FirstExpression, GetNextExpression(Parts, secondExpression));
            }
            else
            {
                return new AndExpression(FirstExpression, GetNextExpression(Parts, secondExpression));
            }
        }
コード例 #3
0
 public void Visit(Expression node)
 {
     VisitChildren (node);
 }
コード例 #4
0
 public AndExpression(Expression expression1, Expression expression2)
 {
     this.Expression1 = expression1;
     this.Expression2 = expression2;
 }