-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbootstrap.py
More file actions
26 lines (21 loc) · 832 Bytes
/
bootstrap.py
File metadata and controls
26 lines (21 loc) · 832 Bytes
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
import sys
try:
from hermes.GrammarCodeGenerator import TemplateWriter
from hermes.GrammarCodeGenerator import FactoryFactory as TemplateFactoryFactory
from hermes.GrammarFileParser import GrammarFileParser, HermesParserFactory
except:
sys.stderr.write('Hermes is not installed. Cannot bootstrap.\n')
sys.exit(-1)
grammars = [
('pp', 'grammars/pp.zgr'),
('c', 'grammars/c.zgr')
]
cGrammars = []
for name, grammarFile in grammars:
print('generating parser for grammar %s' % (grammarFile))
grammarFileParser = GrammarFileParser(HermesParserFactory().create())
cGrammars.append( grammarFileParser.parse( name, open(grammarFile) ) )
templateFactory = TemplateFactoryFactory().create('python')
templateWriter = TemplateWriter(templateFactory)
templateWriter.write(cGrammars, 'cast', addMain=False)
import setup