예제 #1
0
파일: converge.py 프로젝트: siwiwit/slps
def projectSymbols(xs,ss):
	if xs.who() == 'Sequence':
		e = BGF3.Sequence()
		for x in xs.data:
			# TODO: now works only for nonterminals
			if x.wrapped.who() == 'Nonterminal' and x.wrapped.data in ss:
				m = BGF3.Marked()
				m.setExpr(BGF3.Expression(x))
				e.add(m)
			else:
				e.add(x)
		return e
	else:
		print('projectSymbols not implemented for',xs.who())
		print('■')
		sys.exit(1)
예제 #2
0
파일: converge.py 프로젝트: siwiwit/slps
def renameNinExpr(namemap,expr):
	if expr.who() == 'Sequence':
		e = BGF3.Sequence()
		for el in expr.data:
			e.add(BGF3.Expression(renameNinExpr(namemap,el.wrapped)))
		return e
	elif expr.who() == 'Nonterminal':
		e = BGF3.Nonterminal()
		if expr.data in namemap:
			e.setName(namemap[expr.data])
		else:
			e.setName(expr.data)
		return e
	else:
		print('Unfinished implementation of renameNin for',expr.who())
		print('■')
		sys.exit(1)
예제 #3
0
				else:
					s1 = s
				if k1==k2:
					# print('[MBGF] iteration('+l+','+n+','+s+','+k1+','+k2+') ::= id')
					print('id')
				elif k1=='iterate' and k2.endswith('assoc'):
					# print('[MBGF] iteration('+l+','+n+','+s+','+k1+','+k2+') ::= '+k2+'(['+l+'] '+n1+' ← '+n1+' '+s1+' '+n1+')')
					if s1:
						print(k2+'(['+l+'] '+n1+' ← '+n1+' '+s1+' '+n1+')')
					else:
						print(k2+'(['+l+'] '+n1+' ← '+n1+' '+n1+')')
					ren = XBGF3.Step(k2)
					p = BGF3.Production()
					p.setLabel(l)
					p.setNT(n1)
					e = BGF3.Sequence()
					e2 = BGF3.Nonterminal()
					e2.setName(n1)
					e.add(BGF3.Expression(e2))
					if s:
						e2 = BGF3.Nonterminal()
						e2.setName(s1)
						e.add(BGF3.Expression(e2))
					e2 = BGF3.Nonterminal()
					e2.setName(n1)
					e.add(BGF3.Expression(e2))
					p.setExpr(BGF3.Expression(e))
					ren.addParam(p)
					xbgfsbyid[id].append(ren)
				elif k1.endswith('assoc') and k2=='iterate':
					if s1: