Permalink
Browse files

fixing the last bugs in the last two tools

git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@901 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information...
grammarware committed Dec 10, 2010
1 parent 2641224 commit 0276b477765557ac183281cb960990a2d7e07bc6
@@ -1,10 +1,20 @@
all:
echo 'Extracting the actual grammar...'
./extract.py RascalRascal.rsc rascal.bgf
../../../shared/tools/validate bgf rascal.bgf
../../../shared/tools/subgrammar rascal.bgf Module rascal.true.bgf
../../../shared/tools/validate bgf rascal.true.bgf
../../../shared/tools/bgf2bnf rascal.bgf rascal.bnf
../../../shared/tools/bgf2bnf rascal.true.bgf rascal.true.bnf
../../../shared/tools/bgf2html rascal.true.bgf rascal.true.html
echo 'Recovering the horizontal grammar...'
../../../shared/tools/xbgf horizontalize.xbgf rascal.bgf rascal.hor.bgf
../../../shared/tools/validate bgf rascal.hor.bgf
../../../shared/tools/subgrammar rascal.hor.bgf Module rascal.true.hor.bgf
../../../shared/tools/validate bgf rascal.true.hor.bgf
../../../shared/tools/bgf2bnf rascal.hor.bgf rascal.hor.bnf
../../../shared/tools/bgf2bnf rascal.true.hor.bgf rascal.true.hor.bnf
../../../shared/tools/bgf2html rascal.true.hor.bgf rascal.true.hor.html
clean:
rm -f *.bgf *.bnf
rm -f *.bgf *.bnf *.html
@@ -92,6 +92,7 @@ def parseGroup(g):
for nt in grammar.keys():
for alt in grammar[nt]:
if prevline:
# dead code yet
prevline.append('|')
prevline.extend(alt)
alt = prevline[:]
@@ -112,6 +113,15 @@ def parseGroup(g):
# if there is whitespace between the label and the :
prod.setLabel(alt[0])
alt = alt[2:]
if alt and len(alt)>1 and alt[0][:2] == '/*':
if alt[0].find('*/')>0:
alt[0] = alt[0][:alt[0].index('/*')] + alt[0][alt[0].index('*/')+2:]
if alt[0] == '':
alt = alt[1:]
# had to do it the second time - bad sign
if alt and len(alt)>0 and alt[0][-1] == ':':
prod.setLabel(alt[0][:-1])
alt = alt[1:]
cx = 0
seq = BGF.Sequence()
sym = None
@@ -157,8 +167,21 @@ def parseGroup(g):
if alt[cx][0].isupper() or alt[cx][0]=='&':
if sym:
seq.add(sym)
sym = BGF.Nonterminal()
sym.setName(alt[cx])
if alt[cx][-1] == '+':
sym = BGF.Plus()
sym.setExpr(BGF.Nonterminal())
sym.data.setName(alt[cx][:-1])
elif alt[cx][-1] == '*':
sym = BGF.Star()
sym.setExpr(BGF.Nonterminal())
sym.data.setName(alt[cx][:-1])
elif alt[cx][-1] == '?':
sym = BGF.Optional()
sym.setExpr(BGF.Nonterminal())
sym.data.setName(alt[cx][:-1])
else:
sym = BGF.Nonterminal()
sym.setName(alt[cx])
cx += 1
continue
if alt[cx] == 'lex':
@@ -237,7 +260,7 @@ def parseGroup(g):
seq.add(sym)
prod.setExpr(seq)
bgf.addProd(prod)
elif curly == 0 and len(seq.data)>0:
elif curly == 0 and (len(seq.data)>0 or prod.label != ''):
#print 'Adding2',seq
prod.setExpr(seq)
#print str(prod)
@@ -27,11 +27,14 @@
ET.SubElement(newBgf,'root').text = nts[0]
oldnts = []
while nts:
for prod in grammar[nts[0]]:
newBgf.append(prod)
for nt in prod.findall('.//nonterminal'):
if (nt.text not in oldnts) and (nt.text not in nts):
nts.append(nt.text)
if nts[0] not in grammar.keys():
print 'Nonterminal not found:',nts[0]
else:
for prod in grammar[nts[0]]:
newBgf.append(prod)
for nt in prod.findall('.//nonterminal'):
if (nt.text not in oldnts) and (nt.text not in nts):
nts.append(nt.text)
oldnts.append(nts[0]) # car
nts = nts[1:] # cdr
ET.ElementTree(newBgf).write(sys.argv[3])

0 comments on commit 0276b47

Please sign in to comment.