3 ms·
Lexers/parsers, when written together, generally interface each other either as "parser calls lexer.PeekToken()/lexer.AdvanceToken() until it's done parsing, or
by Joker_vD 6y ago
Lexers/parsers, when written together, generally interface each other either as "parser calls lexer.PeekToken()/lexer.AdvanceToken() until it's done parsing, or lexer returns EOF", or, rarer, "lexer calls parser.ConsumeToken(tok) until there is no more input left, and calls parser.Done()". IIRC, SQLite uses the second approach to parse SQL.
At no point does any of these schemes require the lexer to read the whole file into memory, and chop it in one go into a huge list of ready-to-be-consumed tokens.
- quietbritishjim 6y agoSure, in practice, no one ever builds the whole list of tokens in memory, because they all use the same sort of idea described in the article (and described again in your comment). But the article author chose to compare why they don't ever do it that way, and that's what I was commenting on.