Skip to content

Commit

Permalink
extracting labels from attributes
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@165 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 15, 2008
1 parent ccd923c commit e6d2268
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 28 deletions.
34 changes: 34 additions & 0 deletions topics/extraction/sdf2bgf/Main.asf
Expand Up @@ -37,6 +37,25 @@ trafoSymbols() =
<epsilon/>
</bgf:expression>

[transform-a-labelled-production]
&C1 := sort2chardata(&N1),
&E2 := trafoSymbols(&Ss1),
&C0 := guessLabel(&Acs1)
=====================
trafoProd ( &Ss1 -> &N1 {&Acs1} ) =
<bgf:production>
&C0
<nonterminal>&C1</nonterminal>
&E2
</bgf:production>

[transform-empty-definition-of-nonterminal]
trafoSymbols() =
<bgf:expression>
<epsilon/>
</bgf:expression>


[transform-definition-that-is-not-a-sequence]
trafoSymbols(&S1) = trafoSymbol(&S1)

Expand Down Expand Up @@ -99,3 +118,18 @@ trafoSymbol(&S1?) =
<bgf:expression>
<optional>&E1</optional>
</bgf:expression>

[cons-to-label-only-cons]
guessLabel(cons(&I1)) = <label>idcon2chardata(&I1)</label>

[cons-to-label-cons-etc]
guessLabel(cons(&I1),&Acs2) = <label>idcon2chardata(&I1)</label>

[cons-to-label-empty]
guessLabel() =

[default-cons-to-label-no-cons]
guessLabel(&A1) =

[default-cons-to-label-head-is-not-cons]
guessLabel(&A1,&Acs2) = guessLabel(&Acs2)
23 changes: 13 additions & 10 deletions topics/extraction/sdf2bgf/Main.sdf
Expand Up @@ -26,22 +26,25 @@ module Main
trafoSymbol(Symbol) -> Element
trafoSymbols(Symbols) -> Element
mapTrafoSymbol(Symbols) -> Content*
guessLabel({Attribute ","}*) -> Content?

variables
"&A" [0-9]+ -> Attribute
"&A" [0-9]+ -> Attribute
"&A*" [0-9]+ -> Attribute*
"&As" [0-9]+ -> Attributes
"&C" [0-9]+ -> Content
"&Acs"[0-9]+ -> {Attribute ","}*
"&C" [0-9]+ -> Content
"&C*" [0-9]+ -> Content*
"&E" [0-9]+ -> Element
%% "&E*" [0-9]+ -> Element* %% Useless because of lack of covariance
"&G" [0-9]+ -> Grammar
"&M" [0-9]+ -> Module
"&N" [0-9]+ -> Sort
"&P" [0-9]+ -> Production
"&E" [0-9]+ -> Element
%% "&E*" [0-9]+ -> Element* %% Useless because of lack of covariance
"&G" [0-9]+ -> Grammar
"&M" [0-9]+ -> Module
"&N" [0-9]+ -> Sort
"&P" [0-9]+ -> Production
"&P*" [0-9]+ -> Production*
"&Ps" [0-9]+ -> Productions
"&S" [0-9]+ -> Symbol
"&S" [0-9]+ -> Symbol
"&S*" [0-9]+ -> Symbol*
"&Ss" [0-9]+ -> Symbols
"&Z" [0-9]+ -> StrCon
"&Z" [0-9]+ -> StrCon
"&I" [0-9]+ -> IdCon
11 changes: 11 additions & 0 deletions topics/extraction/sdf2bgf/Tokens.asf
Expand Up @@ -21,3 +21,14 @@ strchar(&Chr1) := &StrChar1,
chardata(&Char1 &Chars1) := strcon2chardata(strcon(\" &StrChar+2 \"))
===========================================================
strcon2chardata(strcon(\" &StrChar1 &StrChar+2 \")) = chardata(&Chr1 &Char1 &Chars1)

[idcon-of-length-1]
idcon2chardata(idcon(&IdHead1)) = chardata(&IdHead1)

[idcon-of-length-2]
idcon2chardata(idcon(&IdHead1 &Middle1)) = chardata(&IdHead1 &Middle1)

[idcon-of-length-greater-than-2]
chardata(&Char1 &Chars1) := idcon2chardata(idcon(&IdHead1 &Middles1))
===============================================================
idcon2chardata(idcon(&IdHead1 &Middle1 &Middles1)) = chardata(&Char1 &Middle1 &Chars1)
37 changes: 19 additions & 18 deletions topics/extraction/sdf2bgf/Tokens.sdf
Expand Up @@ -4,18 +4,18 @@ imports
languages/sdf2/syntax/Sorts
languages/xml/syntax/XML
basic/StrCon
basic/IdentifierCon

exports

sorts CharData

context-free syntax
sort2chardata(Sort) -> CharData
strcon2chardata(StrCon) -> CharData
sorts
CharData
context-free syntax
sort2chardata(Sort) -> CharData
strcon2chardata(StrCon) -> CharData
idcon2chardata(IdCon) -> CharData

hiddens

lexical syntax
lexical syntax
%% Let's remind ourselves of the relevant lexical syntax.
%%
%% 1. languages/sdf2/syntax/Sorts
Expand All @@ -35,13 +35,14 @@ hiddens
%% ~[\0-\31\n\t\"\\] -> StrChar {cons("normal")}
%% [\"] chars:StrChar* [\"] -> StrCon {cons("default")}

lexical variables
"&Head" [0-9]* -> [A-Z] %% Part of Sort
"&Middle" [0-9]* -> [A-Za-z0-9\-] %% Part of Sort
"&Middles" [0-9]* -> [A-Za-z0-9\-]* %% Part of Sort
"&Last" [0-9]* -> [A-Za-z0-9] %% Part of Sort
"&Char" [0-9]* -> ~[\<\&] %% Part of CharData
"&Chars" [0-9]* -> ~[\<\&]* %% Part of CharData
"&StrChar" [0-9]* -> StrChar %% Part of StrCon
"&StrChar+" [0-9]* -> StrChar+ %% Part of StrCon
"&Chr" [0-9]* -> ~[\0-\31\n\t\"\\\<\&]
lexical variables
"&Head" [0-9]* -> [A-Z] %% Part of Sort
"&IdHead" [0-9]* -> [A-Za-z] %% Part of IdCon
"&Middle" [0-9]* -> [A-Za-z0-9\-] %% Part of Sort
"&Middles" [0-9]* -> [A-Za-z0-9\-]* %% Part of Sort
"&Last" [0-9]* -> [A-Za-z0-9] %% Part of Sort
"&Char" [0-9]* -> ~[\<\&] %% Part of CharData
"&Chars" [0-9]* -> ~[\<\&]* %% Part of CharData
"&StrChar" [0-9]* -> StrChar %% Part of StrCon
"&StrChar+" [0-9]* -> StrChar+ %% Part of StrCon
"&Chr" [0-9]* -> ~[\0-\31\n\t\"\\\<\&]

0 comments on commit e6d2268

Please sign in to comment.