I'm working on a compiler for a C++-like language (assume that we'll be compiling C++ for now, and do not consider The Lexer Hack). So far the stages from stream to lexer can be narrow; the parser calls getToken which may call getCharacter. This is contrasted to the "broad" technique which would load the entire stream into memory and then convert the stream entirely into tokens before moving to parsing.
Now I have a narrow lexer and stream, but I'm wondering if it's possible to create a narrow parser as well. Specifically using a re-entrant LL(1) parser. In any case, what is the smallest unit that goes out of the parser into the semantic analyzer (a function syntax tree? An entire file? A single statement tree?)? The parser will output a parse tree. Should the parser output something different?
To make it more clear: Lexer -> Parser -> Semantic Analysis
The lexer sends tokens one-by-one to the parser, and the parser parses them. Whenever the parser requests a token, the lexer will provide it. Now I want to try the same for the semantic analyzer. Imagine the semantic analyzer going: getTree(). It causes the parser to parse sufficiently such that an analyzable tree is generated for semantic analysis. The question is about the how to determine the minimally required tree for successful semantic analysis.
Thinking of it: maybe I am asking for a re-entrant semantic analyzer.