void FunctionDeclaration(out FunctionDeclaration decl, Scope parentScope) { Statement stmt; BaseType type; VariableDeclarationList decls; Expect(6); Expect(1); decl = new FunctionDeclaration(t, parentScope); Expect(38); if (StartOf(1)) { Type(out type); Expect(1); decl.AddArgument(t, type); while (la.kind == 31) { Get(); Type(out type); Expect(1); decl.AddArgument(t, type); } } Expect(45); if (la.kind == 30) { Get(); Type(out type); decl.returnType = type; } while (la.kind == 14) { VariableDeclarations(out decls); decl.localScope.AddVariables(decls); } BlockStatement(out stmt); decl.body = stmt as BlockStatement; }
void ProgramBody(out FunctionDeclaration main) { Statement stmt; main = new FunctionDeclaration("Main", CSR.Compiler.Compiler.staticScope); BlockStatement(out stmt); main.body = stmt as BlockStatement; }
/// <summary> /// Adds a function declaration /// </summary> /// <param name="decl">FunctionDeclaration object</param> public void AddFunction(FunctionDeclaration decl) { // Check if a function with the same exact signature was already declared foreach (FunctionDeclaration func in functions) { // Check if functions have the same name if (func.name == decl.name) { // Check if functions have the same signature if (func.ToSignature().IsExactMatch(decl.ToSignature())) { // Issue error Compiler.Compiler.errors.SemErr(decl.t.line, decl.t.col, string.Format("Function '{0}' already declared", decl.name)); } } } // Add function to list functions.Add(decl); }