Navigation Menu

Skip to content

Commit

Permalink
updated the extractor, added BGF analysis tool
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@408 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Nov 8, 2008
1 parent b0254b0 commit 3087a55
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 38 deletions.
11 changes: 11 additions & 0 deletions shared/tools/checkbgf
@@ -0,0 +1,11 @@
#!/bin/sh

# Get our hands on basedir
LOCAL1=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL1}

python ${SLPS}/topics/presentation/analyses/bgf_check.py $1

5 changes: 5 additions & 0 deletions topics/extraction/html2bgf/html2bgf.py
Expand Up @@ -286,6 +286,11 @@ def mapHTMLtoTokenStream(line):
flags.append(True)
line = line[14:]
continue
if line.find('<sub>Opt</sub>')==0:
tokens.append('?????')
flags.append(True)
line = line[14:]
continue
if line.find('<sub><i>opt')==0:
tokens.append('?????')
flags.append(True)
Expand Down
2 changes: 1 addition & 1 deletion topics/java/lci/Makefile
Expand Up @@ -4,7 +4,7 @@ build:

diff:
python ../../convergence/lci/lci.py java3.lcf architecture
gdts bgf/app3.correct.refactor.generalizeLabels.generalizeBlock.generalize.bgf bgf/doc3.correct.generalizeModifiers.generalizeNames.deyaccify.refactorTypes.refactorExpressions.inlineStatements.generalizeStatements.refactorStatements.editExpressions.refactorClasses.refactorInterfaces.refactorEnums.refactorDeclarations.edit.bgf
gdts bgf/wa.bgf bgf/wd.bgf

test:
python ../../convergence/lci/lci.py java.lcf architecture
Expand Down
3 changes: 2 additions & 1 deletion topics/java/lci/java-lci.csproj
Expand Up @@ -97,7 +97,8 @@
<None Include="xbgf\refactorExpressions.xbgf" />
<None Include="xbgf\refactorInterfaces-doc2.xbgf" />
<None Include="xbgf\refactorInterfaces-doc3.xbgf" />
<None Include="xbgf\refactorStatements.xbgf" />
<None Include="xbgf\refactorStatements-doc3.xbgf" />
<None Include="xbgf\refactorStatements-jls1.xbgf" />
<None Include="xbgf\refactorTypes-doc2.xbgf" />
<None Include="xbgf\refactorTypes-doc3.xbgf" />
<None Include="xbgf\refactorTypes-jls1.xbgf" />
Expand Down
5 changes: 5 additions & 0 deletions topics/java/lci/xbgf/correct-app3.xbgf
Expand Up @@ -178,4 +178,9 @@ Annotation:
<nonterminal>ElementValues</nonterminal>
</in>
</xbgf:replace>

<!-- undefine lexical term -->
<!-- GENERALITY -->
<xbgf:undefine>Identifier</xbgf:undefine>

</xbgf:sequence>
19 changes: 10 additions & 9 deletions topics/java/lci/xbgf/extend-doc12.xbgf
Expand Up @@ -1506,10 +1506,11 @@
<terminal>?</terminal>
</bgf:expression>
<bgf:expression>
<nonterminal>WildcardBounds</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>Opt</nonterminal>
<optional>
<bgf:expression>
<nonterminal>WildcardBounds</nonterminal>
</bgf:expression>
</optional>
</bgf:expression>
</sequence>
</bgf:expression>
Expand Down Expand Up @@ -1609,11 +1610,11 @@
vs.
- [], ,([n(TypeDeclSpecifier), ?(n(TypeArguments))])
-->
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:undefine>InterfaceType</xbgf:undefine>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:undefine>ClassType</xbgf:undefine>
<!-- GENERALITY -->
<!-- GENERALITY -->
<xbgf:define>
<bgf:production>
<nonterminal>InterfaceType</nonterminal>
Expand All @@ -1633,7 +1634,7 @@
</bgf:expression>
</bgf:production>
</xbgf:define>
<!-- GENERALITY -->
<!-- GENERALITY -->
<xbgf:define>
<bgf:production>
<nonterminal>ClassType</nonterminal>
Expand Down Expand Up @@ -2164,7 +2165,7 @@
</sequence>
</bgf:expression>
</bgf:production>
</xbgf:designate>
</xbgf:designate>
<!-- ??? please redo with one replace -->
<!-- GENERALITY -->
<xbgf:project>
Expand Down
37 changes: 32 additions & 5 deletions topics/java/lci/xbgf/refactor-app3.xbgf
Expand Up @@ -12,9 +12,6 @@
<xbgf:vertical>
<nonterminal>Expression3</nonterminal>
</xbgf:vertical>
<xbgf:vertical>
<nonterminal>InterfaceMemberDecl</nonterminal>
</xbgf:vertical>

<!--
- Fail: Annotations.
Expand Down Expand Up @@ -81,7 +78,7 @@
','([n('Primary'), *(n('Selector')), *(n('PostfixOp'))])
vs
;([n('Primary'), n('QualifiedIdentifier'), ','([n('PostfixExpression'), n('PostfixOp')])])
-->
-->
<!-- BREFACTOR -->
<xbgf:replace>
<bgf:expression>
Expand All @@ -108,7 +105,37 @@
</bgf:expression>
</choice>
</bgf:expression>
</xbgf:replace>
</xbgf:replace>
<xbgf:eliminate>Selector</xbgf:eliminate>

<!-- Making new nonterminal -->
<xbgf:extract>
<bgf:production>
<nonterminal>ModifiersOpt</nonterminal>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>Modifier</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
</bgf:production>
</xbgf:extract>

<!-- we don't need minimised lookahead here -->
<xbgf:inline>InterfaceMemberDecl</xbgf:inline>
<xbgf:inline>InterfaceMethodOrFieldDecl</xbgf:inline>
<xbgf:inline>InterfaceMethodOrFieldRest</xbgf:inline>
<xbgf:inline>InterfaceGenericMethodDecl</xbgf:inline>
<xbgf:inline>InterfaceMethodDeclaratorRest</xbgf:inline>
<xbgf:inline>VoidInterfaceMethodDeclaratorRest</xbgf:inline>
<xbgf:inline>ConstantDeclaratorsRest</xbgf:inline>

<xbgf:distribute>
<nonterminal>InterfaceBodyDeclaration</nonterminal>
</xbgf:distribute>
<!--remove when done-->
<xbgf:vertical>
<nonterminal>InterfaceBodyDeclaration</nonterminal>
</xbgf:vertical>
</xbgf:sequence>
4 changes: 2 additions & 2 deletions topics/java/lci/xbgf/refactorClasses-doc2.xbgf
Expand Up @@ -94,7 +94,7 @@

Later with factor/distribute this should be done better!
-->
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:inject>
<bgf:production>
<nonterminal>ClassOrInterfaceDeclaration</nonterminal>
Expand Down Expand Up @@ -405,7 +405,7 @@
</bgf:expression>
</bgf:production>
</xbgf:designate>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:inject>
<bgf:production>
<label>target</label>
Expand Down
31 changes: 11 additions & 20 deletions topics/java/lci/xbgf/refactorClasses-doc3.xbgf
Expand Up @@ -175,7 +175,7 @@
</bgf:expression>
</bgf:production>
</xbgf:designate>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:inject>
<bgf:production>
<label>target</label>
Expand Down Expand Up @@ -204,7 +204,7 @@
</bgf:expression>
</bgf:production>
</xbgf:designate>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:inject>
<bgf:production>
<label>target</label>
Expand Down Expand Up @@ -305,9 +305,9 @@
vs.
- [], ;([n(FormalParameter), ,([n(FormalParameters), t((,)), n(FormalParameter)])])
-->
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:undefine>FormalParameters</xbgf:undefine>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>FormalParameters</nonterminal>
Expand All @@ -330,7 +330,7 @@
</bgf:expression>
</bgf:production>
</xbgf:define>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>FormalParameterDecls</nonterminal>
Expand Down Expand Up @@ -360,7 +360,7 @@
</bgf:expression>
</bgf:production>
</xbgf:define>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>FormalParameterDeclsRest</nonterminal>
Expand Down Expand Up @@ -654,7 +654,7 @@
</bgf:expression>
</bgf:production>
</xbgf:extract>
<!-- ISSUE PERMISSIVENESS -->
<!-- ISSUE PERMISSIVENESS -->
<xbgf:narrow>
<bgf:expression>
<optional>
Expand Down Expand Up @@ -730,7 +730,7 @@
</bgf:expression>
</bgf:production>
</xbgf:add>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>VoidMethodDeclaratorRest</nonterminal>
Expand Down Expand Up @@ -782,7 +782,7 @@
</bgf:expression>
</bgf:production>
</xbgf:add>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>MethodOrFieldDecl</nonterminal>
Expand All @@ -801,7 +801,7 @@
</bgf:expression>
</bgf:production>
</xbgf:define>
<!-- BREFACTOR -->
<!-- BREFACTOR -->
<xbgf:define>
<bgf:production>
<nonterminal>MethodOrFieldRest</nonterminal>
Expand Down Expand Up @@ -1044,16 +1044,6 @@
</bgf:production>
</xbgf:inject>

<!--
Multiple cases like this one:

- Fail: ClassOrInterfaceDeclaration.
- [], ,([*(n(Modifier)), ;([n(ClassDeclaration), n(InterfaceDeclaration)])])
vs.
- [], ,([n(ModifiersOpt), ;([n(ClassDeclaration), n(InterfaceDeclaration)])])
-->
<xbgf:inline>ModifiersOpt</xbgf:inline>

<!--
- Fail: ConstructorDeclaratorRest.
- [], ,([n(FormalParameters), ?(,([t(throws), n(QualifiedIdentifierList)])), n(MethodBody)])
Expand All @@ -1072,6 +1062,7 @@
<nonterminal>ConstructorDeclaratorRest</nonterminal>
</in>
</xbgf:replace>
<xbgf:eliminate>ConstructorBody</xbgf:eliminate>

<!--
This is used by class definitions and interface definitions
Expand Down
42 changes: 42 additions & 0 deletions topics/java/lci/xbgf/refactorInterfaces-doc3.xbgf
Expand Up @@ -623,6 +623,7 @@
<to>QualifiedIdentifierList</to>
</xbgf:unite>
<xbgf:inline>Throws</xbgf:inline>
<xbgf:eliminate>ExceptionType</xbgf:eliminate>

<!--
can't match right away because one is left recursion and the other one is right
Expand Down Expand Up @@ -756,4 +757,45 @@
<xbgf:inline>SingleStaticImportDeclaration</xbgf:inline>
<xbgf:inline>StaticImportOnDemandDeclaration</xbgf:inline>

<!--
- Fail: InterfaceBodyDeclaration.
- [], ;([t((;)), ,([*(n(Modifier)), n(InterfaceMemberDecl)])])
vs.
- [], t((;))
- [], ,([n(ModifiersOpt), n(InterfaceDeclaration)])
- [], ,([n(ModifiersOpt), n(ClassDeclaration)])
- [], ,([*(n(Modifier)), ?(n(TypeParameters)), ;([n(Type), t(void)]), n(Identifier), t((), ?(n(FormalParameterList)), t()), n(BracketsOpt), ?(,([t(throws), n(QualifiedIdentifierList)])), t((;))])
-->
<!--<xbgf:unfold>
<nonterminal>ModifiersOpt</nonterminal>
<in>
<nonterminal>InterfaceBodyDeclaration</nonterminal>
</in>
</xbgf:unfold>
<xbgf:horizontal>InterfaceBodyDeclaration</xbgf:horizontal>-->
<xbgf:massage>
<bgf:expression>
<optional>
<bgf:expression>
<nonterminal>TypeParameters</nonterminal>
</bgf:expression>
</optional>
</bgf:expression>
<bgf:expression>
<choice>
<bgf:expression>
<nonterminal>TypeParameters</nonterminal>
</bgf:expression>
<bgf:expression>
<epsilon/>
</bgf:expression>
</choice>
</bgf:expression>
</xbgf:massage>
<xbgf:distribute>
<nonterminal>InterfaceBodyDeclaration</nonterminal>
</xbgf:distribute>
<xbgf:vertical>
<nonterminal>InterfaceBodyDeclaration</nonterminal>
</xbgf:vertical>
</xbgf:sequence>
53 changes: 53 additions & 0 deletions topics/presentation/analyses/bgf_check.py
@@ -0,0 +1,53 @@
#!/usr/bin/python
import os
import sys

productions = "count(/*/*[local-name()='production'])"
nonterminals = "count(/*[local-name()='grammar']/*/nonterminal[not(text()=../preceding-sibling::*/nonterminal/text())])"
top = "count(/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())])"
listtop = "/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())]"
bottom = " | (echo '<set>' ; xpath '//nonterminal[not(text()=/*/*/nonterminal/text())]' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' "
listbottom = "//nonterminal[not(text()=/*/*/nonterminal/text())]"
unique = " | (echo '<set>' ; xpath '//nonterminal' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' "

def runxpath(filename,xpathexpr):
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null')
tmp = open('TMP-res','r')
res = tmp.readline().strip()
tmp.close()
return res

def runxpathlist(filename,xpathexpr):
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null')
tmp = open('TMP-res','r')
resa = tmp.readline().strip().split('<nonterminal>')
resu = []
for x in resa:
if x not in resu:
resu.append(x)
resu.sort()
return ''.join(resu).replace('</nonterminal>',', ')[:-2]
tmp.close()
res = res.replace('<nonterminal>','').replace('</nonterminal>',', ')
return res[:-2]

def runxpath2(filename,xpathexpr):
os.system('cat '+filename+xpathexpr+' 1>TMP-res 2>/dev/null')
tmp = open('TMP-res','r')
res = tmp.readline().strip()
tmp.close()
return res

if __name__ == "__main__":
if len(sys.argv) != 2:
print 'This tool generates an overview of a bunch of BGF sources and targets.'
print 'Usage:'
print ' checkbgf <bgf>'
sys.exit(1)
print 'Productions: ',runxpath(sys.argv[1],productions)
print 'Nonterminals defined:',runxpath(sys.argv[1],nonterminals)
print '%20s:' % 'unique',runxpath2(sys.argv[1],unique)
print '%20s:' % 'bottom',runxpath2(sys.argv[1],bottom),'(',runxpathlist(sys.argv[1],listbottom),')'
print '%20s:' % 'top',runxpath(sys.argv[1],top),'(',runxpathlist(sys.argv[1],listtop),')'
sys.exit(0)

0 comments on commit 3087a55

Please sign in to comment.