Skip to content

Commit

Permalink
TXL parser for FL
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@657 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Jul 6, 2009
1 parent 006a690 commit 901f622
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
67 changes: 67 additions & 0 deletions topics/fl/txl/FL.Txl
@@ -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

3 changes: 3 additions & 0 deletions topics/fl/txl/Makefile
@@ -0,0 +1,3 @@
test:
cp ../shared/factorial.txt factorial.fl
txl -newline factorial.fl

0 comments on commit 901f622

Please sign in to comment.