Skip to content

Commit

Permalink
top choices constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed May 15, 2012
1 parent c0eabf7 commit a60996e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
14 changes: 13 additions & 1 deletion shared/python/MBGF.py
Expand Up @@ -175,4 +175,16 @@ class Anonymity (SrcProdModel):
def __init__(self, xml):
self.parse(xml)
def getSpecifics(self):
return ''
return '—'

# <top-choice>
# <name>ops</name>
# <src name="ant">horizontal</src>
# <src name="dcg,sdf,rsc">vertical</src>
# </top-choice>
class TopChoice (SrcSimpleModel):
def __init__(self, xml):
self.nt = xml.findtext('name')
self.parse(xml)
def getSpecifics(self):
return 'n('+self.nt+')'
49 changes: 33 additions & 16 deletions topics/convergence/tri/mbgf2xbgf.py
Expand Up @@ -76,6 +76,8 @@ def wrapexp(exp,mod):
predicates.append(MBGF.Iteration(e))
elif e.tag=='anonymity':
predicates.append(MBGF.Anonymity(e))
elif e.tag=='top-choice':
predicates.append(MBGF.TopChoice(e))
else:
print('Predicate',e.tag,'not supported.')
# print(sources)
Expand Down Expand Up @@ -207,18 +209,18 @@ def wrapexp(exp,mod):
s = p.sep
k1 = p.getData(inname)
k2 = p.getData(outname)
if n in namemap:
n1 = namemap[n]
else:
n1 = n
if s in namemap:
s1 = namemap[s]
else:
s1 = s
if k1==k2:
# print('[MBGF] iteration('+l+','+n+','+s+','+k1+','+k2+') ::= id')
print('id')
elif k1=='iterate' and k2.endswith('assoc'):
if n in namemap:
n1 = namemap[n]
else:
n1 = n
if s in namemap:
s1 = namemap[s]
else:
s1 = s
# print('[MBGF] iteration('+l+','+n+','+s+','+k1+','+k2+') ::= '+k2+'(['+l+'] '+n1+' ← '+n1+' '+s1+' '+n1+')')
print(k2+'(['+l+'] '+n1+' ← '+n1+' '+s1+' '+n1+')')
ren = XBGF3.Step(k2)
Expand All @@ -240,14 +242,6 @@ def wrapexp(exp,mod):
ren.addParam(p)
xbgfsbyid[id].append(ren)
elif k1.endswith('assoc') and k2=='iterate':
if n in namemap:
n1 = namemap[n]
else:
n1 = n
if s in namemap:
s1 = namemap[s]
else:
s1 = s
if s1:
ass = n1+' ('+s1+' '+n1+')*'
else:
Expand Down Expand Up @@ -309,6 +303,29 @@ def wrapexp(exp,mod):
print('id')
else:
print('Weird: from',ps1,'to',ps2)
elif p.who() == 'TopChoice':
n = p.nt
if n in namemap:
n1 = namemap[n]
else:
n1 = n
k1 = p.getData(inname)
k2 = p.getData(outname)
if k1==k2:
print('id')
elif k1 == 'horizontal' and k2 == 'vertical':
cmd = 'vertical'
elif k2 == 'horizontal' and k1 == 'vertical':
cmd = 'horizontal'
else:
print('ERROR: unknown presets:',k1,'vs',k2)
sys.exit(2)
print(cmd+'('+n1+')')
ren = XBGF3.Step(cmd)
p = XBGF3.Nonterminal()
p.setName(n1)
ren.addParam(p)
xbgfsbyid[id].append(ren)
else:
print('UNKNOWN COMMAND')
scheduled = []
Expand Down
5 changes: 5 additions & 0 deletions topics/convergence/tri/test.mbgf
Expand Up @@ -340,4 +340,9 @@
</bgf:production>
</src>
</anonymity> -->
<top-choice>
<name>ops</name>
<src name="ant">horizontal</src>
<src name="dcg,sdf,rsc">vertical</src>
</top-choice>
</mbgf:sequence>

0 comments on commit a60996e

Please sign in to comment.