source: proto/RE2PBS/bin/main.py @ 1130

Last change on this file since 1130 was 1130, checked in by ksherdy, 8 years ago

Initial check in.

File size: 734 bytes
Line 
1# -*- coding: utf-8 -*-
2import antlr3
3from re2pbsLexer import re2pbsLexer
4from re2pbsParser import re2pbsParser
5
6import sys
7
8data = '[\?]'
9
10def readfile(filename):
11        f = open(filename, 'r')
12        contents = f.read()
13        f.close()
14        return contents
15
16def do_parse(char_stream):
17        lexer = re2pbsLexer(char_stream)
18        tokens = antlr3.CommonTokenStream(lexer)
19        parser = re2pbsParser(tokens)
20        parser.prog()
21       
22if __name__ == "__main__":
23               
24        lgth = len(sys.argv)
25
26        if lgth == 1:
27                char_stream = antlr3.ANTLRStringStream(data)
28                do_parse(char_stream)
29
30        if len(sys.argv) == 2:
31                filename = sys.argv[1]
32                char_stream = antlr3.ANTLRFileStream(filename, 'utf-8')
33                do_parse(char_stream)
34
35        elif len(sys.argv) > 2:
36                print("Usage: python parabix2.py <file>")       
37
Note: See TracBrowser for help on using the repository browser.