1 """
2 Code and classes for top down recursive descent parser.
3 Currently just a recognizer is actually implemented.
4
5 >>> from td_parser import *
6 >>> demo(['John likes Mary'])
7
8 This will recognize 'John likes Mary' with the first default
9 grammar defined in the C{demo} function at the bottom of
10 the module file.
11
12 >>> g = Grammar('s')
13
14 defines a grammar C{g} with start symbol 's'
15
16 >>> g.add_production('s', ['np','vp'])
17
18 adds the rule s -> np vp.
19
20 >>> p = Parser(g)
21
22 creates a parser instance C{p} with grammar g.
23
24 >>> p.trace()
25 >>> p.recognize_string('The boy likes the girl')
26
27 Turn verbose trace output on for C{p} and recognize the string
28 'The boy likes the girl.'
29
30 For more examples of all of the above see the C{demo} function
31 in C{td_parser.td_parser}.
32
33 >>> strings = ['John likes Mary', 'The boy likes the girl', 'Eat beans']
34 >>> demo(strings)
35
36 Run the demo with these 3 strings.
37
38 C{td_parser.td_parser} includes a class for a top down recursive
39 descent parser, a class for context-free grammars, and parser states.
40 There are two grammars defined in the demo function, declared
41 as globals C{g1} and C{g2}.
42 """
43