/// <summary> /// Parser for Formal /// </summary> /// <returns>Parsed Formal</returns> public Formal ParseFormal() { Formal formal = new Formal(); CurrentToken = TokenStream.NextToken(); formal.SetIdentifier(CurrentToken.GetValue().ToString()); return(formal); }
/// <summary> /// Interpret FuncBindAssignment /// </summary> /// <param name="assignment">FuncBindAssignment to interpret</param> public override void Visit(FuncBindAssignment assignment) { //Make a function of this binding and add it to SymbolTable FunctionDefinition functionDefinition = new FunctionDefinition(); functionDefinition.SetIdentifier(assignment.GetIdentifier()); functionDefinition.AddStatement(assignment.GetStatement()); //Convert identifiers to formals foreach (String id in assignment.GetIdentifiers()) { Formal frml = new Formal(); frml.SetIdentifier(id); functionDefinition.AddFormal(frml); } //Create new SymbolTable for function FunctionSymbolTable.Add(functionDefinition, (SymbolTable)SymbolTable.Clone()); //Add function to SymbolTable SymbolTable.AddFunctionDefinition(functionDefinition); }
/// <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); }