Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
AsFix->BTF extractor, work in progress
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@181 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 19, 2008
1 parent 8b69e8f commit c05f53f
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 0 deletions.
91 changes: 91 additions & 0 deletions topics/extraction/asfix2btf/AsFixTokens.asf
@@ -0,0 +1,91 @@
equations

[final-1]
strchar(&Chr1) := mapsymbol(&N1)
========================================
tree2chardata([&N1]) = chardata(&Chr1)

[one]
strchar(&Chr1) := mapsymbol(&N1),
chardata(&Char1 &Char*1) := tree2chardata([&T*2])
==============================================
tree2chardata([&N1,&T*2]) = chardata ( &Chr1 &Char1 &Char*1 )




[zero]
strchar(&Chr1) := mapsymbol(&N1)
========================================
list2chardata([&N1]) = chardata(&Chr1)

[one]
strchar(&Chr1) := mapsymbol(&N1),
chardata(&Char1 &Char*1) := list2chardata([&N*2])
==============================================
list2chardata([&N1,&N*2]) = chardata ( &Chr1 &Char1 &Char*1 )

[one]
symbols2chardata([&N1]) = [mapsymbol(&N1)]

[one]
&C1 := mapsymbol(&N1),
[&C*2] := symbols2chardata([&N*2])
===============================================
symbols2chardata([&N1,&N*2]) = [&C1,&C*2]

[strcon-of-length-1]
array2chardata([&StrChr1]) = strcon(\" &StrChr1 \")

[strcon-of-length-1]
strcon(\" &StrChr+1 \" ):= array2chardata([&C*2])
====================================================
array2chardata([&StrChr1,&C*2]) = strcon(\" &StrChr1 &StrChr+1 \")

[strcon-of-length-1]
strchar(&Chr1) := &StrChr1
========================================
array2chars([&StrChr1]) = chardata(&Chr1)

[strcon-of-length-1]
strchar(&Chr1) := &StrChr1,
chardata(&Char1 &Char*1) := array2chars([&C*2])
====================================================
array2chars([&StrChr1,&C*2]) = chardata ( &Chr1 &Char1 &Char*1 )

[alpha-a] mapsymbol(97) = a
[alpha-b] mapsymbol(98) = b
[alpha-c] mapsymbol(99) = c
[alpha-d] mapsymbol(100) = d
[alpha-e] mapsymbol(101) = e
[alpha-f] mapsymbol(102) = f
[alpha-g] mapsymbol(103) = g
[alpha-h] mapsymbol(104) = h
[alpha-i] mapsymbol(105) = i
[alpha-j] mapsymbol(106) = j
[alpha-k] mapsymbol(107) = k
[alpha-l] mapsymbol(108) = l
[alpha-m] mapsymbol(109) = m
[alpha-n] mapsymbol(110) = n
[alpha-o] mapsymbol(111) = o
[alpha-p] mapsymbol(112) = p
[alpha-q] mapsymbol(113) = q
[alpha-r] mapsymbol(114) = r
[alpha-s] mapsymbol(115) = s
[alpha-t] mapsymbol(116) = t
[alpha-u] mapsymbol(117) = u
[alpha-v] mapsymbol(118) = v
[alpha-w] mapsymbol(119) = w
[alpha-x] mapsymbol(120) = x
[alpha-y] mapsymbol(121) = y
[alpha-z] mapsymbol(122) = z
[digit-0] mapsymbol(48) = 0
[digit-1] mapsymbol(49) = 1
[digit-2] mapsymbol(50) = 2
[digit-3] mapsymbol(51) = 3
[digit-4] mapsymbol(52) = 4
[digit-5] mapsymbol(53) = 5
[digit-6] mapsymbol(54) = 6
[digit-7] mapsymbol(55) = 7
[digit-8] mapsymbol(56) = 8
[digit-9] mapsymbol(57) = 9
50 changes: 50 additions & 0 deletions topics/extraction/asfix2btf/AsFixTokens.sdf
@@ -0,0 +1,50 @@
module AsFixTokens

%% mapTree(appl(prod([lex(iter(char-class([range(97,122)])))],lex(sort("NAME")),no-attrs),[appl(list(lex(iter(char-class([range(97,122)])))),[102,117,110])]))
%% [97,122] -> a,z
%% [102,117,110] -> fun

imports
languages/asfix/syntax/Tree
languages/xml/syntax/XML
basic/StrCon
basic/NatCon

exports

sorts
CharNumList CharValList StrCon CharData
context-free start-symbols
CharNumList CharValList
context-free syntax
"[" {NatCon ","}+ "]" -> CharNumList
"[" {StrChar ","}+ "]" -> CharValList
"symbols2chardata" "(" CharNumList ")" -> CharValList
"mapsymbol" "(" NatCon ")" -> StrChar
array2chardata(CharValList) -> StrCon
array2chars(CharValList) -> CharData
list2chardata(CharNumList) -> CharData
tree2chardata(Args) -> CharData

hiddens
%% imports
%%basic/Whitespace
variables
"&N" [0-9]+ -> NatCon %% char number
"&N*" [0-9]+ -> {NatCon ","}+ %% char number
"&C" [0-9]+ -> StrChar
"&C*" [0-9]+ -> {StrChar ","}+
"&T" [0-9]+ -> Tree
"&T*" [0-9]+ -> {Tree ","}+
lexical variables
"&StrChr" [0-9]+ -> StrChar
"&StrChr+" [0-9]+ -> StrChar+
"&Chr" [0-9]* -> ~[\0-\31\n\t\"\\\<\&]
"&Char" [0-9]* -> ~[\<\&]
"&Char*" [0-9]* -> ~[\<\&]*

%% "&S" [0-9]+ -> Symbol

%% Python code to generate the boring part of the ASF:
%% for x in range(97,123):
%% print '['+chr(x)+']','mapsymbol('+`x`+')','=',chr(x)
252 changes: 252 additions & 0 deletions topics/extraction/asfix2btf/Main.asf
@@ -0,0 +1,252 @@
equations

[map-asfix-to-btf]
main(parsetree(&T1,&I1))
=
mapTree(&T1)

[kill-layout-before]
mapTree(appl(prod([cf(opt(layout)),&Scs1],&S0,&As1),[&T1,&Tcs1]))
=
mapTree(appl(prod([&Scs1],&S0,&As1),[&Tcs1]))

[kill-layout-after]
mapTree(appl(prod([&Scs1,cf(opt(layout))],&S0,&As1),[&Tcs1,&T1]))
=
mapTree(appl(prod([&Scs1],&S0,&As1),[&Tcs1]))

[map-start-symbol]
mapTree(appl(prod([&S1],sort("<START>"),&As1),[&T1]))
=
mapTree(&T1)
%%<btf:tree xmlns:btf="http://planet-sl.org/btf" xmlns:bgf="http://planet-sl.org/bgf">

[default-map-one-prod]
mapTree(appl(prod([cf(&S1)],&S0,&As1),[&T1]))
=
<btf:tree>
<nonterminal>
<bgf:production>
symbol2content(&S0)
mapExpr(&S1)
</bgf:production>
mapTree(&T1)
</nonterminal>
</btf:tree>

[default-map-one-list]
mapTree(appl(list(cf(iter(sort(&Z1)))),[&Tcs1]))
=
<btf:tree>
<plus>
mapTrees2Trees([&Tcs1])
</plus>
</btf:tree>

[default-map-more-cf]
mapTree(appl(prod([cf(&S1), &Scs2],&S0,&As1),[&T1, &Tcs2]))
=
<btf:tree>
<nonterminal>
<bgf:production>
symbol2content(&S0)
<bgf:expression>
<sequence>
mapExpr(&S1)
mapExprs([&Scs2])
</sequence>
</bgf:expression>
</bgf:production>
<btf:tree>
<sequence>
mapTree(&T1)
mapTrees2Trees([&Tcs2])
</sequence>
</btf:tree>
</nonterminal>
</btf:tree>

%% attributes contains cons(bla), need to recover !
[default-map-more-lit]
mapTree(appl(prod([lit(&Z1), &Scs2],&S0,&As1),[&T1, &Tcs2]))
=
<btf:tree>
<nonterminal>
<bgf:production>
symbol2content(&S0)
<bgf:expression>
<sequence>
<bgf:expression><terminal>strcon2chardata(&Z1)</terminal></bgf:expression>
mapExprs([&Scs2])
</sequence>
</bgf:expression>
</bgf:production>
<btf:tree>
<sequence>
<btf:tree><terminal>strcon2chardata(&Z1)</terminal></btf:tree>
mapTrees2Trees([&Tcs2])
</sequence>
</btf:tree>
</nonterminal>
</btf:tree>

%%[map-plus-iteration]
%%mapTree(appl(list(cf(iter(sort("Function")))),[&Tcs1]))
%%=
%%<btf:tree>
%%</btf:tree>


[map-plus-in-production]
mapExpr(iter(&S1))
=
<bgf:expression>
<plus>
<bgf:expression>
symbol2content(&S1)
</bgf:expression>
</plus>
</bgf:expression>

[map-nonterm-in-production]
mapExpr(sort(&Z1))
=
<bgf:expression>
<nonterminal>strcon2chardata(&Z1)</nonterminal>
</bgf:expression>

[dont-care-if-context-free]
mapExpr(cf(&S1)) = mapExpr(&S1)

[dont-care-if-lexical]
mapExpr(lex(&S1)) = mapExpr(&S1)

[s2c1]
symbol2content(cf(&S1)) = symbol2content(&S1)

[s2c2]
&C1 := strcon2chardata(&Z1)
===================================
symbol2content(sort(&Z1)) = <nonterminal>&C1</nonterminal>

%%[map-plus-in-tree]
%%mapTree(appl(list(cf(iter(&S1))),[&T1]))
%%=
%%<btf:tree>
%% <plus>
%% mapTree(&T1)
%% </plus>
%%</btf:tree>

[recursive-expr-1]
mapExprs([&S1]) = mapExpr(&S1)

[recursive-expr-2]
mapExprs([cf(opt(layout)),&Scs2]) = mapExprs([&Scs2])

[default-recursive-expr-2]
mapExprs([&S1,&Scs2]) = mapExpr(&S1)mapExprs([&Scs2])

[map-literal-to-terminal]
mapExpr(lit(&Z1))
=
<bgf:expression>
<terminal>strcon2chardata(&Z1)</terminal>
</bgf:expression>

[map-optional-to-expr]
mapExpr(opt(&S1))
=
<bgf:expression>
<optional>
mapExpr(&S1)
</optional>
</bgf:expression>


[map-literal-to-tree]
mapTree(appl(prod(&Ss1,lit(&Z1),&As1),[&Tcs1]))
=
<btf:tree>
<terminal>
strcon2chardata(&Z1)
</terminal>
</btf:tree>

[map-literal-production-to-tree]
mapTree(appl(prod([lit(&Z1)],cf(sort(&Z0)),&As1),[&T1]))
=
<btf:tree>
<nonterminal>
<bgf:production>
<nonterminal>strcon2chardata(&Z0)</nonterminal>
<bgf:expression>
<terminal>strcon2chardata(&Z1)</terminal>
</bgf:expression>
</bgf:production>
<btf:tree>
<terminal>strcon2chardata(&Z1)</terminal>
</btf:tree>
</nonterminal>
</btf:tree>

[map-optional-to-tree]
mapTree(appl(prod([&Scs1],cf(opt(&S1)),&As1),[&Tcs1]))
=
<btf:tree>
<optional>
mapTree(appl(prod([&Scs1],&S1,&As1),[&Tcs1]))
</optional>
</btf:tree>

[map-empty-optional-to-tree]
mapTree(appl(prod([],cf(opt(&S1)),&As1),[]))
=
<btf:tree>
<optional>
</optional>
</btf:tree>

[map-literal-nonterminals-to-tree]
mapTree(appl(prod([lex(sort(&Z0))],cf(sort(&Z0)),&As1),[&T1]))
=
<btf:tree>
<nonterminal>
<bgf:production>
<nonterminal>strcon2chardata(&Z0)</nonterminal>
<bgf:expression>
<terminal>
mapTree(&T1)
</terminal>
</bgf:expression>
</bgf:production>
<btf:tree>
<terminal>mapTree(&T1)</terminal>
</btf:tree>
</nonterminal>
</btf:tree>

[recursive-tree-empty]
mapTrees2Trees([]) =

[recursive-tree-1]
mapTrees2Trees([&T1]) = mapTree(&T1)

[recursive-tree-no-layout]
mapTrees2Trees([appl(prod([&Scs1],cf(opt(layout)),&As1),[&Tcs1]),&Tcs2]) = mapTrees2Trees([&Tcs2])

[default-recursive-tree-2]
mapTrees2Trees([&T1,&Tcs2]) = mapTree(&T1)mapTrees2Trees([&Tcs2])

[wip]
mapTree(appl(prod(&Ss1,lex(&S1),&As1),[appl(list(lex(&S2)),[&Tcs1])]))
=
tree2chardata([&Tcs1])

[terrible]
mapExprs([]) =

[map-lex-literal]
mapTree(appl(prod([lit(&Z1)],lex(&S1),&As1),[&Tcs1]))
=
strcon2chardata(&Z1)

0 comments on commit c05f53f

Please sign in to comment.