Comment by ModernMech
2 days ago
The way you would implement them in Python or C++ is using their functional facilities. Or you'd write a library that emulated them.
The key feature is first class functions, so you can have combinators like "or()", "and()", "repeat()", "optional()", etc, which take a function pointer as a parameter, as well as the input character stream; and returns the matched characters from the input stream, as well as the rest of the stream. When all combinators have this function signature, you can compose them easily, and writing the parser is becomes a matter of transcribing the ebnf grammar.
No comments yet
Contribute on Hacker News ↗