PEG for Python style indentation

Pure PEG cannot parse indentation. But peg.js can. I did a quick-and-dirty experiment (being inspired by Ira Baxter’s comment about cheating) and wrote a simple tokenizer. For a more complete solution (a complete parser) please see this question: Parse indentation level with PEG.js /* Initializations */ { function start(first, tail) { var done = [first[1]]; … Read more

What are the differences between PEGs and CFGs?

A CFG grammar is non-deterministic, meaning that some input could result in two or more possible parse-trees. Though most CFG-based parser-generators have restrictions on the determinability of the grammar. It will give a warning or error if it has two or more choices. A PEG grammar is deterministic, meaning that any input can only be … Read more

tech