-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopsc.py
More file actions
executable file
·59 lines (42 loc) · 1.85 KB
/
Copy pathoopsc.py
File metadata and controls
executable file
·59 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# coding: utf-8
import sys, os, logging
from optparse import OptionParser
import lexer
import parser
from utils import TokenStream
def generate_parser():
usage = "%prog [options] source [dest]"
parser = OptionParser(usage=usage)
parser.add_option("-c", "--print-context", dest="p_context",
action="store_true", default=False,
help='print the outcome of the context analysis')
parser.add_option('--heapsize', dest="heapsize", action='store',
type='int', default=100, metavar='LONGWORDS',
help='set the size of the heap to x LONGWORDS (4 Byte)')
parser.add_option('--stacksize', dest='stacksize', action='store',
type='int', default=50, metavar='LONGWORDS',
help='set the size of the stack to x LONDWORDS (4 Byte)')
parser.add_option('-i', '--print-identifier', dest='p_identifier',
action='store_true', default=False, help='print the '
'identifier map')
parser.add_option('-I', '--print-lexical', dest='p_lexical',
action='store_true', default=False,
help='print the outcome of the lexical analysis')
parser.add_option('-s', '--print-syntax', dest='p_syntax',
action='store_true', default=False,
help='print the outcome of the syntax analysis')
return parser
if __name__ == '__main__':
pars = generate_parser()
options, args = pars.parse_args()
#open the file
f = open(args[0])
char_stream = unicode(f.read(), 'utf8')
tokens = list(lexer.lex(char_stream))
if options.p_lexical:
for token in tokens:
print token
ast = parser.parse(TokenStream(tokens))
if options.p_syntax:
print ast