Hacker News new | ask | show | jobs
by qznc 3835 days ago
There is a trick for parsing "indented" syntax which is not covered by this tutorial: the lexer (not the parser) keeps track of indentation. Lexer inserts Indent and Descent tokens, which the parser considers like { and } tokens in a C syntax language.

Now your parser implements a context-free grammar although the language is not context-free.

1 comments

There is even a better trick - ditch the lexer altogether.
Yes a lexer is primarily a performance optimisation. A good one though.