示例#1
0
        public void visit_vardeclNode(AST node)
        {
            string name = node.left.token.getLexeme();

            if (node.right != null)
            {
                memory[name] = this.visit(node.right);
            }
            else
            {
                Utils.Type bType = node.builtinType;
                if (bType == Utils.Type.INTEGER)
                {
                    memory[name] = 0;
                }
                else if (bType == Utils.Type.STRING)
                {
                    memory[name] = "";
                }
                else if (bType == Utils.Type.BOOLEAN)
                {
                    memory[name] = false;
                }
            }
        }
示例#2
0
 public void visit_vardeclNode(AST node)
 {
     this.visit(node.left);
     if (node.right != null)
     {
         this.visit(node.right);
         Utils.Type left  = node.left.builtinType;
         Utils.Type right = node.right.builtinType;
         if (left == Utils.Type.INTEGER && left == right)
         {
             node.builtinType = Utils.Type.INTEGER;
         }
         else if (left == Utils.Type.BOOLEAN && left == right)
         {
             node.builtinType = Utils.Type.BOOLEAN;
         }
         else if (left == Utils.Type.STRING && left == right)
         {
             node.builtinType = Utils.Type.STRING;
         }
         else
         {
             node.builtinType = Utils.Type.ERROR;
             this.ThrowErrorMessage(new VarDeclTypeMismatchError(node.left, node.right));
         }
     }
     else
     {
         node.builtinType = node.left.builtinType;
     }
 }
示例#3
0
 public void visit_assertNode(AST node)
 {
     this.visit(node.left);
     Utils.Type expr = node.left.builtinType;
     if (expr == Utils.Type.BOOLEAN)
     {
         node.builtinType = Utils.Type.BOOLEAN;
     }
     else
     {
         node.builtinType = Utils.Type.ERROR;
         this.ThrowErrorMessage(new TypeNotSupportedError(node, node.left));
     }
 }
示例#4
0
 public void visit_rangeNode(AST node)
 {
     Utils.Type left  = node.left.builtinType;
     Utils.Type right = node.right.builtinType;
     if (left == Utils.Type.INTEGER && left == right)
     {
         node.builtinType = Utils.Type.INTEGER;
     }
     else
     {
         node.builtinType = Utils.Type.ERROR;
         this.ThrowErrorMessage(new VarDeclTypeMismatchError(node.left, node.right));
     }
 }
示例#5
0
 public void visit_readNode(AST node)
 {
     this.visit(node.left);
     Utils.Type expr = node.left.builtinType;
     if (expr == Utils.Type.INTEGER)
     {
         node.builtinType = Utils.Type.INTEGER;
     }
     else if (expr == Utils.Type.STRING)
     {
         node.builtinType = Utils.Type.STRING;
     }
     else
     {
         node.builtinType = Utils.Type.ERROR;
         this.ThrowErrorMessage(new TypeNotSupportedError(node, node.left));
     }
 }
示例#6
0
        public void visit_unaryOpNode(AST node)
        {
            this.visit(node.left);
            TokenType op = node.token.getType();

            Utils.Type left = node.left.builtinType;
            if (op == TokenType.NOT)
            {
                if (left == Utils.Type.BOOLEAN)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new UnaryOperandTypeError(node.left, node));
                }
            }
        }
示例#7
0
        public void visit_opNode(AST node)
        {
            this.visit(node.left);
            this.visit(node.right);
            TokenType op = node.token.getType();

            Utils.Type left  = node.left.builtinType;
            Utils.Type right = node.right.builtinType;
            if (op == TokenType.PLUS)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.INTEGER;
                }
                else if (left == Utils.Type.STRING && left == right)
                {
                    node.builtinType = Utils.Type.STRING;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.MINUS)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.INTEGER;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.DIV)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.INTEGER;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.MULT)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.INTEGER;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.LESSTHAN)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else if (left == Utils.Type.STRING && left == right)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else if (left == Utils.Type.BOOLEAN)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.EQUALS)
            {
                if (left == Utils.Type.INTEGER && left == right)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else if (left == Utils.Type.STRING && left == right)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else if (left == Utils.Type.BOOLEAN)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
            else if (op == TokenType.AND)
            {
                if (left == Utils.Type.BOOLEAN && left == right)
                {
                    node.builtinType = Utils.Type.BOOLEAN;
                }
                else
                {
                    node.builtinType = Utils.Type.ERROR;
                    this.ThrowErrorMessage(new BinaryOperandTypeError(node.left, node.right, node));
                }
            }
        }