Skip to content

Commit

Permalink
labelled productions; makefile treats ambiguities as ERRORS(!)
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@162 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 15, 2008
1 parent a5b8208 commit eda334c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
9 changes: 8 additions & 1 deletion topics/fl/asfsdf/Makefile
Expand Up @@ -21,9 +21,16 @@ FL.tbl: FL.sdf syntax/FL.sdf optimise/FL.sdf
fi

test:
@echo Parsing factorial:
@echo --------------------------------------------------------
@cat ${testcase}
@echo --------------------------------------------------------
@cat ${testcase} | python pre.py | sglr -p FL.tbl | asfe -e FL.eqs | restorebrackets -p FL.tbl | unparsePT | python post.py
@cat ${testcase} | python pre.py | sglr -p FL.tbl -A | unparsePT | python post.py
@echo Optimising example:
@echo --------------------------------------------------------
@cat suboptimal.fl
@echo --------------------------------------------------------
@cat suboptimal.fl | python pre.py | sglr -p FL.tbl -A | asfe -e FL.eqs | restorebrackets -p FL.tbl | unparsePT | python post.py

catbuild:
echo definition > FL.def
Expand Down
2 changes: 1 addition & 1 deletion topics/fl/asfsdf/optimise/FL.asf
Expand Up @@ -31,4 +31,4 @@ equations
===============================
if (E1 == N2) then E3 else E4 = if E1 then E4 else E3

[realplus] N1 + N2 = add-int (N1,N2)
[realplus] N1 + N2 = add-int(N1,N2)
24 changes: 12 additions & 12 deletions topics/fl/asfsdf/syntax/FL.sdf
Expand Up @@ -8,20 +8,20 @@ exports
Program Function Expr Ops Name Newline

context-free syntax
Function+ -> Program
Name Name+ "=" Expr Newline+ -> Function
Expr Ops Expr -> Expr {left} %% binary
Name Expr+ -> Expr %% apply
"if" Expr "then" Expr "else" Expr -> Expr %% ifthenelse
"(" Expr ")" -> Expr {bracket}
Name -> Expr
Int -> Expr
Function+ -> Program
Name Name+ "=" Expr Newline+ -> Function
Expr Ops Expr -> Expr {left,prefer,cons(binary)}
Name Expr+ -> Expr {avoid,cons(apply)}
"if" Expr "then" Expr "else" Expr -> Expr {cons(ifThenElse)}
"(" Expr ")" -> Expr {bracket}
Name -> Expr
Int -> Expr

context-free syntax
"-" -> Ops
"+" -> Ops
"==" -> Ops
";" -> Newline %% preprocessed
"-" -> Ops {cons(minus)}
"+" -> Ops {cons(plus)}
"==" -> Ops {cons(equal)}
";" -> Newline {cons(preprocessed)}

lexical syntax
[a-z]+ -> Name
Expand Down
28 changes: 14 additions & 14 deletions topics/fl/asfsdf/syntax/Numbers.asf
@@ -1,25 +1,25 @@
equations

[a] toInt ( N1 ) = N1
[a] toInt(&N1) = &N1

[b] toInt ( -N1 ) = -N1
[b] toInt ( -&N1 ) = -&N1

[1] H1 := N1 + N2,
I1 := toInt ( H1 )
[1] &H1 := &N1 + &N2,
&I1 := toInt ( &H1 )
=======================
add-int ( N1, N2 ) = I1
add-int ( &N1, &N2 ) = &I1

[2] H1 := N2 - N1,
I1 := toInt ( H1 )
[2] &H1 := &N2 - &N1,
&I1 := toInt ( &H1 )
=======================
add-int ( -N1, N2 ) = I1
add-int ( -&N1, &N2 ) = &I1

[3] H1 := N1 - N2,
I1 := toInt ( H1 )
[3] &H1 := &N1 - &N2,
&I1 := toInt ( &H1 )
=======================
add-int ( N1, -N2 ) = I1
add-int ( &N1, -&N2 ) = &I1

[4] H1 := - (N1 + N2),
I1 := toInt ( H1 )
[4] &H1 := - (&N1 + &N2),
&I1 := toInt ( &H1 )
=======================
add-int ( -N1, -N2 ) = I1
add-int ( -&N1, -&N2 ) = &I1
12 changes: 6 additions & 6 deletions topics/fl/asfsdf/syntax/Numbers.sdf
Expand Up @@ -8,16 +8,16 @@ exports
Int

context-free syntax
"-"? NatCon -> Int
"add-int" "(" Int "," Int ")" -> Int
add-int(Int,Int) -> Int
"-"? NatCon -> Int

hiddens
context-free start-symbols Int

context-free syntax
"toInt" "(" Integer ")" -> Int
toInt(Integer) -> Int

variables
"N" [0-9]* -> NatCon
"I" [0-9]* -> Int
"H" [0-9]* -> Integer
"&N" [0-9]* -> NatCon
"&I" [0-9]* -> Int
"&H" [0-9]* -> Integer

0 comments on commit eda334c

Please sign in to comment.