-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pending changes needed for publication of BX in ECEASST
- Loading branch information
1 parent
b6f06b2
commit 9643736
Showing
5 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.cbgf.forward.xbgf | ||
*.cbgf.reverse.xbgf | ||
*.rsc | ||
tmp.bgf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<xns1:grammar xmlns:xns1="http://planet-sl.org/bgf"> | ||
<root>grammar</root> | ||
<xns1:production> | ||
<nonterminal>grammar</nonterminal> | ||
<xns1:expression> | ||
<plus> | ||
<xns1:expression> | ||
<nonterminal>rule</nonterminal> | ||
</xns1:expression> | ||
</plus> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>rule</nonterminal> | ||
<xns1:expression> | ||
<sequence> | ||
<xns1:expression> | ||
<nonterminal>sort</nonterminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<terminal>:</terminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<nonterminal>alts</nonterminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<terminal>;</terminal> | ||
</xns1:expression> | ||
</sequence> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>alts</nonterminal> | ||
<xns1:expression> | ||
<sequence> | ||
<xns1:expression> | ||
<nonterminal>alt</nonterminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<star> | ||
<xns1:expression> | ||
<nonterminal>alts-tail</nonterminal> | ||
</xns1:expression> | ||
</star> | ||
</xns1:expression> | ||
</sequence> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>alts-tail</nonterminal> | ||
<xns1:expression> | ||
<sequence> | ||
<xns1:expression> | ||
<terminal>|</terminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<nonterminal>alt</nonterminal> | ||
</xns1:expression> | ||
</sequence> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>alt</nonterminal> | ||
<xns1:expression> | ||
<star> | ||
<xns1:expression> | ||
<nonterminal>term</nonterminal> | ||
</xns1:expression> | ||
</star> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>term</nonterminal> | ||
<xns1:expression> | ||
<sequence> | ||
<xns1:expression> | ||
<nonterminal>basis</nonterminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<optional> | ||
<xns1:expression> | ||
<nonterminal>repetition</nonterminal> | ||
</xns1:expression> | ||
</optional> | ||
</xns1:expression> | ||
</sequence> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>basis</nonterminal> | ||
<xns1:expression> | ||
<choice> | ||
<xns1:expression> | ||
<nonterminal>literal</nonterminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<nonterminal>sort</nonterminal> | ||
</xns1:expression> | ||
</choice> | ||
</xns1:expression> | ||
</xns1:production> | ||
<xns1:production> | ||
<nonterminal>repetition</nonterminal> | ||
<xns1:expression> | ||
<choice> | ||
<xns1:expression> | ||
<terminal>*</terminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<terminal>+</terminal> | ||
</xns1:expression> | ||
<xns1:expression> | ||
<terminal>?</terminal> | ||
</xns1:expression> | ||
</choice> | ||
</xns1:expression> | ||
</xns1:production> | ||
</xns1:grammar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<cbgf:relationship xmlns:cbgf="http://planet-sl.org/cbgf"><cbgf:rename-rename><nonterminal><from>LLL1Grammar</from><to>LLL2genGrammar</to></nonterminal></cbgf:rename-rename><cbgf:rename-rename><nonterminal><from>LLL1Production</from><to>LLL2genProduction</to></nonterminal></cbgf:rename-rename><cbgf:rename-rename><nonterminal><from>LLL1Definition</from><to>LLL2genDefinition</to></nonterminal></cbgf:rename-rename><cbgf:rename-rename><nonterminal><from>LLL1Symbol</from><to>LLL2genSymbol</to></nonterminal></cbgf:rename-rename><cbgf:rename-rename><nonterminal><from>LLL1Nonterminal</from><to>LLL2genNonterminal</to></nonterminal></cbgf:rename-rename><cbgf:rename-rename><nonterminal><from>LLL1Terminal</from><to>LLL2genTerminal</to></nonterminal></cbgf:rename-rename><cbgf:add-remove><vertical><bgf:production xmlns:bgf="http://planet-sl.org/bgf"><label>group</label><nonterminal>LLL2genSymbol</nonterminal><bgf:expression><sequence><bgf:expression><terminal>(</terminal></bgf:expression><bgf:expression><seplistplus><bgf:expression><nonterminal>LLL2genDefinition</nonterminal></bgf:expression><bgf:expression><terminal>|</terminal></bgf:expression></seplistplus></bgf:expression><bgf:expression><terminal>)</terminal></bgf:expression></sequence></bgf:expression></bgf:production></vertical></cbgf:add-remove><cbgf:add-remove><vertical><bgf:production xmlns:bgf="http://planet-sl.org/bgf"><label>sepliststar</label><nonterminal>LLL2genSymbol</nonterminal><bgf:expression><sequence><bgf:expression><terminal>{</terminal></bgf:expression><bgf:expression><nonterminal>LLL2genSymbol</nonterminal></bgf:expression><bgf:expression><nonterminal>LLL2genSymbol</nonterminal></bgf:expression><bgf:expression><terminal>}*</terminal></bgf:expression></sequence></bgf:expression></bgf:production></vertical></cbgf:add-remove><cbgf:add-remove><vertical><bgf:production xmlns:bgf="http://planet-sl.org/bgf"><label>seplistplus</label><nonterminal>LLL2genSymbol</nonterminal><bgf:expression><sequence><bgf:expression><terminal>{</terminal></bgf:expression><bgf:expression><nonterminal>LLL2genSymbol</nonterminal></bgf:expression><bgf:expression><nonterminal>LLL2genSymbol</nonterminal></bgf:expression><bgf:expression><terminal>}+</terminal></bgf:expression></sequence></bgf:expression></bgf:production></vertical></cbgf:add-remove></cbgf:relationship> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ns0:grammar xmlns:ns0="http://planet-sl.org/bgf"><ns0:production><nonterminal>specification</nonterminal><ns0:expression><plus><ns0:expression><nonterminal>rule</nonterminal></ns0:expression></plus></ns0:expression></ns0:production><ns0:production><nonterminal>rule</nonterminal><ns0:expression><sequence><ns0:expression><nonterminal>ident</nonterminal></ns0:expression><ns0:expression><terminal>:</terminal></ns0:expression><ns0:expression><nonterminal>disjunction</nonterminal></ns0:expression><ns0:expression><terminal>;</terminal></ns0:expression></sequence></ns0:expression></ns0:production><ns0:production><nonterminal>disjunction</nonterminal><ns0:expression><seplistplus><ns0:expression><nonterminal>conjunction</nonterminal></ns0:expression><ns0:expression><terminal>|</terminal></ns0:expression></seplistplus></ns0:expression></ns0:production><ns0:production><nonterminal>conjunction</nonterminal><ns0:expression><plus><ns0:expression><nonterminal>term</nonterminal></ns0:expression></plus></ns0:expression></ns0:production><ns0:production><nonterminal>term</nonterminal><ns0:expression><sequence><ns0:expression><nonterminal>basis</nonterminal></ns0:expression><ns0:expression><optional><ns0:expression><nonterminal>repetition</nonterminal></ns0:expression></optional></ns0:expression></sequence></ns0:expression></ns0:production><ns0:production><nonterminal>basis</nonterminal><ns0:expression><choice><ns0:expression><nonterminal>ident</nonterminal></ns0:expression><ns0:expression><nonterminal>literal</nonterminal></ns0:expression><ns0:expression><terminal>%epsilon</terminal></ns0:expression><ns0:expression><nonterminal>alternation</nonterminal></ns0:expression><ns0:expression><nonterminal>group</nonterminal></ns0:expression></choice></ns0:expression></ns0:production><ns0:production><nonterminal>repetition</nonterminal><ns0:expression><choice><ns0:expression><terminal>+</terminal></ns0:expression><ns0:expression><terminal>*</terminal></ns0:expression><ns0:expression><terminal>?</terminal></ns0:expression></choice></ns0:expression></ns0:production><ns0:production><nonterminal>alternation</nonterminal><ns0:expression><sequence><ns0:expression><terminal>{</terminal></ns0:expression><ns0:expression><nonterminal>basis</nonterminal></ns0:expression><ns0:expression><nonterminal>basis</nonterminal></ns0:expression><ns0:expression><terminal>}</terminal></ns0:expression><ns0:expression><nonterminal>repetition</nonterminal></ns0:expression></sequence></ns0:expression></ns0:production><ns0:production><nonterminal>group</nonterminal><ns0:expression><sequence><ns0:expression><terminal>(</terminal></ns0:expression><ns0:expression><nonterminal>disjunction</nonterminal></ns0:expression><ns0:expression><terminal>)</terminal></ns0:expression></sequence></ns0:expression></ns0:production></ns0:grammar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
#!/Library/Frameworks/Python.framework/Versions/3.1/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
import os, sys | ||
import xml.etree.ElementTree as ET | ||
sys.path.append(os.getcwd().split('projects')[0]+'projects/slps/shared/python') | ||
import BGF3, slpsns | ||
from functools import reduce | ||
import xml.etree.ElementTree as ET | ||
|
||
debug = False | ||
#debug = True | ||
|
||
defaults = {'definition-separator-symbol':'|||||'} | ||
config = {} | ||
masked = {} | ||
always_terminals = [] | ||
always_nonterminals = [] | ||
ignore_tokens = [] | ||
ignore_lines = [] | ||
nonterminals_alphabet = ['-','_'] | ||
nonterminals_start = [] | ||
multiples = [] | ||
aliases = {} | ||
|
||
metasymbols = \ | ||
[ | ||
'DEFINING-SYMBOL', | ||
'TERMINATOR-SYMBOL', | ||
'MULTIPLE-DEFINING-SYMBOL', | ||
'DEFINITION-SEPARATOR-SYMBOL', | ||
'START-GROUP-SYMBOL', | ||
'END-GROUP-SYMBOL', | ||
'START-OPTION-SYMBOL', | ||
'END-OPTION-SYMBOL', | ||
'START-REPETITION-STAR-SYMBOL', | ||
'END-REPETITION-STAR-SYMBOL', | ||
'START-REPETITION-PLUS-SYMBOL', | ||
'END-REPETITION-PLUS-SYMBOL', | ||
'START-SEPLIST-STAR-SYMBOL', | ||
'END-SEPLIST-STAR-SYMBOL', | ||
'START-SEPLIST-PLUS-SYMBOL', | ||
'END-SEPLIST-PLUS-SYMBOL', | ||
'POSTFIX-OPTION-SYMBOL', | ||
'POSTFIX-REPETITION-STAR-SYMBOL', | ||
'POSTFIX-REPETITION-PLUS-SYMBOL', | ||
] | ||
specials = \ | ||
[ | ||
'POSSIBLE-TERMINATOR-SYMBOL', | ||
'CONCATENATE-SYMBOL', | ||
'LINE-CONTINUATION-SYMBOL' | ||
'START-TERMINAL-SYMBOL', | ||
'END-TERMINAL-SYMBOL', | ||
'START-NONTERMINAL-SYMBOL', | ||
'END-NONTERMINAL-SYMBOL', | ||
'NONTERMINAL-IF-CONTAINS', | ||
'NONTERMINAL-IF-DEFINED', | ||
'NONTERMINAL-IF-UPPERCASE', | ||
'NONTERMINAL-IF-LOWERCASE', | ||
'NONTERMINAL-IF-CAMELCASE', | ||
'NONTERMINAL-IF-MIXEDCASE', | ||
'TERMINAL-IF-UNDEFINED', | ||
'TERMINAL-IF-UPPERCASE', | ||
'TERMINAL-IF-LOWERCASE', | ||
'TERMINAL-IF-CAMELCASE', | ||
'TERMINAL-IF-MIXEDCASE', | ||
'IGNORE-EXTRA-NEWLINES', | ||
'GLUE-NONALPHANUMERIC-TERMINALS', | ||
] | ||
specials.extend(metasymbols) | ||
|
||
def readConfig(f): | ||
global debug | ||
cfg = ET.parse(f) | ||
for e in cfg.findall('*'): | ||
if e.tag == 'mask': | ||
if e.findall('terminal'): | ||
masked[e.findtext('token')] = e.findtext('terminal') | ||
elif e.findall('epsilon'): | ||
masked[e.findtext('token')] = 'EPSILON' | ||
else: | ||
print('Unknown masked token:',e.findtext('token')) | ||
elif e.tag == 'nonterminals-may-contain': | ||
for x in e.text: | ||
nonterminals_alphabet.append(x) | ||
elif e.tag == 'nonterminals-may-start-with': | ||
for x in e.text: | ||
nonterminals_start.append(x) | ||
elif e.tag == 'ignore': | ||
#config[e.tag] = '' | ||
for x in e.findall('*'): | ||
if x.tag == 'newline': | ||
ignore_tokens.append('\n') | ||
ignore_tokens.append('@@@0-0') | ||
elif x.tag == 'space': | ||
ignore_tokens.append(' ') | ||
elif x.tag == 'lines-containing': | ||
ignore_lines.append(x.text) | ||
elif x.tag == 'same-indentation': | ||
ignore_tokens.append('@@@1-1') | ||
else: | ||
ignore_tokens.append(x.text) | ||
elif e.tag == 'alias': | ||
for x in e.findall('*'): | ||
if x.tag not in aliases.keys(): | ||
aliases[x.tag] = [] | ||
aliases[x.tag].append(x.text) | ||
elif e.text: | ||
config[e.tag] = e.text.replace('\\n','\n') | ||
else: | ||
config[e.tag] = '' | ||
if e.tag in ('nonterminal-if-camelcase','nonterminal-if-mixedcase','nonterminal-if-uppercase','nonterminal-if-lowercase','nonterminal-if-contains','nonterminal-if-defined','decompose-symbols'): | ||
if e.text: | ||
config[e.tag] = e.text | ||
else: | ||
config[e.tag] = '' | ||
for x in e.findall('except'): | ||
always_terminals.append(x.text) | ||
if e.tag in ('terminal-if-camelcase','terminal-if-mixedcase','terminal-if-uppercase','terminal-if-lowercase','terminal-if-undefined'): | ||
config[e.tag] = '' | ||
for x in e.findall('except'): | ||
always_nonterminals.append(x.text) | ||
if debug: | ||
print('Ok',config) | ||
|
||
def writeConfig(f): | ||
global debug | ||
cfg = ET.Element(slpsns.edd_('config')) | ||
for ms in config.keys(): | ||
ET.SubElement(cfg,ms).text = config[ms] | ||
#print(ms,'processed.') | ||
ig = ET.Element('ignore') | ||
igy = False | ||
for i in ignore_tokens: | ||
if i == '\n': | ||
ET.SubElement(ig,'newline') | ||
igy = True | ||
elif i.find('@@@') == 0: | ||
pass | ||
else: | ||
print('Ignore %s?'%i) | ||
for i in ignore_lines: | ||
ET.SubElement(ig,'lines-containing').text = i | ||
igy = True | ||
if igy: | ||
cfg.append(ig) | ||
ET.ElementTree(cfg).write(f) | ||
|
||
def quoted(x): | ||
return '"'+x+'"' | ||
|
||
def grammarNameOf(x): | ||
if x.find('/') < 0: | ||
return x.split('.')[0] | ||
else: | ||
return x.split('/')[-1].split('.')[0] | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 6: | ||
print('Usage:') | ||
print(' xedd.py input.xedd input.edd output.edd coupled-grammar.cbgf coupled-grammarbase.cbgf') | ||
sys.exit(-1) | ||
slpsns.init(ET) | ||
readConfig(sys.argv[2]) | ||
cbgf = ET.Element(slpsns.cbgf_('relationship')) | ||
cbgfr = ET.Element(slpsns.cbgf_('relationship')) | ||
# renaming ALWAYS happens if the name of the notation is changed | ||
# if we do not call two different entities two different names, we cannot tell them apart | ||
edd1 = grammarNameOf(sys.argv[2]) | ||
edd2 = grammarNameOf(sys.argv[3]) | ||
for s in ('Grammar', 'Production', 'Definition', 'Symbol','Nonterminal','Terminal'): | ||
r = ET.SubElement(cbgf,slpsns.cbgf_('rename-rename')) | ||
n = ET.SubElement(r,'nonterminal') | ||
ET.SubElement(n,'from').text = edd1 + s | ||
ET.SubElement(n,'to').text = edd2 + s | ||
# processing commands | ||
for cmd in ET.parse(sys.argv[1]).findall('*'): | ||
if cmd.tag == slpsns.xedd_('rename'): | ||
ms = cmd.findtext('metasymbol') | ||
x = cmd.findtext('from') | ||
y = cmd.findtext('to') | ||
print('xedd:rename-metasymbol('+ms+', '+quoted(x)+', '+quoted(y)+');') | ||
ms += '-symbol' | ||
if ms in config.keys(): | ||
if config[ms] == x: | ||
config[ms] = y | ||
r = ET.SubElement(cbgf,slpsns.cbgf_('rename-rename')) | ||
t = ET.SubElement(r,'terminal') | ||
ET.SubElement(t,'from').text = x | ||
ET.SubElement(t,'to').text = y | ||
else: | ||
print('Impossible to rename since %s is "%s" and not "%s" as expected!'%(ms,config[ms],x)) | ||
sys.exit(-1) | ||
else: | ||
print('Impossible to rename since %s is not defined!'%ms) | ||
sys.exit(-1) | ||
elif cmd.tag == slpsns.xedd_('introduce'): | ||
ms = cmd.findtext('metasymbol') | ||
x = cmd.findtext('start') | ||
y = cmd.findtext('end') | ||
print('xedd:introduce-metasymbol('+ms+', '+quoted(x)+', '+quoted(y)+');') | ||
ms1 = 'start-'+ms+'-symbol' | ||
ms2 = 'end-'+ms+'-symbol' | ||
if ms1 in config.keys(): | ||
print('Cannot introduce metasymbol that is already defined: %s.' % ms1) | ||
sys.exit(1) | ||
elif ms2 in config.keys(): | ||
print('Cannot introduce metasymbol that is already defined: %s.' % ms2) | ||
sys.exit(1) | ||
else: | ||
config[ms1] = x | ||
config[ms2] = y | ||
if ms == 'group': | ||
p = ET.SubElement(cbgf,slpsns.cbgf_('add-remove')) | ||
p = ET.SubElement(p,'vertical') | ||
p = ET.SubElement(p,slpsns.bgf_('production')) | ||
ET.SubElement(p,'label').text = ms | ||
ET.SubElement(p,'nonterminal').text = edd2 + 'Symbol' | ||
e = ET.SubElement(p,slpsns.bgf_('expression')) | ||
s = ET.SubElement(e,'sequence') | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'terminal').text = x | ||
if 'definition-separator-symbol' in config: | ||
slp = ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'seplistplus') | ||
ET.SubElement(ET.SubElement(slp,slpsns.bgf_('expression')),'nonterminal').text = edd2 + 'Definition' | ||
ET.SubElement(ET.SubElement(slp,slpsns.bgf_('expression')),'terminal').text = config['definition-separator-symbol'] | ||
else: | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'nonterminal').text = edd2 + 'Definition' | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'terminal').text = y | ||
elif ms in ('seplist-plus','seplist-star'): | ||
p = ET.SubElement(cbgf,slpsns.cbgf_('add-remove')) | ||
p = ET.SubElement(p,'vertical') | ||
p = ET.SubElement(p,slpsns.bgf_('production')) | ||
ET.SubElement(p,'label').text = ms.replace('-','') | ||
ET.SubElement(p,'nonterminal').text = edd2 + 'Symbol' | ||
e = ET.SubElement(p,slpsns.bgf_('expression')) | ||
s = ET.SubElement(e,'sequence') | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'terminal').text = x | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'nonterminal').text = edd2 + 'Symbol' | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'nonterminal').text = edd2 + 'Symbol' | ||
ET.SubElement(ET.SubElement(s,slpsns.bgf_('expression')),'terminal').text = y | ||
else: | ||
print('No coupled transformation added, please teach me how to do it first.') | ||
|
||
else: | ||
print(cmd.tag,'is unknown') | ||
writeConfig(sys.argv[3]) | ||
print('Coupled notation grammar transformation: %i steps' % len(cbgf)) | ||
ET.ElementTree(cbgf).write(sys.argv[4]) | ||
print('Coupled grammarbase transformation: %i steps' % len(cbgfr)) | ||
ET.ElementTree(cbgfr).write(sys.argv[5]) |