3 ms·
I'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
by mrspuratic 4y ago
I'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 ; }