3 ms·
> `lex` and `yacc` yacc is ancient. Even its replacement, bison, is ancient at this point. I have seen "lexing" done on the parsing level in the past. The sam
by otikik 4y ago
> `lex` and `yacc`
yacc is ancient. Even its replacement, bison, is ancient at this point.
I have seen "lexing" done on the parsing level in the past. The same way you can say "a sum expression is a subexpression, a plus sign and another expression" you can say "an identifier is 1 letter followed by 0 or more letters or digits". It was a bit cute, but awkward.
It's very convenient to have two passes. The first one removes unnecessary stuff like superfluous spaces or comments, so that the actual parsing can operate over a simplified space (not having to take into account things like "an expression 0 or more spaces, the plus sign, 0 or more spaces and another expression"). At that point, you might as well just use a Lexer for phase 1.