示例#1
0
        private ISqlElement CreateUnionCondition(QueryEntityProperty property, QueryEntity nestedEntity)
        {
            if (!nestedEntity.mapping.Index.HasValue)
            {
                const string messageFormat = "invalid table name [{0}], table name must contain index";
                throw new InvalidOperationException(string.Format(messageFormat,
                                                                  nestedEntity.mapping.DbTableName));
            }
            var tableIndexColumnName = property.mapping.UnionLayout.TableIndexColumnName;

            if (string.IsNullOrEmpty(tableIndexColumnName))
            {
                const string messageFormat = "tableIndex column is not defined for [{0}.{1}]";
                throw new InvalidOperationException(string.Format(messageFormat,
                                                                  property.referer.mapping.QueryTableName, property.mapping.PropertyName));
            }
            ISqlElement result = new EqualityExpression
            {
                Left = new ColumnReferenceExpression
                {
                    Name  = tableIndexColumnName,
                    Table = GetTableDeclaration(property.referer)
                },
                Right = new LiteralExpression
                {
                    Value   = nestedEntity.mapping.Index,
                    SqlType = SqlType.ByteArray
                }
            };
            var typeColumnName = property.mapping.UnionLayout.TypeColumnName;

            if (!string.IsNullOrEmpty(typeColumnName))
            {
                result = new AndExpression
                {
                    Left = new EqualityExpression
                    {
                        Left = new ColumnReferenceExpression
                        {
                            Name  = typeColumnName,
                            Table = GetTableDeclaration(property.referer)
                        },
                        Right = new LiteralExpression
                        {
                            Value   = configurationItemReferenceType,
                            SqlType = SqlType.ByteArray
                        }
                    },
                    Right = result
                }
            }
            ;
            return(result);
        }
示例#2
0
 public virtual object Walk(EqualityExpression node)
 {
     if (Enter(node))
     {
         node.LeftExpression.Accept(this);
         if (node.RightExpression != null)
         {
             node.RightExpression.Accept(this);
         }
     }
     Exit(node);
     return(null);
 }
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IEqualityExpression node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            Success &= EqualityExpression.ResolveCompilerReferences(node, ErrorList, out IResultType ResolvedResult, out IResultException ResolvedException, out ISealableList <IExpression> ConstantSourceList, out ILanguageConstant ExpressionConstant);
            if (Success)
            {
                data = new Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant>(ResolvedResult, ResolvedException, ConstantSourceList, ExpressionConstant);
            }

            return(Success);
        }
示例#4
0
        public void Equals_MissingAtSymb()
        {
            EqualityExpression <string> expression = null;
            Dictionary <string, object> parameters = null;
            string whereParam = null;

            expression = Expression.Equals("a");
            parameters = expression.GetDynamicParameters("p1");
            whereParam = expression.ToSqlExpression("[Table].[Field]", "p1");
            Console.WriteLine(String.Join(",", parameters.Keys));

            Assert.AreEqual(parameters["p1"], "a");
            Assert.AreEqual(whereParam, " and [Table].[Field] = @p1");
        }
示例#5
0
 public override object Walk(EqualityExpression node)
 {
     var lv = node.LeftExpression.Accept(this);
     var rv = node.RightExpression.Accept(this);
     switch (node.Operator)
     {
         case TokenType.Equal:
             return OpEqual(lv, rv);
         case TokenType.NotEqual:
             return OpNotEqual(lv, rv);
         default:
             throw ErrorFactory.CreateInvalidProgramError("Invalid equality operator");
     }
 }
示例#6
0
        public override object Walk(EqualityExpression node)
        {
            var lv = node.LeftExpression.Accept(this);
            var rv = node.RightExpression.Accept(this);

            switch (node.Operator)
            {
            case TokenType.Equal:
                return(OpEqual(lv, rv));

            case TokenType.NotEqual:
                return(OpNotEqual(lv, rv));

            default:
                throw ErrorFactory.CreateInvalidProgramError("Invalid equality operator");
            }
        }
示例#7
0
        public ExprNode ParseEqualityExpression()
        {
            var exp = new EqualityExpression
            {
                Token          = Next(),
                LeftExpression = ParseRelationalExpression()
            };

            if (Next().IsNot(TokenType.Equal) && Next().IsNot(TokenType.NotEqual))
            {
                return(exp.LeftExpression);
            }
            exp.Operator = Next().Type;
            Consume();
            exp.RightExpression = ParseEqualityExpression();
            return(exp);
        }
示例#8
0
        // [26] EqualityExpression = RelationalExpression ('==' | '!=') RelationalExpression.
        private bool IsEqualityExpression(out EqualityExpression equalityExpression)
        {
            equalityExpression = new EqualityExpression();
            if (!IsRelationalExpression(out var relationalExpression))
            {
                return(false);
            }
            if (CheckToken(SyntaxKind.EqualsEqualsToken) || CheckToken(SyntaxKind.ExclamationEqualToken))
            {
                ;
            }
            if (!IsRelationalExpression(out var otherRelationalExpression))
            {
                return(false);
            }

            return(true);
        }
 public virtual bool Enter(EqualityExpression node)
 {
     return(true);
 }
 public virtual void Exit(EqualityExpression node)
 {
 }
示例#11
0
        public void SetUp(List <string> args)
        {
            if (verbose)
            {
                Console.WriteLine("import path:");

                foreach (string directory in pathResolver.Directories)
                {
                    Console.WriteLine("  " + directory);
                }
            }

            AppDomain domain = Thread.GetDomain();

            rootModule = new Module(null, null);

            foreach (Assembly assembly in domain.GetAssemblies())
            {
                AssemblyLoaded(assembly);
            }

            domain.AssemblyLoad += OnDomainAssemblyLoad;

            rootModule.SetName("null", null);
            rootModule.SetName("true", true);
            rootModule.SetName("false", false);
            rootModule.SetName("args", args);

            DefaultWhitespace.SetUp(rootModule, grammar);
            LineComment.SetUp(rootModule, grammar);
            BlockComment.SetUp(rootModule, grammar);
            Whitespace.SetUp(rootModule, grammar);
            Name.SetUp(rootModule, grammar);
            Name.SetUp(rootModule, grammar);
            Number.SetUp(rootModule, grammar);
            Base.String.SetUp(rootModule, grammar);

            Expression.SetUp(rootModule, grammar);
            ValueExpression.SetUp(rootModule, grammar);
            NameExpression.SetUp(rootModule, grammar);
            ParenExpression.SetUp(rootModule, grammar);
            MemberExpression.SetUp(rootModule, grammar);
            CallExpression.SetUp(rootModule, grammar);
            CallInParentScopeExpression.SetUp(rootModule, grammar);
            NewExpression.SetUp(rootModule, grammar);
            TypeExpression.SetUp(rootModule, grammar);
            IsExpression.SetUp(rootModule, grammar);
            AsExpression.SetUp(rootModule, grammar);
            UnaryExpression.SetUp(rootModule, grammar);
            NotExpression.SetUp(rootModule, grammar);
            MultiplicativeExpression.SetUp(rootModule, grammar);
            MultiplyExpression.SetUp(rootModule, grammar);
            DivideExpression.SetUp(rootModule, grammar);
            AdditiveExpression.SetUp(rootModule, grammar);
            AddExpression.SetUp(rootModule, grammar);
            SubtractExpression.SetUp(rootModule, grammar);
            ComparisonExpression.SetUp(rootModule, grammar);
            LessExpression.SetUp(rootModule, grammar);
            LessOrEqualExpression.SetUp(rootModule, grammar);
            EqualityExpression.SetUp(rootModule, grammar);
            InequalityExpression.SetUp(rootModule, grammar);
            GreaterExpression.SetUp(rootModule, grammar);
            GreaterOrEqualExpression.SetUp(rootModule, grammar);
            JunctionExpression.SetUp(rootModule, grammar);
            AndExpression.SetUp(rootModule, grammar);
            AssignmentExpression.SetUp(rootModule, grammar);
            AssignExpression.SetUp(rootModule, grammar);

            /*
             *  NameExpression = ValueExpression
             * ParenExpression = ValueExpression
             *
             * CallExpression < ValueExpression
             * CallInParentScopeExpression = CallExpression
             * MemberExpression = CallExpression
             *
             * NewExpression < CallExpression
             * TypeExpression < NewExpression
             * UnaryExpression < TypeExpression
             * MultiplicativeExpression < UnaryExpression
             * AdditiveExpression < MultiplicativeExpression
             * ComparisonExpression < AdditiveExpression
             * JunctionExpression < ComparisonExpression
             * AssignmentExpression < JunctionExpression
             */

            Precedence.SetPrecedence(NameExpression.pattern.Precedence,
                                     ValueExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(ParenExpression.pattern.Precedence,
                                     ValueExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(CallExpression.pattern.Precedence,
                                     ValueExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(CallInParentScopeExpression.pattern.Precedence,
                                     CallExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(MemberExpression.pattern.Precedence,
                                     CallExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(NewExpression.pattern.Precedence,
                                     CallExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(TypeExpression.pattern.Precedence,
                                     NewExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(UnaryExpression.pattern.Precedence,
                                     TypeExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(MultiplicativeExpression.pattern.Precedence,
                                     UnaryExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(AdditiveExpression.pattern.Precedence,
                                     MultiplicativeExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(ComparisonExpression.pattern.Precedence,
                                     AdditiveExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(JunctionExpression.pattern.Precedence,
                                     ComparisonExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(AssignmentExpression.pattern.Precedence,
                                     JunctionExpression.pattern.Precedence, Relation.Lower);

            Grammar.PatternChanged(ValueExpression.pattern,
                                   NameExpression.pattern,
                                   ParenExpression.pattern,
                                   MemberExpression.pattern,
                                   CallExpression.pattern,
                                   NewExpression.pattern,
                                   TypeExpression.pattern,
                                   UnaryExpression.pattern,
                                   MultiplicativeExpression.pattern,
                                   AdditiveExpression.pattern,
                                   ComparisonExpression.pattern,
                                   JunctionExpression.pattern,
                                   AssignmentExpression.pattern);

            PatternExpression.SetUp(rootModule, grammar);
            ReferencePatternExpression.SetUp(rootModule, grammar);
            AnyPatternExpression.SetUp(rootModule, grammar);
            TextPatternExpression.SetUp(rootModule, grammar);
            Option.SetUp(rootModule, grammar);
            BlockPatternExpression.SetUp(rootModule, grammar);
            ParenPatternExpression.SetUp(rootModule, grammar);
            TokenPatternExpression.SetUp(rootModule, grammar);
            RangePatternExpression.SetUp(rootModule, grammar);
            RepeatPatternExpression.SetUp(rootModule, grammar);
            AndPatternExpression.SetUp(rootModule, grammar);
            NotPatternExpression.SetUp(rootModule, grammar);
            LabelPatternExpression.SetUp(rootModule, grammar);
            SequencePatternExpression.SetUp(rootModule, grammar);
            AltPatternExpression.SetUp(rootModule, grammar);

            /*
             *  EndPatternExpression = ReferencePatternExpression
             * AnyPatternExpression = ReferencePatternExpression
             *  TextPatternExpression = ReferencePatternExpression
             *  BlockPatternExpression = ReferencePatternExpression
             *  ParenPatternExpression = ReferencePatternExpression
             *  TokenPatternExpression = ReferencePatternExpression
             *
             *  RangePatternExpression < ReferencePatternExpression
             *
             *  AndPatternExpression < RangePatternExpression
             *  NotPatternExpression = AndPatternExpression
             *  RepeatPatternExpression = AndPatternExpression
             *
             *  LabelPatternExpression < AndPatternExpression
             *  SequencePatternExpression < LabelPatternExpression
             *  AltPatternExpression < SequencePatternExpression
             */

            Precedence.SetPrecedence(AnyPatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(TextPatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(BlockPatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(ParenPatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(TokenPatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(RangePatternExpression.pattern.Precedence,
                                     ReferencePatternExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(AndPatternExpression.pattern.Precedence,
                                     RangePatternExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(NotPatternExpression.pattern.Precedence,
                                     AndPatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(RepeatPatternExpression.pattern.Precedence,
                                     AndPatternExpression.pattern.Precedence, Relation.Equal);

            Precedence.SetPrecedence(LabelPatternExpression.pattern.Precedence,
                                     AndPatternExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(SequencePatternExpression.pattern.Precedence,
                                     LabelPatternExpression.pattern.Precedence, Relation.Lower);

            Precedence.SetPrecedence(AltPatternExpression.pattern.Precedence,
                                     SequencePatternExpression.pattern.Precedence, Relation.Lower);

            Grammar.PatternChanged(ReferencePatternExpression.pattern,
                                   AnyPatternExpression.pattern,
                                   TextPatternExpression.pattern,
                                   BlockPatternExpression.pattern,
                                   ParenPatternExpression.pattern,
                                   TokenPatternExpression.pattern,
                                   RangePatternExpression.pattern,
                                   RepeatPatternExpression.pattern,
                                   AndPatternExpression.pattern,
                                   NotPatternExpression.pattern,
                                   LabelPatternExpression.pattern,
                                   SequencePatternExpression.pattern,
                                   AltPatternExpression.pattern);

            Statement.SetUp(rootModule, grammar);
            ExpressionStatement.SetUp(rootModule, grammar);
            CompoundStatement.SetUp(rootModule, grammar);
            PrintStatement.SetUp(rootModule, grammar);
            IfStatement.SetUp(rootModule, grammar);
            WhileStatement.SetUp(rootModule, grammar);
            ReturnStatement.SetUp(rootModule, grammar);
            ThrowStatement.SetUp(rootModule, grammar);
            TryStatement.SetUp(rootModule, grammar);
            ModuleStatement.SetUp(rootModule, grammar);
            FunctionStatement.SetUp(rootModule, grammar);
            Member.SetUp(rootModule, grammar);
            PatternMember.SetUp(rootModule, grammar);
            FieldMember.SetUp(rootModule, grammar);
            ConstructorMember.SetUp(rootModule, grammar);
            MethodMember.SetUp(rootModule, grammar);
            ClassStatement.SetUp(rootModule, grammar);
            SetPrecedenceStatement.SetUp(rootModule, grammar);
            UsingStatement.SetUp(rootModule, grammar);
            ImportStatement.SetUp(rootModule, grammar);
            TopLevelStatement.SetUp(rootModule, grammar);
            Program.SetUp(rootModule, grammar);

            Grammar.PatternChanged(Member.pattern, Statement.pattern);

            grammar.RootPattern = Program.pattern;

            hasBeenSetUp = true;
        }
示例#12
0
        public void VisitEqualityExpression(EqualityExpression equalityExpression)
        {
            VisitExpression(equalityExpression.Left);
            object left = ReturnValue;

            VisitExpression(equalityExpression.Right);
            object right = ReturnValue;

            ReturnValue = null;
            if (left != null && right != null) {
                switch (equalityExpression.Operator) {
                    case TokenType.Eq:
                        ReturnValue = left == right;
                        break;
                    case TokenType.EqStrict:
                        ReturnValue = left == right;
                        break;
                    case TokenType.Ne:
                        ReturnValue = left != right;
                        break;
                    case TokenType.NeStrict:
                        ReturnValue = left != right;
                        break;
                }
            }
        }
示例#13
0
        /// <summary>
        /// The following are rules for C expressions.
        /// </summary>
        public static void SetExpressionRules()
        {
            // expression
            //   : assignment-expression [ ',' assignment-expression ]*
            Expression.Is(
                AssignmentExpression
                .OneOrMore(Comma)
                .Then(exprs => {
                if (exprs.Count == 1)
                {
                    return(exprs[0]);
                }
                return(AssignmentList.Create(exprs));
            })
                );

            // primary-expression
            //   : identifier          # Cannot be a typedef name.
            //   | constant
            //   | string-literal
            //   | '(' expression ')'
            PrimaryExpression.Is(
                Either(Variable)
                .Or(Constant)
                .Or(StringLiteral)
                .Or(
                    (LeftParen).Then(Expression).Then(RightParen)
                    )
                );

            // An identifier for a variable must not be defined as a typedef name.
            Variable.Is(
                Identifier.Check(result => !result.Environment.IsTypedefName(result.Result)).Then(AST.Variable.Create)
                );

            // constant
            //   : const-char
            //   : const-int
            //   : const-float
            Constant.Is(
                Either(ConstChar)
                .Or(ConstInt)
                .Or(ConstFloat)
                );


            // constant-expression
            //   : conditional-expression
            //
            // Note:
            // The size of an array should be a constant.
            // Note that the check is actually performed in semantic analysis.
            ConstantExpression.Is(
                ConditionalExpression
                );

            // conditional-expression
            //   : logical-or-expression [ '?' expression ':' conditional-expression ]?
            ConditionalExpression.Is(
                (LogicalOrExpression)
                .Then(
                    Given <Expr>()
                    .Then(Question)
                    .Then(Expression)
                    .Then(Colon)
                    .Then(ConditionalExpression)
                    .Then(AST.ConditionalExpression.Create)
                    .Optional()
                    )
                );

            // assignment-expression
            //   : unary-expression assignment-operator assignment-expression   # first-set = first-set(unary-expression)
            //   | conditional-expression                                       # first-set = first-set(cast-expression) = first-set(unary-expression) ++ { '(' }
            //
            // Note:
            //   Assignment operators are:
            //     '=', '*=', '/=', '%=', '+=', '-=', '<<=', '>>=', '&=', '^=', '|='
            AssignmentExpression.Is(
                Either(
                    AssignmentOperator(
                        UnaryExpression,
                        AssignmentExpression,
                        BinaryOperatorBuilder.Create(Assign, Assignment.Create),
                        BinaryOperatorBuilder.Create(MultAssign, AST.MultAssign.Create),
                        BinaryOperatorBuilder.Create(DivAssign, AST.DivAssign.Create),
                        BinaryOperatorBuilder.Create(ModAssign, AST.ModAssign.Create),
                        BinaryOperatorBuilder.Create(AddAssign, AST.AddAssign.Create),
                        BinaryOperatorBuilder.Create(SubAssign, AST.SubAssign.Create),
                        BinaryOperatorBuilder.Create(LeftShiftAssign, LShiftAssign.Create),
                        BinaryOperatorBuilder.Create(RightShiftAssign, RShiftAssign.Create),
                        BinaryOperatorBuilder.Create(BitwiseAndAssign, AST.BitwiseAndAssign.Create),
                        BinaryOperatorBuilder.Create(XorAssign, AST.XorAssign.Create),
                        BinaryOperatorBuilder.Create(BitwiseOrAssign, AST.BitwiseOrAssign.Create)
                        )
                    ).Or(
                    ConditionalExpression
                    )
                );

            // postfix-expression
            //   : primary-expression [
            //         '[' expression ']'                      # Get element from array
            //       | '(' [argument-expression-list]? ')'     # Function call
            //       | '.' identifier                          # Get member from struct/union
            //       | '->' identifier                         # Get member from struct/union
            //       | '++'                                    # Increment
            //       | '--'                                    # Decrement
            //     ]*
            PostfixExpression.Is(
                PrimaryExpression
                .Then(
                    Either(
                        Given <Expr>()
                        .Then(LeftBracket)
                        .Then(Expression)
                        .Then(RightBracket)
                        .Then((array, index) => Dereference.Create(AST.Add.Create(array, index)))
                        ).Or(
                        Given <Expr>()
                        .Then(LeftParen)
                        .Then(ArgumentExpressionList.Optional(ImmutableList <Expr> .Empty))
                        .Then(RightParen)
                        .Then(FuncCall.Create)
                        ).Or(
                        Given <Expr>()
                        .Then(Period)
                        .Then(Identifier)
                        .Then(Attribute.Create)
                        ).Or(
                        Given <Expr>()
                        .Then(RightArrow)
                        .Then(Identifier)
                        .Then((expr, member) => Attribute.Create(Dereference.Create(expr), member))
                        ).Or(
                        Given <Expr>()
                        .Then(Increment)
                        .Then(PostIncrement.Create)
                        ).Or(
                        Given <Expr>()
                        .Then(Decrement)
                        .Then(PostDecrement.Create)
                        ).ZeroOrMore()
                    )
                );

            // argument-expression-list
            //   : assignment-expression [ ',' assignment-expression ]*
            ArgumentExpressionList.Is(
                AssignmentExpression.OneOrMore(Comma)
                );

            // unary-expression
            //   : postfix-expression               # first-set = { id, const, string }
            //   | '++' unary-expression            # first-set = { '++' }
            //   | '--' unary-expression            # first-set = { '--' }
            //   | unary-operator cast-expression   # first-set = { '&', '*', '+', '-', '~', '!' }
            //   | 'sizeof' unary-expression        # first-set = { 'sizeof' }
            //   | 'sizeof' '(' Type-name ')'       # first-set = { 'sizeof' }
            //
            // Notes:
            // 1. unary-operator can be '&', '*', '+', '-', '~', '!'.
            // 2. The last two rules are ambiguous: you can't figure out whether the x in sizeof(x) is a typedef of a variable.
            //    I have a parser hack for this: add a parser environment to track all the typedefs.
            // 3. first_set = first_set(postfix-expression) + { '++', '--', '&', '*', '+', '-', '~', '!', 'sizeof' }
            //              = first_set(primary-expression) + { '++', '--', '&', '*', '+', '-', '~', '!', 'sizeof' }
            //              = { id, const, string, '++', '--', '&', '*', '+', '-', '~', '!', 'sizeof' }
            UnaryExpression.Is(
                Either(
                    PostfixExpression
                    ).Or(
                    (Increment).Then(UnaryExpression).Then(PreIncrement.Create)
                    ).Or(
                    (Decrement).Then(UnaryExpression).Then(PreDecrement.Create)
                    ).Or(
                    (BitwiseAnd).Then(CastExpression).Then(Reference.Create)
                    ).Or(
                    (Mult).Then(CastExpression).Then(Dereference.Create)
                    ).Or(
                    (Add).Then(CastExpression).Then(Positive.Create)
                    ).Or(
                    (Sub).Then(CastExpression).Then(Negative.Create)
                    ).Or(
                    (BitwiseNot).Then(CastExpression).Then(AST.BitwiseNot.Create)
                    ).Or(
                    (LogicalNot).Then(CastExpression).Then(AST.LogicalNot.Create)
                    ).Or(
                    (SizeOf).Then(UnaryExpression).Then(SizeofExpr.Create)
                    ).Or(
                    (SizeOf).Then(LeftParen).Then(TypeName).Then(RightParen).Then(SizeofType.Create)
                    )
                );

            // cast-expression
            //   : unary-expression                     # first-set = { id, const, string, '++', '--', '&', '*', '+', '-', '~', '!', 'sizeof' }
            //   | '(' type_name ')' cast-expression    # first-set = '('
            CastExpression.Is(
                Either(
                    UnaryExpression
                    ).Or(
                    (LeftParen).Then(TypeName).Then(RightParen).Then(CastExpression)
                    .Then(TypeCast.Create)
                    )
                );

            // multiplicative-expression
            //   : cast-expression [ [ '*' | '/' | '%' ] cast-expression ]*
            MultiplicativeExpression.Is(
                BinaryOperator(
                    CastExpression,
                    BinaryOperatorBuilder.Create(Mult, Multiply.Create),
                    BinaryOperatorBuilder.Create(Div, Divide.Create),
                    BinaryOperatorBuilder.Create(Mod, Modulo.Create)
                    )
                );

            // additive-expression
            //   : multiplicative-expression [ [ '+' | '-' ] multiplicative-expression ]*
            AdditiveExpression.Is(
                BinaryOperator(
                    MultiplicativeExpression,
                    BinaryOperatorBuilder.Create(Add, AST.Add.Create),
                    BinaryOperatorBuilder.Create(Sub, AST.Sub.Create)
                    )
                );

            // shift-expression
            //   : additive-expression [ [ '<<' | '>>' ] additive-expression ]*
            ShiftExpression.Is(
                BinaryOperator(
                    AdditiveExpression,
                    BinaryOperatorBuilder.Create(LeftShift, LShift.Create),
                    BinaryOperatorBuilder.Create(RightShift, RShift.Create)
                    )
                );

            // relational-expression
            //   : shift-expression [ [ '<' | '>' | '<=' | '>=' ] shift-expression ]*
            RelationalExpression.Is(
                BinaryOperator(
                    ShiftExpression,
                    BinaryOperatorBuilder.Create(Less, AST.Less.Create),
                    BinaryOperatorBuilder.Create(Greater, AST.Greater.Create),
                    BinaryOperatorBuilder.Create(LessEqual, LEqual.Create),
                    BinaryOperatorBuilder.Create(GreaterEqual, GEqual.Create)
                    )
                );

            // equality-expression
            //   : relational-expression [ [ '==' | '!=' ] relational-expression ]*
            EqualityExpression.Is(
                BinaryOperator(
                    RelationalExpression,
                    BinaryOperatorBuilder.Create(Equal, AST.Equal.Create),
                    BinaryOperatorBuilder.Create(NotEqual, AST.NotEqual.Create)
                    )
                );

            // and-expression
            //   : equality-expression [ '&' equality-expression ]*
            AndExpression.Is(
                BinaryOperator(
                    EqualityExpression,
                    BinaryOperatorBuilder.Create(BitwiseAnd, AST.BitwiseAnd.Create)
                    )
                );

            // exclusive-or-expression
            //   : and-expression [ '^' and-expression ]*
            ExclusiveOrExpression.Is(
                BinaryOperator(
                    AndExpression,
                    BinaryOperatorBuilder.Create(Xor, AST.Xor.Create)
                    )
                );

            // inclusive-or-expression
            //   : exclusive-or-expression [ '|' exclusive-or-expression ]*
            InclusiveOrExpression.Is(
                BinaryOperator(
                    ExclusiveOrExpression,
                    BinaryOperatorBuilder.Create(BitwiseOr, AST.BitwiseOr.Create)
                    )
                );

            // logical-and-expression
            //   : inclusive-or-expression [ '&&' inclusive-or-expression ]*
            LogicalAndExpression.Is(
                BinaryOperator(
                    InclusiveOrExpression,
                    BinaryOperatorBuilder.Create(LogicalAnd, AST.LogicalAnd.Create)
                    )
                );

            // logical-or-expression
            //   :logical-and-expression [ '||' logical-and-expression ]*
            LogicalOrExpression.Is(
                BinaryOperator(
                    LogicalAndExpression,
                    BinaryOperatorBuilder.Create(LogicalOr, AST.LogicalOr.Create)
                    )
                );
        }
示例#14
0
文件: Parser.cs 项目: buunguyen/bike
 public ExprNode ParseEqualityExpression()
 {
     var exp = new EqualityExpression
                   {
                       Token = Next(),
                       LeftExpression = ParseRelationalExpression()
                   };
     if (Next().IsNot(TokenType.Equal) && Next().IsNot(TokenType.NotEqual))
         return exp.LeftExpression;
     exp.Operator = Next().Type;
     Consume();
     exp.RightExpression = ParseEqualityExpression();
     return exp;
 }
示例#15
0
 public virtual object Walk(EqualityExpression node)
 {
     if (Enter(node))
     {
         node.LeftExpression.Accept(this);
         if (node.RightExpression != null)
             node.RightExpression.Accept(this);
     }
     Exit(node);
     return null;
 }
示例#16
0
 public override void Exit(EqualityExpression node)
 {
     level--;
 }
示例#17
0
 public virtual void Exit(EqualityExpression node)
 {
 }
示例#18
0
 public virtual bool Enter(EqualityExpression node)
 {
     return true;
 }
示例#19
0
 public override bool Enter(EqualityExpression node)
 {
     Print("EqualityExpression");
     level++;
     return(true);
 }
示例#20
0
 public override bool Enter(EqualityExpression node)
 {
     Print("EqualityExpression");
     level++;
     return true;
 }
示例#21
0
 public override void Exit(EqualityExpression node)
 {
     level--;
 }