Skip to content

Commit

Permalink
quick Rascal implementation of FL, just the parser
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1160 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 1, 2012
1 parent 5ca8708 commit a5dd4fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions topics/fl/rascal1/FL.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module FL

import IO;
import ParseTree;

syntax Program = Function+ LO;
syntax Function = Name Name+ "=" Expr ";" ;
syntax Expr =
binary: Expr Ops Expr
| apply: Name Expr+
| ifThenElse: "if" Expr "then" Expr "else" Expr
| "(" Expr ")"
| argument: Name
| literal: Int ;
lexical Ops =
minus: "-"
| plus: "+"
| equal: "==" ;
lexical Name = [a-z]+ !>> [a-z] ;
lexical Int = [0] | [1-9][0-9]* !>> [0-9] ;
layout LO = [\ \t\n\r]? ;

public void main(list[str] args)
{
loc src = |cwd:///|+args[0];
parse(#Program,src);
println("Done.");
}

4 changes: 4 additions & 0 deletions topics/fl/rascal1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build:

test:
java -jar ../../../download/rascal.jar FL.rsc factorial.txt
2 changes: 2 additions & 0 deletions topics/fl/rascal1/factorial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)));

0 comments on commit a5dd4fe

Please sign in to comment.