private void Visit(FunctionDeclarationStmt declarationStmt) // TODO tarkista että palauttaa oikeasti jotain { if (!Symbols.ExistsInCurrentScope(declarationStmt.Identifier)) { int currentScope = Symbols.CurrentScope; int procedureScope = Symbols.EnterScope(); //ReturnTypeStack.Push(new TypeInfo(declarationStmt.ReturnType)); var parameterSymbols = new List <ParameterSymbol>(); foreach (var parameter in declarationStmt.Parameters) { var parameterSymbol = new ParameterSymbol(parameter, procedureScope); Symbols.AddSymbol(parameterSymbol); parameterSymbols.Add(parameterSymbol); } var funcSymbol = new FunctionSymbol(declarationStmt, parameterSymbols, currentScope); Symbols.AddSymbol(funcSymbol); FunctionStack.Push(funcSymbol); declarationStmt.DeclarationSymbol = funcSymbol; Visit(declarationStmt.ProcedureBlock, false); Symbols.LeaveScope(); //ReturnTypeStack.Pop(); FunctionStack.Pop(); } else { AddError(string.Format("'{0}' is already declared in current scope", declarationStmt.Identifier), declarationStmt); } }
private FunctionDeclarationStmt ParseFunctionDeclaration() { Match(TokenType.KwFunction); FunctionDeclarationStmt statement = new FunctionDeclarationStmt(AcceptedToken); statement.Identifier = ParseIdentifier(); Match(TokenType.LParen); statement.Parameters = ParseParameters(); Match(TokenType.RParen); Match(TokenType.Colon); statement.ReturnType = ParseType(); Match(TokenType.LineTerm); statement.ProcedureBlock = ParseBlock(); return(statement); }
public FunctionSymbol(FunctionDeclarationStmt declaration, List <ParameterSymbol> parameters, int scope) : base(declaration, parameters, scope) { }