@@ -42,6 +42,7 @@ <h1>A Pint-sized Earley Parser</h1>
4242 < li > < a href ="#algorithm "> The Algorithm</ a > </ li >
4343 </ ul >
4444 < li > < a href ="#parser "> The Parser</ a > </ li >
45+ < li > < a href ="#demo "> A Trivial Demonstration</ a > </ li >
4546 < li > < a href ="#future "> Future Work</ a > </ li >
4647</ ul >
4748
@@ -288,19 +289,44 @@ <h2><a name="parser">The Parser</a></h2>
288289
289290
290291
292+ < h2 > < a name ="demo "> A Trivial Demonstration</ a > </ h2 >
293+
294+ < pre > < code > g = Grammar('S',
295+ S -> X X b
296+ X ->
297+ X -> a
298+ X -> a a
299+ X -> a a a)
300+
301+ parse(g, 'aaab')</ code > </ pre >
302+
303+ < div id ="forest "> </ div >
304+ < script src ="demo.js "> </ script >
305+ < script >
306+ var g = new Grammar ( 'S' , [
307+ new Rule ( 'S' , [ 'X' , 'X' , 'b' ] ) ,
308+ new Rule ( 'X' , [ ] ) ,
309+ new Rule ( 'X' , [ 'a' ] ) ,
310+ new Rule ( 'X' , [ 'a' , 'a' ] ) ,
311+ new Rule ( 'X' , [ 'a' , 'a' , 'a' ] )
312+ ] ) ;
313+ var f = g . parse ( 'aaab' ) ;
314+
315+ var div = document . getElementById ( 'forest' ) ;
316+ var tree = forest_to_html ( f ) ;
317+ tree . className = 'center' ;
318+ div . appendChild ( tree ) ;
319+ </ script >
320+
321+
291322< h2 > < a name ="future "> Future Work</ a > </ h2 >
292323
293- < p > I'm excited about finally getting this to work, so I'm writing this
294- up and posting it right away. But this is just the core parsing
295- algorithm: I want to at < em > least</ em > write a parse forest visualizer
296- and set up a page with a demo grammar where you can enter text and see
297- the resulting forest.</ p >
298-
299- < p > And to be really usable at all it needs a means to enter grammars in
300- a convenient notation, a way to choose a parse tree from the forest, and
301- a way to attach actions to rules. I hope to get to this soon, but
302- realistically it might be a month or three before I get around to
303- finishing all of it.</ p >
324+ < p > I'm excited about finally getting this algorithm figured out and running, so
325+ I'm writing it up and posting it right away. But to be really usable at all it
326+ needs a means to enter grammars in a convenient notation, a way to choose a
327+ parse tree from the forest, and a way to attach actions to rules. I hope to
328+ get to this soon, but realistically it might be a month or three before I get
329+ around to finishing all of it.</ p >
304330
305331</ div >
306332
0 commit comments