From eda334c452acb32615d417ecf56b1dae6ebffae7 Mon Sep 17 00:00:00 2001 From: grammarware Date: Fri, 15 Aug 2008 15:58:30 +0000 Subject: [PATCH] labelled productions; makefile treats ambiguities as ERRORS(!) git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@162 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- topics/fl/asfsdf/Makefile | 9 ++++++++- topics/fl/asfsdf/optimise/FL.asf | 2 +- topics/fl/asfsdf/syntax/FL.sdf | 24 ++++++++++++------------ topics/fl/asfsdf/syntax/Numbers.asf | 28 ++++++++++++++-------------- topics/fl/asfsdf/syntax/Numbers.sdf | 12 ++++++------ 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/topics/fl/asfsdf/Makefile b/topics/fl/asfsdf/Makefile index 75067f84..3ea999ea 100644 --- a/topics/fl/asfsdf/Makefile +++ b/topics/fl/asfsdf/Makefile @@ -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 diff --git a/topics/fl/asfsdf/optimise/FL.asf b/topics/fl/asfsdf/optimise/FL.asf index e1ec42e8..4d23092c 100644 --- a/topics/fl/asfsdf/optimise/FL.asf +++ b/topics/fl/asfsdf/optimise/FL.asf @@ -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) \ No newline at end of file + [realplus] N1 + N2 = add-int(N1,N2) diff --git a/topics/fl/asfsdf/syntax/FL.sdf b/topics/fl/asfsdf/syntax/FL.sdf index d2415caa..964fff67 100644 --- a/topics/fl/asfsdf/syntax/FL.sdf +++ b/topics/fl/asfsdf/syntax/FL.sdf @@ -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 diff --git a/topics/fl/asfsdf/syntax/Numbers.asf b/topics/fl/asfsdf/syntax/Numbers.asf index 261f9be6..13510a28 100644 --- a/topics/fl/asfsdf/syntax/Numbers.asf +++ b/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 \ No newline at end of file + add-int ( -&N1, -&N2 ) = &I1 diff --git a/topics/fl/asfsdf/syntax/Numbers.sdf b/topics/fl/asfsdf/syntax/Numbers.sdf index 5bca1969..857fd355 100644 --- a/topics/fl/asfsdf/syntax/Numbers.sdf +++ b/topics/fl/asfsdf/syntax/Numbers.sdf @@ -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