/// <summary> /// 函数参数定义 /// </summary> /// <param name="node"></param> public void Visit(ParameterDeclarationNode node) { var builder = new StringBuilder(); builder.Append("函数参数:"); builder.AppendFormat("{0} {1}", node.Type, node.Name); Console.Write(builder.ToString()); }
protected override List <AssemblyElement> VisitParameterDeclaration(ParameterDeclarationNode node) { return(new List <AssemblyElement> { GetParameterPush(node.Symbol), GetAssignInstruction(node.Symbol), }); }
protected override List <AssemblyElement> VisitFunctionDefinition(FunctionDefinitionNode node) { List <AssemblyElement> instructions = ((BlockSymbol)node.Symbol).Instructions; if (node.IsExternal) { return(instructions); } for (int i = node.ParameterNodes.Count - 1; i >= 0; i--) { ParameterDeclarationNode parameterNode = node.ParameterNodes[i]; instructions.AddRange(Visit(parameterNode)); } foreach (StatementNode bodyNode in node.BodyNodes) { instructions.AddRange(Visit(bodyNode)); } instructions.Add(new Ret()); return(instructions); }
public Type Visit(ParameterDeclarationNode node) { foreach (var typeNode in node) { Type type = Visit((dynamic)typeNode); int pos = 0; foreach (var idNode in typeNode) { var varName = idNode.AnchorToken.Lexeme; if (CurrentScopeHasSymbol(varName)) { throw new SemanticError($"Duplicated parameter: {varName}", idNode.AnchorToken); } else { AddSymbolToScope(varName, type, Kind.PARAM, pos: pos++, value: type.DefaultValue()); } } } return(Type.VOID); }
public void Visit(ParameterDeclarationNode node) { // do nothing }
internal override void Visit(ParameterDeclarationNode node) { }