public string Visit(NFunCall nFunCall) { string lexeme = nFunCall.AnchorToken.Lexeme; FunctionSym functionSym = semanticAnalyzer.GetFunctionSymbolByLexeme(lexeme); NExprList argumentList = (NExprList)nFunCall[0]; string argumentsPreparation = Visit(argumentList); string prefix = ""; if (functionSym.kind == FunctionSymKind.STANDARD) { prefix = "\t\tcall int64 class ['int64lib']'Int64'.'Utils'::"; } else { prefix = "\t\tcall int64 class 'Int64Program'::"; } string paramTypeList = ""; for (var i = 0; i < argumentList.children.Count; i++) { paramTypeList += "int64"; if (i != argumentList.children.Count - 1) { paramTypeList += ", "; } } if (lexeme == "new") { lexeme = "New"; } return(argumentsPreparation + prefix + "'" + lexeme + "'(" + paramTypeList + ")\n"); }
public void Visit(NFunDef nFunDef) { currentFunction = semanticAnalyzer.GetFunctionSymbolByLexeme(nFunDef.AnchorToken.Lexeme); // No need to visit neither parameter list nor variable definition list NStmtList stmtList = (NStmtList)nFunDef[2]; Visit(stmtList); currentFunction = null; }
private FunctionSym newStandardFunction(string symbol, params string[] parameters) { FunctionSym retVal = new FunctionSym(new Token(symbol, TokenCategory.IDENTIFIER, -1, -1), FunctionSymKind.STANDARD); for (int i = 0; i < parameters.Length; i++) { retVal.AddLocalVariable(new VariableSym(new Token(parameters[i], TokenCategory.IDENTIFIER, -1, -1), VariableSymKind.PARAMETER)); } return(retVal); }
public void AddFunction(FunctionSym newFunction) { foreach (FunctionSym function in functions) { if (function.anchorToken.Lexeme == newFunction.anchorToken.Lexeme) { throw new SemanticError("Name collision", newFunction.anchorToken); } } functions.Add(newFunction); }
public void Visit(NFunCall nFunCall) { string lexeme = nFunCall.AnchorToken.Lexeme; FunctionSym functionSym = semanticAnalyzer.GetFunctionSymbolByLexeme(lexeme); NExprList argumentList = (NExprList)nFunCall[0]; if (functionSym != null && functionSym.GetArity() == argumentList.children.Count) { Visit(argumentList); } else { throw new SemanticError("Nonexistent function or signature mismatch", nFunCall.AnchorToken); } }
public void Visit(NFunDefList node) { foreach (NFunDef funDef in node) { FunctionSym newFuncSym = new FunctionSym(funDef.AnchorToken, FunctionSymKind.USER_DEFINED); // Add parameters to local scope foreach (NParameter param in funDef[0]) { VariableSym newParam = new VariableSym(param.AnchorToken, VariableSymKind.PARAMETER); newFuncSym.AddLocalVariable(newParam); } // Add variables to local scope foreach (NVarDef variable in funDef[1]) { VariableSym newVariable = new VariableSym(variable.AnchorToken, VariableSymKind.REGULAR); newFuncSym.AddLocalVariable(newVariable); } semanticAnalyzer.AddFunction(newFuncSym); } }
public string Visit(NFunDef nFunDef) { currentFunction = semanticAnalyzer.GetFunctionSymbolByLexeme(nFunDef.AnchorToken.Lexeme); string lexeme = nFunDef.AnchorToken.Lexeme; Node parameters = nFunDef[0]; Node varDefList = nFunDef[1]; Node stmtList = nFunDef[2]; string retVal = "\t.method public static hidebysig default int64 '" + lexeme + "' (" + Visit((dynamic)parameters) + ") cil managed {\n"; if (lexeme == "main") { retVal += "\t\t.entrypoint\n"; } retVal += Visit((dynamic)varDefList) + Visit((dynamic)stmtList) + "\t\tldc.i8 0\n" + "\t\tret\n" + "\t}\n"; currentFunction = null; return(retVal); }