Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="value"></param>
 public Return(Expression value)
 {
     Value = value;
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
 public For(Body body, Assignment counter, Expression condition, Assignment initializer)
 {
     Body = body; Counter = counter; Condition = condition; Initializer = initializer;
 }
Exemplo n.º 5
0
 public If(Body elseBody, Body ifBody, Expression condition)
 {
     ElseBody = elseBody; IfBody = ifBody; Condition = condition;
 }
Exemplo n.º 6
0
 public Do(Expression condition, Body body)
 {
     Body = body;
     Condition = condition;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a expression element object.
 /// </summary>
 public Element(Expression expression)
 {
     ElementType = ElementType.Expression;
     Expression = expression;
 }
Exemplo n.º 8
0
 public While(Body body, Expression condition)
 {
     Body = body;
     Condition = condition;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="value"></param>
 public Continue(Expression value)
 {
     Value = value;
 }
Exemplo n.º 10
0
 public UnaryExpression(Expression indexer, Expression value, UnaryOperatorType unaryOperatorType)
 {
     Value = value; Indexer = indexer; UnaryOperatorType = unaryOperatorType;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="value"></param>
 public Break(Expression value)
 {
     Value = value;
 }
Exemplo n.º 12
0
 public BinaryExpression(Expression right, Expression left, BinaryOperatorType binaryOperatorType)
 {
     Right = right; Left = left; BinaryOperatorType = binaryOperatorType;
 }
Exemplo n.º 13
0
 public Assignment(Expression value, Expression index, string name)
 {
     Value = value; Name = name; Index = index;
 }
Exemplo n.º 14
0
 /// <summary>
 /// конструктор
 /// </summary>
 public Argument(Expression value, PassMethod passMethod)
 {
     Value = value; PassMethod = passMethod;
 }