public override void Visit(FuncCallExpressionNode node) { node.Id.Accept(this); CSharpString.Append("("); node.ActualParameters?.ForEach(x => { if (node.ActualParameters.IndexOf(x) != 0) { CSharpString.Append(", "); } x.Accept(this); }); CSharpString.Append(")"); }
public override void Visit(FuncCallExpressionNode node) { node.Id.Accept(this); Console.Write("("); node.ActualParameters?.ForEach(x => { if (node.ActualParameters.IndexOf(x) != 0) { Console.Write(", "); } x.Accept(this); }); Console.Write(")"); }
public override void Visit(FuncCallExpressionNode node) { node.ActualParameters?.ForEach(x => x.Accept(this)); var astNode = symbolTable.RetrieveSymbol(node.Id.Id, node); if (astNode is FunctionDclNode funcDcl) { if (funcDcl.Id.Id == "ChooseOption") { if (node.ActualParameters.Count > 1) { if (node.ActualParameters[0].Type != "bool") { throw new SemanticException($"Error on line {node.line}: Wrong type {node.ActualParameters[0].Type} provided for ChooseOption."); } for (int i = 1; i < node.ActualParameters.Count; i++) { if (node.ActualParameters[i].Type != "string") { throw new SemanticException($"Error on line {node.line}: Wrong type {node.ActualParameters[i].Type} provided for ChooseOption."); } } } else { throw new SemanticException($"Error on line {node.line}: The ChooseOption did not receive enough parameters."); } } else if (funcDcl.Id.Id == "Print") { if (node.ActualParameters.Count == 1) { if (!IsPrimitiveType(node.ActualParameters[0].Type)) { throw new SemanticException($"Error on line {node.line}: The Print function can only use integers, floats, booleans and strings."); } } else { throw new SemanticException($"Error on line {node.line}: No function of name {node.Id.Id} with {node.ActualParameters.Count} parameters found."); } } else if (funcDcl.Id.Id == "ListRemove" || funcDcl.Id.Id == "ListAdd") { if (node.ActualParameters.Count == 2) { if (!(node.ActualParameters[0].Type.Contains("[]") && node.ActualParameters[1].Type == node.ActualParameters[0].Type.Replace("[]", ""))) { throw new SemanticException($"Error on line {node.line}: Element type {node.ActualParameters[1].Type} was tried to be added or removed to array of type {node.ActualParameters[0].Type}."); } } else { throw new SemanticException($"Error on line {node.line}: No function of name {node.Id.Id} with {node.ActualParameters.Count} parameters found."); } } else if (funcDcl.Id.Id == "ListLength" || funcDcl.Id.Id == "ListEmpty") { if (!(node.ActualParameters.Count == 1)) { throw new SemanticException($"Error on line {node.line}: No function of name {node.Id.Id} with {node.ActualParameters.Count} parameters found."); } else { if (!node.ActualParameters[0].Type.Contains("[]")) { throw new SemanticException($"Error on line {node.line}: {node.Id.Id} expected list parameter."); } } } else if (node.ActualParameters.Count == funcDcl.FormalParamNodes.Count) { for (int i = 0; i < node.ActualParameters.Count; i++) { //CompatibleTypes(node.ActualParameters[i].Type, funcDcl.FormalParamNodes[i].Type + (funcDcl.FormalParamNodes[i].IsArray? "[]" : "") , "parameter type", node); if (node.ActualParameters[i].Type != funcDcl.FormalParamNodes[i].Type + (funcDcl.FormalParamNodes[i].IsArray ? "[]" : "")) { throw new SemanticException($"Error on line {node.line}: Invalid parameter type: can't convert {funcDcl.FormalParamNodes[i].Type + (funcDcl.FormalParamNodes[i].IsArray ? "[]" : "")} to type {node.ActualParameters[i].Type}."); } } } else { throw new SemanticException($"Error on line {node.line}: No function of name {node.Id.Id} with {node.ActualParameters.Count} parameters found."); } node.Type = funcDcl.ReturnType; } else if (astNode is StructDclNode structDcl && structDcl.Constructor != null) { if (node.ActualParameters.Count == structDcl.Constructor.FormalParamNodes.Count) { for (int i = 0; i < node.ActualParameters.Count; i++) { //CompatibleTypes(node.ActualParameters[i].Type, structDcl.Constructor.FormalParamNodes[i].Type + (structDcl.Constructor.FormalParamNodes[i].IsArray ? "[]" : ""), "parameter type", node); if (node.ActualParameters[i].Type != structDcl.Constructor.FormalParamNodes[i].Type + (structDcl.Constructor.FormalParamNodes[i].IsArray ? "[]" : "")) { throw new SemanticException($"Error on line {node.line}: Invalid parameter type: can't convert {structDcl.Constructor.FormalParamNodes[i].Type + (structDcl.Constructor.FormalParamNodes[i].IsArray ? "[]" : "")} to type {node.ActualParameters[i].Type}."); } } } else { throw new SemanticException($"Error on line {node.line}: No constructor of name {node.Id.Id} with {node.ActualParameters.Count} parameters found."); } node.Type = structDcl.Id.Id; }
internal abstract void Visit(FuncCallExpressionNode node);
public abstract void Visit(FuncCallExpressionNode node);