Exemplo n.º 1
0
        public Variable getVariable(Identifier identifier)
        {
            Variable variable = variables[identifier.name];

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

            return variable;
        }
Exemplo n.º 2
0
        // 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);
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 5
0
        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";
 }
Exemplo n.º 7
0
 public Variable(Identifier identifier, Value.Value value)
 {
     this.identifier = identifier;
     this.value = value;
 }
Exemplo n.º 8
0
 public Assignment(Identifier identifier, Expressions.Expression expression) : base(expression.token)
 {
     this.identifier = identifier;
     this.expression = expression;
 }
Exemplo n.º 9
0
 public FunctionCall(Identifier functionName, ArgumentList argumentList) : base(functionName.token)
 {
     this.functionName = functionName;
     this.argumentList = argumentList;
 }
Exemplo n.º 10
0
 public FunctionCall(Identifier functionName) : base(functionName.token)
 {
     this.functionName = functionName;
     argumentList = null;
 }
Exemplo n.º 11
0
 public bool visit(Identifier identifier)
 {
     return true;
 }
Exemplo n.º 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()); 
        }
Exemplo n.º 13
0
 public void setVariable(Identifier identifier)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 private Variable getParentVariable(Identifier identifier)
 {
     if (parentScope != null)
     {
         return parentScope.getVariable(identifier);
     }
     throw new VariableDoesNotExistException(identifier);
 }