Skip to content

Commit

Permalink
preprocessor & postprocessor
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@110 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 1, 2008
1 parent 1be9b6c commit a53ceff
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
Binary file modified topics/fl/asfsdf/FL.eqs
Binary file not shown.
3 changes: 1 addition & 2 deletions topics/fl/asfsdf/FL.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ exports
context-free start-symbols
PROGRAM
sorts
PROGRAM NEWLINE

PROGRAM

Binary file modified topics/fl/asfsdf/FL.tbl
Binary file not shown.
10 changes: 5 additions & 5 deletions topics/fl/asfsdf/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
metaenv = ~/Tools/Meta
metaenv = `which sdf2table | xargs dirname`/../share

all:
make build
make test

test:
cat suboptimal.trm
sglr -p FL.tbl -i suboptimal.trm | asfe -e FL.eqs | unparsePT
cat suboptimal.fl
cat suboptimal.fl | python pre.py | sglr -p FL.tbl | asfe -e FL.eqs | restorebrackets -p FL.tbl | unparsePT | python post.py

build:
echo definition > FL.def
cat *.sdf syntax/*.sdf optimise/*.sdf >> FL.def
cat ${metaenv}/share/sdf-library/library/basic/*.sdf >> FL.def
cat ${metaenv}/share/asf-library/library/basic/*.sdf >> FL.def
cat ${metaenv}/sdf-library/library/basic/*.sdf >> FL.def
cat ${metaenv}/asf-library/library/basic/*.sdf >> FL.def
sdf2table -m FL FL.def

clean:
Expand Down
6 changes: 3 additions & 3 deletions topics/fl/asfsdf/optimise/FL.sdf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module optimise/FL

imports syntax/FL

hiddens
imports basic/Whitespace
context-free start-symbols PROGRAM

variables
"N"[0-9]* -> FL-INT
"E"[0-9]* -> EXPR
Expand All @@ -13,4 +13,4 @@ hiddens
"Fun*" -> FUNCTION*
"Fun" -> FUNCTION
"Program" -> PROGRAM


4 changes: 4 additions & 0 deletions topics/fl/asfsdf/post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/python
import sys
for line in sys.stdin:
print line.strip().split(';')[0]
5 changes: 5 additions & 0 deletions topics/fl/asfsdf/pre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/python
import sys
for line in sys.stdin:
if line.strip():
print line.strip(),';'
8 changes: 8 additions & 0 deletions topics/fl/asfsdf/suboptimal.fl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fun x = if (0 == 1) then 42 else (43 + 45)
fdu y = 0 + 1 + 0 + 5 + 0 - 0
fte z = if z then (2 + 3) else (2+3)
fqu a = if (a==0) then (0+5) else (7 - 0)
fse b = (b + 2) == (b + 2)
mult n m = if (n==0) then 0 else (m + (mult (n - 1) m))
fac n = if (n==0) then 1 else (mult n (fac (n - 1)))

5 changes: 0 additions & 5 deletions topics/fl/asfsdf/suboptimal.trm

This file was deleted.

11 changes: 4 additions & 7 deletions topics/fl/asfsdf/syntax/FL.sdf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module syntax/FL

imports syntax/Numbers
imports basic/Whitespace

exports
sorts
PROGRAM FUNCTION EXPR OPS NAME
PROGRAM FUNCTION EXPR OPS NAME NEWLINE

context-free syntax
FUNCTION+ -> PROGRAM
NAME NAME+ "=" EXPR NEWLINE+ -> FUNCTION
NAME NAME+ "=" EXPR NEWLINE -> FUNCTION
EXPR OPS EXPR -> EXPR {left} %% binary
NAME EXPR+ -> EXPR %% apply
"if" EXPR "then" EXPR "else" EXPR -> EXPR %% ifthenelse
Expand All @@ -20,6 +21,7 @@ exports
"-" -> OPS
"+" -> OPS
"==" -> OPS
";" -> NEWLINE %% preprocessed

lexical syntax
[a-z]+ -> NAME
Expand All @@ -31,8 +33,3 @@ exports
hiddens
context-free start-symbols
PROGRAM
sorts
NEWLINE
lexical syntax
[\ \t] -> LAYOUT
[\n] -> NEWLINE
4 changes: 1 addition & 3 deletions topics/fl/asfsdf/syntax/Numbers.sdf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module syntax/Numbers

imports basic/Integers
imports basic/Whitespace

exports
sorts
Expand All @@ -11,9 +12,6 @@ context-free syntax
"add-int" "(" FL-INT "," FL-INT ")" -> FL-INT

hiddens

imports basic/Whitespace

context-free start-symbols FL-INT

context-free syntax
Expand Down

0 comments on commit a53ceff

Please sign in to comment.