Exemple #1
0
        public Variable getVariable(Identifier identifier)
        {
            Variable variable = variables[identifier.name];

            if (variable == null)
            {
                return getParentVariable(identifier);
            }

            return variable;
        }
        // assignment_stmt = { lvalue " = " } ( expression | new_instance ) terminator ;
        public static Assignment produce(Queue<Token> tokens)
        {
            List<Symbol.Symbol> childSymbols = new List<Symbol.Symbol>();

            // lvalue
            if (tokens.First().tokenType != TokenType.IDENTIFIER)
                return null;

            Token identifierToken = tokens.First();
            Identifier identifier = new Identifier(identifierToken);
            tokens.Dequeue();

            // " is "
            if (tokens.First().tokenType != TokenType.ASSIGNMENT)
            {
                // there is no assign, this might be a method call, stop processing
                tokens.Enqueue(identifierToken);
                return null;
            }
            tokens.Dequeue();

            if (tokens.First().tokenType == TokenType.NEW)
            {
                /*
                // new_instance
                NewInstance newInstance = NewInstanceFactory.produce(symbols);
                if(newInstance == null)
                    throw new ParsingException("NewInstance expected.", symbols.peek());

                // terminator
                optionalTerminator(symbols);

                return Optional.of(new NewInstanceAssignment(identifier, newInstance));
                */
                // TODO: Fix me
                return null;
            }
            else {
                // expression
                Expression expression = ExpressionFactory.produce(tokens);

                // terminator
                optionalTerminator(tokens);

                return new Assignment(identifier, expression);
            }
        }
Exemple #3
0
        //public void AddFunction(Function function)
        //{

        //}

        //public List<Function> GetFunctions()
        //{

        //}

        public Scope findIdentifier(Identifier identifier)
        {
            Scope scope = this;

            do
            {
                if (scope.variables[identifier.name] == null)
                {
                    scope = scope.parentScope;
                }
                else {
                    return scope;
                }
            } while (scope.parentScope != null);

            return null;
        }
Exemple #4
0
        public Function getFunction(Identifier identifier)
        {
            Function function = recipies[identifier.name];

            if (function == null)
            {
                if (parentScope != null)
                {
                    return parentScope.getFunction(identifier);
                }
                else {
                    throw new VirtualMachineRuntimeException("Function " + identifier.name + " does not exist.");
                }
            }

            return function;
        }
        public virtual bool visit(Identifier identifier)
        {
            var value = scope.getVariable(identifier).value;
            evaluation.Push(value);

            return true;
        }
 public VariableDoesNotExistException(Identifier identifier) : base(message)
 {
     message = identifier.name + "does not exist";
 }
Exemple #7
0
 public Variable(Identifier identifier, Value.Value value)
 {
     this.identifier = identifier;
     this.value = value;
 }
Exemple #8
0
 public Assignment(Identifier identifier, Expressions.Expression expression) : base(expression.token)
 {
     this.identifier = identifier;
     this.expression = expression;
 }
Exemple #9
0
 public FunctionCall(Identifier functionName, ArgumentList argumentList) : base(functionName.token)
 {
     this.functionName = functionName;
     this.argumentList = argumentList;
 }
Exemple #10
0
 public FunctionCall(Identifier functionName) : base(functionName.token)
 {
     this.functionName = functionName;
     argumentList = null;
 }
 public bool visit(Identifier identifier)
 {
     return true;
 }
Exemple #12
0
        public void setVariable(Identifier identifier, Value.Value value)
        {
            string name = identifier.name;
            Variable variable = new Variable(identifier, value);

            variables.Remove(name);
            variables.Add(name, variable);
            Console.WriteLine("SET - Variable " + name + " = " + value.getText()); 
        }
Exemple #13
0
 public void setVariable(Identifier identifier)
 {
     throw new NotImplementedException();
 }
Exemple #14
0
 private Variable getParentVariable(Identifier identifier)
 {
     if (parentScope != null)
     {
         return parentScope.getVariable(identifier);
     }
     throw new VariableDoesNotExistException(identifier);
 }