本文整理汇总了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;
}
示例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;
}
示例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));
}