bool TestlistComp(out AST.ProgObj obj) { if (Test(out obj)) { goto _1; } obj = null; return(false); _1: //if (scan.Lexeme == Lexeme.Comma) { // scan.Next(); // goto _2; //} goto _end; //_2: // if (Test()) { // goto _3; // } // goto _end; //_3: // if (scan.Lexeme == Lexeme.Comma) { // scan.Next(); // goto _2; // } // CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool ArithExpr(out AST.ProgObj expr) { string name; if (Term(out expr)) { goto _2; } return(false); _1: if (Term(out var right)) { expr = new AST.FuncCall(name, expr, right); goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (scan.Lexeme == Lexeme.Plus) { name = "__add__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.Minus) { name = "__sub__"; scan.Next(); goto _1; } goto _end; _end: return(true); }
bool AndExpr(out AST.ProgObj expr) { if (ShiftExpr(out expr)) { goto _2; } return(false); _1: if (ShiftExpr(out var right)) { expr = new AST.FuncCall("__bitand__", expr, right); goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (scan.Lexeme == Lexeme.BitAnd) { scan.Next(); goto _1; } goto _end; _end: return(true); }
bool ShiftExpr(out AST.ProgObj expr) { string name; if (ArithExpr(out expr)) { goto _2; } return(false); _1: if (ArithExpr(out var right)) { expr = new AST.FuncCall(name, expr, right); goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (scan.Lexeme == Lexeme.LeftShift) { name = "__lshift__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.RightShift) { name = "__rshift__"; scan.Next(); goto _1; } goto _end; _end: return(true); }
bool OrTest(out AST.ProgObj expr) { if (AndTest(out expr)) { goto _2; } return(false); _1: if (AndTest(out var right)) { expr = new AST.FuncCall("__or__", expr, right); goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (scan.Lexeme == Lexeme.KwOr) { scan.Next(); goto _1; } goto _end; _end: return(true); }
bool Trailer(AST.ProgObj atom, out AST.ProgObj expr) { if (scan.Lexeme == Lexeme.LeftParenthesis) { scan.Next(); goto _1; } expr = null; return(false); _1: if (Arglist(out var args)) { expr = new AST.FuncCall(atom, args); goto _2; } expr = new AST.FuncCall(atom); goto _2; _2: if (scan.Lexeme == Lexeme.RightParenthesis) { scan.Next(); goto _end; } throw new CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool Power(out AST.ProgObj expr) { if (AtomExpr(out expr)) { goto _1; } expr = null; return(false); _1: if (scan.Lexeme == Lexeme.Power) { scan.Next(); goto _2; } goto _end; _2: if (Factor(out var right)) { expr = new AST.FuncCall("__pow__", expr, right); goto _end; } throw new CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool Atom(out AST.ProgObj obj) { if (scan.Lexeme == Lexeme.LeftParenthesis) { scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.Id) { obj = new AST.NameObj(scan.TextValue()); scan.Next(); goto _end; } if (scan.Lexeme == Lexeme.Int) { obj = new AST.ConstInt(scan.ToInt()); scan.Next(); goto _end; } if (scan.Lexeme == Lexeme.Float) { obj = new AST.ConstFloat(scan.ToSingle()); scan.Next(); goto _end; } if (scan.Lexeme == Lexeme.KwTrue) { obj = new AST.ConstBool(true); scan.Next(); goto _end; } if (scan.Lexeme == Lexeme.KwFalse) { obj = new AST.ConstBool(false); scan.Next(); goto _end; } obj = null; return(false); _1: if (TestlistComp(out obj)) { goto _2; } obj = new AST.Tuple(); goto _2; _2: if (scan.Lexeme == Lexeme.RightParenthesis) { scan.Next(); goto _end; } throw new CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
public Function(TypeObj retType, string name, params TypeObj[] paramTypes) { Name = name; BuiltIn = true; RetType = retType; for (var i = 0; i < paramTypes.Length; i += 1) { Parameters.Add(new Parameter(i, paramTypes[i])); } }
bool Test(out AST.ProgObj expr) { if (OrTest(out expr)) { goto _1; } return(false); _1: goto _end; _end: return(true); }
bool Term(out AST.ProgObj expr) { string name; if (Factor(out expr)) { goto _2; } expr = null; return(false); _1: if (Factor(out var right)) { expr = new AST.FuncCall(name, expr, right); goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (scan.Lexeme == Lexeme.Star) { name = "__mul__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.Slash) { name = "__truediv__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.Percent) { name = "__mod__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.DoubleSlash) { name = "__floordiv__"; scan.Next(); goto _1; } goto _end; _end: return(true); }
bool Comparison(out AST.ProgObj expr) { string name; AST.ProgObj left; var chained = false; if (Expr(out expr)) { left = expr; goto _2; } return(false); _1: if (Expr(out var right)) { var comp = new AST.FuncCall(name, left, right); left = right; if (chained) { expr = new AST.FuncCall("__and__", expr, comp); } else { expr = comp; chained = true; } goto _2; } throw new CompilationError(ErrorType.InvalidSyntax); _2: if (CompOp(out name)) { goto _1; } goto _end; _end: return(true); }
bool Factor(out AST.ProgObj expr) { string name; if (Power(out expr)) { goto _end; } if (scan.Lexeme == Lexeme.Plus) { name = "__pos__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.Minus) { name = "__neg__"; scan.Next(); goto _1; } if (scan.Lexeme == Lexeme.BitNot) { name = "__invert__"; scan.Next(); goto _1; } expr = null; return(false); _1: if (Factor(out var right)) { expr = new AST.FuncCall(name, right); goto _end; } throw new CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool TestlistStarExpr(out AST.ProgObj expr) { if (Test(out expr)) { goto _1; } return(false); _1: //if (scan.Lexeme == Lexeme.Comma) { // scan.Next(); // goto _2; //} goto _end; //_2: // if (Test()) { // goto _1; // } // goto _end; _end: return(true); }
bool Argument(out AST.ProgObj expr) { if (Test(out expr)) { goto _1; } return(false); _1: //if (scan.Lexeme == Lexeme.Assignment) { // scan.Next(); // goto _2; //} goto _end; //_2: // if (Test()) { // goto _end; // } // CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool NotTest(out AST.ProgObj expr) { if (scan.Lexeme == Lexeme.KwNot) { scan.Next(); goto _1; } if (Comparison(out expr)) { goto _end; } return(false); _1: if (NotTest(out var right)) { expr = new AST.FuncCall("__not__", right); goto _end; } throw new CompilationError(ErrorType.InvalidSyntax); _end: return(true); }
bool AtomExpr(out AST.ProgObj expr) { if (Atom(out expr)) { goto _2; } expr = null; return(false); //_1: // if (Atom()) { // goto _2; // } // throw new CompilationError(ErrorType.InvalidSyntax); _2: if (Trailer(expr, out var trailer)) { expr = trailer; goto _2; } goto _end; _end: return(true); }
public FuncCall(string name, params ProgObj[] args) { Func = new NameObj(name); Args.AddRange(args); }
public FuncCall(ProgObj func, List <ProgObj> args) { Func = func; Args.AddRange(args); }
public FuncCall(ProgObj func) { Func = func; }