3 ms·
The parser stores the entire AST in memory, it is not acting as if it was scarce. As for the idea of not starting with a string but instead reading the file on
by GuB-42 7y ago
The parser stores the entire AST in memory, it is not acting as if it was scarce.
As for the idea of not starting with a string but instead reading the file on the fly, I think it is actually simpler. The point of storing the entire file in memory is to enable going back and forth, but why would you want to do that? State machine based parsers are fast, robust, and based on a solid theoretical grounds, at least for "simple" (context-free) languages.
- fjfaase 7y agoI do not know, if you took time to look at the next function in https://github.com/DoctorWkt/acwj/tree/master/01_Scanner https://github.com/DoctorWkt/acwj/tree/master/01_Scanner , but there is a Putback variable, which seems to imply that the scanner goes back (at most one character). Also having to pass around the result of next, instead of having a current pointer, or at least a current character, makes things more complicated (I feel). Being able to look ahead, without having to consume a character, (I feel) is easier, also for keeping track of the correct line and column number. Note that if Putback is equal to '\n', the Line has already be incremented. Seems that this could lead to errors being reported on the wrong line for terminal symbols at the end of the line.