public bool VerifyExpression(SymbolTable symbolTable, Expression expression) { // // Verify expression. // try { GetExpressionType(symbolTable, expression); return true; } catch (VerifierException x) { System.Diagnostics.Debug.WriteLine(x.Message); return false; } }
/// <summary> /// Конструктор /// </summary> /// <param name="value"></param> public Return(Expression value) { Value = value; }
public Type GetExpressionType(SymbolTable symbolTable, Expression expression) { if (expression is UnaryExpression) { UnaryExpression unary = (UnaryExpression)expression; return FindType(GetExpressionType(symbolTable, unary.Value), unary.UnaryOperatorType); } else if (expression is BinaryExpression) { BinaryExpression binary = (BinaryExpression)expression; return FindType(GetExpressionType(symbolTable, binary.Left), GetExpressionType(symbolTable, binary.Right), binary.BinaryOperatorType); } else if (expression is Literal) { Literal literal = expression as Literal; if (literal.LiteralType == LiteralType.Boolean) return new Type(PrimitiveType.Boolean); if (literal.LiteralType == LiteralType.Character) return new Type(PrimitiveType.Character); if (literal.LiteralType == LiteralType.Integer) return new Type(PrimitiveType.Integer); if (literal.LiteralType == LiteralType.Real) return new Type(PrimitiveType.Real); if (literal.LiteralType == LiteralType.String) return new Type(PrimitiveType.Void); } else if (expression is Name) { return ((Variable)symbolTable.Find(((Name)expression).Value, SymbolType.Variable).SyntaxObject).Type; } else if (expression is Call) { return ((Call)expression).Type; } return null; }
public For(Body body, Assignment counter, Expression condition, Assignment initializer) { Body = body; Counter = counter; Condition = condition; Initializer = initializer; }
public If(Body elseBody, Body ifBody, Expression condition) { ElseBody = elseBody; IfBody = ifBody; Condition = condition; }
public Do(Expression condition, Body body) { Body = body; Condition = condition; }
/// <summary> /// Creates a expression element object. /// </summary> public Element(Expression expression) { ElementType = ElementType.Expression; Expression = expression; }
public While(Body body, Expression condition) { Body = body; Condition = condition; }
/// <summary> /// Конструктор /// </summary> /// <param name="value"></param> public Continue(Expression value) { Value = value; }
public UnaryExpression(Expression indexer, Expression value, UnaryOperatorType unaryOperatorType) { Value = value; Indexer = indexer; UnaryOperatorType = unaryOperatorType; }
/// <summary> /// Конструктор /// </summary> /// <param name="value"></param> public Break(Expression value) { Value = value; }
public BinaryExpression(Expression right, Expression left, BinaryOperatorType binaryOperatorType) { Right = right; Left = left; BinaryOperatorType = binaryOperatorType; }
public Assignment(Expression value, Expression index, string name) { Value = value; Name = name; Index = index; }
/// <summary> /// конструктор /// </summary> public Argument(Expression value, PassMethod passMethod) { Value = value; PassMethod = passMethod; }