3 ms·
It seems like examples for these kinds of simpler grammars tend to be pretty dry. It would be fun to use more programming language-like examples. And then you m
by civopsec 4y ago
It seems like examples for these kinds of simpler grammars tend to be pretty dry. It would be fun to use more programming language-like examples. And then you might also see what difficulties you run into with them (with their limitations).
- mrspuratic 4y agoI'm a visual problem solver, very neat to see this visualized step by step. Last year I had a need to analyze some non-trivial network device configurations, I tried (and almost succeeded, still a work in progress) with perl, Parse::Yapp (LALR rather than LL) and hand-rolled lexer. I found Graphviz2::Parse::Yapp was quite good, but since a lot of my grammar was (effectively) machine generated the graphs were improbably large :/ (16 A4 pages!) Context-free LL(1) grammars are limited in terms of what can be parsed, you can do this though: program ::= { statement_list } $ statement_list ::= statement statement_list statement_list ::= '' statement ::= id = expr ; statement ::= if ( expr ) then statement expr ::= id expr_tail expr ::= num expr_tail ::= + expr expr_tail ::= - expr expr_tail ::= '' id ::= a id ::= b num ::= 5 (cheating slightly with the final three productions so you can just paste that in as the grammar input) and successfully parse { if ( a ) then b = 5 ; }