public bool Parse() { token = lexer.GetNextToken(); if (delayinc) { depth++; delayinc = false; } if (token == Lexer.TokenType.EOF) { depth = 0; return(false); } /* * Console.WriteLine("Token: " + token.ToString() + " - " + * lexer.TokenString); */ switch (token) { case Lexer.TokenType.CLOSE_PAREN: if (depth == 0) { throw new Exception("Parse Error: unexpected )"); } depth--; type = LispType.END_LIST; break; case Lexer.TokenType.OPEN_PAREN: type = LispType.START_LIST; delayinc = true; break; case Lexer.TokenType.SYMBOL: type = LispType.SYMBOL; break; case Lexer.TokenType.STRING: type = LispType.STRING; break; case Lexer.TokenType.TRUE: type = LispType.BOOLEAN; break; case Lexer.TokenType.INTEGER: type = LispType.INTEGER; break; } return(true); }
public List Parse() { Token = Lexer.GetNextToken(); if (Token != Lexer.Token.OPEN_PAREN) { ParseError("file does not start with '('"); } List Result = InternParse(); if (Token != Lexer.Token.EOF) { if (Token == Lexer.Token.CLOSE_PAREN) { ParseError("too many ')'"); } else { ParseError("extra tokens at end of file"); } } return(Result); }