/// <summary> /// Visit FuncBindAssignment /// </summary> /// <param name="assignment">FuncBindAssignment to check</param> public override void Visit(FuncBindAssignment assignment) { //FuncBind is a function, so let checking do by FunctionDefinition visitor FunctionDefinition function = new FunctionDefinition(); function.SetIdentifier(assignment.GetIdentifier()); foreach (String identifier in assignment.GetIdentifiers()) { Formal formal = new Formal(); formal.SetIdentifier(identifier); function.AddFormal(formal); } function.AddStatement(assignment.GetStatement()); //Check this new function function.AcceptVisitor(this); //Add to SymbolTable SymbolTable.AddFunctionDefinition(function); }
/// <summary> /// Parser for FunctionDefinition /// </summary> /// <returns>Parsed FunctionDefinition</returns> public FunctionDefinition ParseFunctionDefinition() { FunctionDefinition functionDefinition = new FunctionDefinition(); //Parse FunctionId CurrentToken = TokenStream.NextToken(); functionDefinition.SetIdentifier(CurrentToken.GetValue().ToString()); //Parse Formals ParseFormals(functionDefinition); //Parse Statements while (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() != "end") { functionDefinition.AddStatement(statementParser.ParseStatement()); } //Skip end token NextToken("end", "def function() statements end", "end"); return(functionDefinition); }