public Statement Parse() { // the Game Maker lexer runs before parsing, but we will scan as we are parsing, using l.Scan(), // implemented in move() and peek(). We will, as in Game Maker, parse completely before executing, // to catch all compile errors. I've heard Game Maker compiles to byte code, but we will build // a parse tree of Stmts and Exprs. We return a Stmt node that can be executed by Stmt.Exec(). // Game Maker does all of its parsing during loading, and if there are no errors, caches the // intermediate representation, which is referenced by the events and scripts. Statement s; move(); if (t == TokenKind.OpeningCurlyBrace) { s = block(); if (t != TokenKind.Eof) error(Error.ProgramEnds); return s; } s = Statement.Nop; while (t != TokenKind.Eof) { s = new Sequence(s, stmt(), next.line, next.col); // stmt() throws ProgramError } Current = s; return s; }
public abstract void VisitSequence(Sequence sequence);
Statement block() { Statement s = Statement.Nop; int l = next.line; int c = next.col; match(Token.OpeningCurlyBrace); while (t != TokenKind.ClosingCurlyBrace && t != TokenKind.Eof) { s = new Sequence(s, stmt(), l, c); } match(Token.ClosingCurlyBrace); while (t == TokenKind.Semicolon) move(); return s; }