当前位置: 首页>>代码示例>>C#>>正文


C# VariableType.Equals方法代码示例

本文整理汇总了C#中VariableType.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# VariableType.Equals方法的具体用法?C# VariableType.Equals怎么用?C# VariableType.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VariableType的用法示例。


在下文中一共展示了VariableType.Equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseExpression

        /// <summary>
        /// To parse the expression
        /// In EBNF: <expression> ::= <term>, { ‘+’|’-’, <term> };
        /// </summary>
        private Node ParseExpression(Node node, VariableType type)
        {
            CheckIfOutOfTokens();

            //A numeric expr can be made up of terms, but a string expr is made up of string factors only
            //(we can't multilply, divide or subtract strings)
            if (type.Equals(VariableType.Integer))
                node = ParseTerm(node);
            else if (type.Equals(VariableType.Boolean))
                node = ParseCondition(node);
            else
                node = ParseFactor(node, VariableType.String);

            //While a valid operator is found
            while (GetCurrentToken().Value.Equals("+") || (type.Equals(VariableType.Integer) &&
                                                           GetCurrentToken().Value.Equals("-")))
            {
                if (node == null)
                    node = new Node();

                Node clonedNode = node.Clone();
                node.Left = clonedNode;
                node.Value = GetCurrentToken().Value;
                TokenIndex++;

                if (type.Equals(VariableType.Integer))
                    node.Right = ParseTerm(node.Right);
                else
                    node.Right = ParseFactor(node.Right, VariableType.String);
            }

            return node;
        }
开发者ID:AlexDiru,项目名称:esper-compiler-v3,代码行数:37,代码来源:Parser.cs

示例2: ParseFactor

        /// <summary>
        /// Parse a facor in an expression
        /// EBNF: <factor> ::= <IDENTIFIER> | <CONSTANT> | ( ‘(’, <expression>, ‘)’ ) | ( '-', <factor> );
        /// We need to have the node where the factor is to be held
        /// A the type so we know whether we are expecting an int or a string
        /// </summary>
        private Node ParseFactor(Node node, VariableType type)
        {
            //Check if we have any tokens left
            CheckIfOutOfTokens();

            //First check for a parenthesised expression
            //( ‘(’, <expression>, ‘)’ )
            if (GetCurrentToken().Value.Equals("("))
            {
                //Skip the parenthesis
                TokenIndex++;

                //Get the expression
                node = ParseExpression(node, type);

                if (!GetCurrentToken().Value.Equals(")"))
                    Console.WriteLine("Expected closing bracket");

                //Skip the closing paren
                TokenIndex++;

                return node;
            }

            //If it's not a parenthesised expression
            //Check for a negative number
            //( '-', <factor> )
            if (type.Equals(VariableType.Integer))
            {
                if (GetCurrentToken().Value.Equals("-"))
                {
                    TokenIndex++;
                    node = ParseFactor(node, type);

                    //Apply the negative sign to the parsed factor
                    node.Value = "-" + node.Value;
                    return node;
                }
            }

            //We have narrowed it down to either a <IDENTIFIER> or <CONSTANT>
            node = new Node();

            //Store the value in the node
            node.Value = GetCurrentToken().Value;

            //Semantics - check if variable exists
            if (GetCurrentToken().Type.Equals(TokenType.Identifier) && !VariableExists(GetCurrentToken().Value))
                Console.WriteLine("Undeclared variable");

            //Give the node extra info to aid in code gen
            if (GetCurrentToken().Type.Equals(TokenType.Identifier))
                node.Attributes[0] = "VARIABLE";
            else
                node.Attributes[1] = "VALUE";

            TokenIndex++;

            return node;
        }
开发者ID:AlexDiru,项目名称:esper-compiler-v3,代码行数:66,代码来源:Parser.cs

示例3: IsAssignable

        public static bool IsAssignable(VariableType left, VariableType right)
        {
            if (left == null || right == null)
                return false;

            if (left.TypeEnum == VariableTypeEnum.Integer)
            {
                return (right.TypeEnum == VariableTypeEnum.Integer || right.TypeEnum == VariableTypeEnum.Char);
            }
            else if (left.TypeEnum == VariableTypeEnum.Array && right.TypeEnum == VariableTypeEnum.NULL)
            {
                return true;
            }
            return (left.Equals(right));
        }
开发者ID:Stasyamba,项目名称:L1Specializer,代码行数:15,代码来源:CompilerServices.cs


注:本文中的VariableType.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。