예제 #1
0
        public override void Visit(AST_assignment assignment)
        {
            assignment.Expression.Accept(this);
            Variable var = variables.GetValueOrDefault(assignment.Identifier.Name);

            var.Set(value);
        }
예제 #2
0
        private AST_assignment Parse_assignment(TokenKind followSet)
        {
            IncrementDepth();

            AST_assignment assignment;
            AST_identifier identifier;
            AST_expression expression = null;

            identifier = Parse_identifier(Assignment);
            if (!Match(Assignment))
            {
                Error("':=' expected.", lastReadToken);
                if (LookAheadToken().Kind != Semicolon)
                {
                    // Assume an incorrect assignment symbol and skip over it
                    GetNextToken();
                }
            }
            expression = Parse_expression(Semicolon);

            assignment = new AST_assignment(identifier, expression);
            DecrementDepth();

            return(assignment);
        }
예제 #3
0
 public virtual void Visit(AST_assignment assignment)
 {
     IncrementDepth();
     assignment.Identifier.Accept(this);
     assignment.Expression.Accept(this);
     DecrementDepth();
 }
예제 #4
0
        override public void Visit(AST_assignment assignment)
        {
            base.Visit(assignment);
            string name = assignment.Identifier.Name;

            if (variables.ContainsKey(name))
            {
                if (assignment.Expression.DataType == variables.GetValueOrDefault(name).Type.Kind)
                {
                    if (loopVariables.ContainsKey(name))
                    {
                        Error("'" + name + "' is a loop variable, assignment not allowed.", assignment.Identifier);
                    }
                }
                else
                {
                    Error("Type mismatch in assignment.", assignment);
                }
            }
            else
            {
                Error("Variable '" + name + "' has not been declared.", assignment);
            }
        }
예제 #5
0
 public override void Visit(AST_assignment assignment)
 {
     assignment.Accept(evaluateVisitor);
 }