void VarNomination(ref Scope scope, out MultiVariableDeclaration mvd, bool decl) { VariableDeclaration varDecl; List<VariableDeclaration> vars = new List<VariableDeclaration>(); if (la.kind == 1) { SingleVarNomination(ref scope, out varDecl, decl); vars.Add(varDecl); } else if (la.kind == 13) { Get(); SingleVarNomination(ref scope, out varDecl, decl); vars.Add(varDecl); while (la.kind == 11) { Get(); SingleVarNomination(ref scope, out varDecl, decl); vars.Add(varDecl); } Expect(14); } else SynErr(37); mvd = new MultiVariableDeclaration(vars, null); }
void VarAssignment(ref Scope scope, out IStatement stmt) { MultiVariableDeclaration mvd; IExpression expr = null; IExpression rhs = null; VariableDeclaration vd = null; stmt = null; if (la.kind == 21) { Get(); VarNomination(ref scope, out mvd, true); Initializer(scope, out expr); stmt = new MultiVariableDeclaration(mvd.Declarations, expr); } else if (la.kind == 1) { SingleVarNomination(ref scope, out vd, false); if (la.kind == 20) { Initializer(scope, out expr); stmt = new MultiVariableDeclaration(new List<VariableDeclaration>(new VariableDeclaration[]{ vd }), expr); } else if (StartOf(1)) { Expression(scope, out rhs); stmt = new FunctionCall(vd, rhs); } else SynErr(41); } else if (la.kind == 1 || la.kind == 13) { VarNomination(ref scope, out mvd, false); Initializer(scope, out expr); stmt = new MultiVariableDeclaration(mvd.Declarations, expr); } else SynErr(42); }
void StillPrimary(Scope scope, out IExpression expr, VarList vl) { IType type = new UnknownType(); string name = ""; expr = null; IExpression rhs; if (la.kind == 1) { Get(); name = t.val; if (la.kind == 14) { Get(); if (la.kind == 8) { VariableDeclaration newestParam = new VariableDeclaration(name, type); vl.Add(newestParam); MultiVariableDeclaration parmDecl = new MultiVariableDeclaration(vl, null); FunctionReturnDefinition(scope, out expr, parmDecl); } if (StartOf(1)) { expr = expr ?? (IExpression)scope.GetDeclarationFor(name); Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } expr = expr ?? (IExpression)scope.GetDeclarationFor(name); } else if (la.kind == 7) { Get(); TypeIdentifier(scope, out type); VariableDeclaration newestParam = new VariableDeclaration(name, type); vl.Add(newestParam); MultiVariableDeclaration parmDecl = new MultiVariableDeclaration(vl, null); if (la.kind == 8) { FunctionReturnDefinition(scope, out expr, parmDecl); if (la.kind == 14) { Get(); if (StartOf(1)) { Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } } else if (StartOf(1)) { Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); if (la.kind == 14) { Get(); } else if (la.kind == 11) { ExpressionList el = new ExpressionList(); expr = expr ?? (IExpression)scope.GetDeclarationFor(name); el.Add(expr); Get(); Secondary(scope, el, out expr); } else SynErr(29); } else if (la.kind == 11) { ExpressionList el = new ExpressionList(); expr = expr ?? (IExpression)scope.GetDeclarationFor(name); el.Add(expr); Get(); Secondary(scope, el, out expr); } else SynErr(30); } else if (la.kind == 14) { Get(); FunctionReturnDefinition(scope, out expr, parmDecl); if (StartOf(1)) { Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } if (la.kind == 11) { ExpressionList el = new ExpressionList(); expr = expr ?? (IExpression)scope.GetDeclarationFor(name); el.Add(expr); Get(); Secondary(scope, el, out expr); } } else if (la.kind == 11) { VariableDeclaration vd; NextNomination(ref scope, out vd); FunctionReturnDefinition(scope, out expr, parmDecl); if (StartOf(1)) { Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } } else SynErr(31); } else if (la.kind == 11) { Get(); vl.Add(new VariableDeclaration(name, type)); StillPrimary(scope, out expr, vl); } else if (la.kind == 8) { VariableDeclaration newestParam = new VariableDeclaration(name, type); vl.Add(newestParam); MultiVariableDeclaration parmDecl = new MultiVariableDeclaration(vl, null); FunctionReturnDefinition(scope, out expr, parmDecl); if (la.kind == 14) { Get(); Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } else if (StartOf(3)) { if (la.kind == 11) { Get(); } ExpressionList el = new ExpressionList(); expr = expr ?? (IExpression)scope.GetDeclarationFor(name); el.Add(expr); Secondary(scope, el, out expr); } else SynErr(32); } else SynErr(33); } else if (la.kind == 3 || la.kind == 10) { if (la.kind == 3) { IntegerLiteral(scope, out expr); } else { ArrayLiteral(scope, out expr); } ExpressionList el = new ExpressionList(); expr = expr ?? (IExpression)scope.GetDeclarationFor(name); el.Add(expr); if (la.kind == 11) { Get(); Secondary(scope, el, out expr); } } else SynErr(34); }
void Primary(Scope scope, out IExpression expr) { IType type = new UnknownType(); string name = ""; expr = null; IExpression rhs; if (la.kind == 1) { Get(); name = t.val; if (la.kind == 7 || la.kind == 8) { if (la.kind == 7) { Get(); TypeIdentifier(scope, out type); VariableDeclaration vd = new VariableDeclaration(name, type); MultiVariableDeclaration parmDecl = new MultiVariableDeclaration(new List<VariableDeclaration>(new VariableDeclaration[] {vd}), null); FunctionReturnDefinition(scope, out expr, parmDecl); } else { VariableDeclaration vd = new VariableDeclaration(name, type); MultiVariableDeclaration parmDecl = new MultiVariableDeclaration(new List<VariableDeclaration>(new VariableDeclaration[] {vd}), null); FunctionReturnDefinition(scope, out expr, parmDecl); } } if (StartOf(1)) { expr = expr ?? (IExpression)scope.GetDeclarationFor(name); Expression(scope, out rhs); expr = new FunctionCall(expr, rhs); } expr = expr ?? (IExpression)scope.GetDeclarationFor(name); } else if (la.kind == 13) { Get(); VarList vl = new VarList(); if (la.kind == 1 || la.kind == 3 || la.kind == 10) { StillPrimary(scope, out expr, vl); } else if (la.kind == 14) { Get(); } else SynErr(27); } else SynErr(28); }
void FunctionReturnDefinition(Scope scope, out IExpression expr, MultiVariableDeclaration parmDecl) { MultiVariableDeclaration retDecl; Scope funcScope = new Scope(scope); StatementList stmts = new StatementList(); Expect(8); VariableDeclaration.Scopify(ref funcScope, parmDecl.Declarations); VarNomination(ref funcScope, out retDecl, true); Expect(15); while (StartOf(2)) { Statement(ref funcScope, stmts); } Expect(16); expr = new FunctionLiteral(retDecl, parmDecl, stmts); }
public FunctionLiteral(MultiVariableDeclaration returnValue, MultiVariableDeclaration parameter, List<IStatement> statements) { this.Type = new FunctionType(parameter.Type, returnValue.Type); this.Statements = statements; this.Parameter = parameter; this.ReturnValue = returnValue; }