private void AddVariable(SymbolDeclarationNode variable)
 {
     if (symbols.ContainsKey(variable.Variable.Name))
     {
         ErrorCode.VariableAlreadyDeclared.ReportAndThrow(variable.SequencePoint,
                                                          String.Format("Variable {0} already declared in this scope", variable.Variable.Name));
     }
     symbols.Add(variable.Variable.Name, variable);
 }
        public override ExpressionNode GetSymbol(string name, ContextNode scope, SequencePoint point)
        {
            if (symbols.ContainsKey(name))
            {
                SymbolDeclarationNode node = symbols[name];
                return(new LocalVariableNode(point, node.Variable, node.IsConst));
            }

            return(Parent.GetSymbol(name, scope, point));
        }
        public CodeBlockNode AddStatement(IAbstractSyntaxTree lexerNode)
        {
            switch (lexerNode.Type)
            {
            case Lexer.TokenType.DeclarationNode:
                return(AddNode(SymbolDeclarationNode.Parse(this, lexerNode)));

            case Lexer.TokenType.Value:
                return(AddNode(ExpressionNode.Parse(this, lexerNode)));

            case Lexer.TokenType.ReturnNode:
                return(AddNode(ReturnNode.Parse(this, lexerNode)));

            default:
                ErrorCode.InvalidStructure.ReportAndThrow(Parser.GetSequencePoint(lexerNode), "Unexpected statement {0} in while parsing code block", lexerNode.Type);
                return(Utils.Utils.Fail <CodeBlockNode>());
            }
        }
 private void AddDeclaration(SymbolDeclarationNode node)
 {
     AddVariable(node);
     nodes.Add(node);
 }