~ubuntu-branches/ubuntu/breezy/antlr/breezy

« back to all changes in this revision

Viewing changes to examples/python/multiParser/multiparser.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2005-06-29 16:11:22 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050629161122-g81crc3z92p5xhsg
Tags: 2.7.5-6ubuntu4
Build depend on java-gcj-compat-dev, depend on java-gcj-compat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import sys
 
3
import traceback
 
4
import antlr
 
5
 
 
6
import SimpleLexer
 
7
import SimpleParser
 
8
import SimpleParser2
 
9
 
 
10
lexer = None
 
11
parser = None
 
12
parser2 = None
 
13
 
 
14
class Main:
 
15
 
 
16
    global lexer, parser, parser2
 
17
 
 
18
    def __init__(self):
 
19
        try:
 
20
            lexer = SimpleLexer.Lexer(sys.stdin);
 
21
 
 
22
            # Invoke first parser
 
23
            sys.stdout.write("first parser" + '\n')
 
24
            parser = SimpleParser.Parser(lexer)
 
25
            parser.simple();
 
26
 
 
27
            # Now we need to get the inputState from the first parser
 
28
            # this includes data about guessing and stuff like it.
 
29
            # If we don't do this and create the second parser
 
30
            # with just the lexer object we might (doh! will!) miss tokens
 
31
            # read for lookahead tests.
 
32
            self.inputstate = parser.getInputState()
 
33
 
 
34
            # When first parser runs out, invoke secnond parser
 
35
            sys.stdout.write("second parser" + '\n')
 
36
            parser2 = SimpleParser2.Parser(self.inputstate)
 
37
            parser2.simple()
 
38
 
 
39
        except antlr.ANTLRException, e:
 
40
            sys.stderr.write("exception: " + str(e) + '\n')
 
41
            #apply(traceback.print_exception, sys.exc_info())
 
42
        except Exception, e:
 
43
            sys.stderr.write("exception: " + str(e) + '\n')
 
44
            #apply(traceback.print_exception, sys.exc_info())
 
45
 
 
46
if __name__ == '__main__':
 
47
    Main()