3 ms·
A minor clarification for those who might be learning from HN: regular expressions aren't equivalent to context-free grammars, they are even more limited than c
by pekk 11y ago
A minor clarification for those who might be learning from HN: regular expressions aren't equivalent to context-free grammars, they are even more limited than context-free grammars. Things which involve arbitrary-depth nesting or recursion, like HTML, can't be parsed by regular expressions, but that is exactly what context-free grammars are for. Where regular expressions correspond to finite state automata (essentially directed graphs where nodes are states and edges are input-driven transitions between states), context-free grammars correspond to pushdown automata (with a stack, this is the recursion secret sauce). Lots of interesting things are context-free. For example, any good programming language grammar should be context-free, to allow sane and efficient parsing. I welcome further corrections.
- pjtr 11y agoIn other words regular expressions are equivalent to regular grammars [1]. (Except "modern regular expressions" support some construct that make them match some non-regular grammars. [2]) [1] https://en.wikipedia.org/wiki/Regular_grammar https://en.wikipedia.org/wiki/Regular_grammar [2] https://en.wikipedia.org/wiki/Regular_expression#Patterns_for_non-regular_languages https://en.wikipedia.org/wiki/Regular_expression#Patterns_fo...
- georgerobinson 11y agoCould you write a blog post on this? I want to learn more!