Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@657 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
006a690
commit 901f622
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
% Calculator.Txl - simple numerical expression evaluator | ||
|
||
% Part I. Syntax specification | ||
define program | ||
[fun+] | ||
end define | ||
|
||
define fun | ||
[id] [id+] = [expression] [newline] | ||
end define | ||
|
||
define expression | ||
[expression] [op] [expression] | ||
| [id] [expression+] | ||
| if [expression] then [expression] else [expression] | ||
| [expression] == [expression] | ||
| [primary] | ||
end define | ||
|
||
define op | ||
+ | ||
| - | ||
| == | ||
end define | ||
|
||
define primary | ||
[number] | ||
| [id] | ||
| ( [expression] ) | ||
end define | ||
|
||
|
||
% Part 2. Transformation rules | ||
rule main | ||
replace [expression] | ||
E [expression] | ||
construct NewE [expression] | ||
E [resolveAddition] | ||
[resolveSubtraction] | ||
[resolveBracketedExpressions] | ||
where not | ||
NewE [= E] | ||
by | ||
NewE | ||
end rule | ||
|
||
rule resolveAddition | ||
replace [expression] | ||
N1 [number] + N2 [number] | ||
by | ||
N1 [+ N2] | ||
end rule | ||
|
||
rule resolveSubtraction | ||
replace [expression] | ||
N1 [number] - N2 [number] | ||
by | ||
N1 [- N2] | ||
end rule | ||
|
||
rule resolveBracketedExpressions | ||
replace [primary] | ||
( N [number] ) | ||
by | ||
N | ||
end rule | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test: | ||
cp ../shared/factorial.txt factorial.fl | ||
txl -newline factorial.fl |