Skip to content

Commit

Permalink
FL is Rascal: now with abstract syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jun 12, 2012
1 parent a8bb16a commit 35847a7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
4 changes: 4 additions & 0 deletions topics/fl/rascal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build:

test:
cd src && java -Xmx1G -Xss32m -jar ../../../../download/rascal.jar FL ../../shared/factorial.txt
13 changes: 13 additions & 0 deletions topics/fl/rascal/src/Abstract.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module Abstract

data FLPrg = prg(list[FLFun]);
data FLFun = fun(str f, list[str] args, FLExpr body);
data FLExpr
= binary(FLExpr e1, FLOp op, FLExpr e2)
| apply(str f, list[FLExpr] vargs)
| ifThenElse(FLExpr c, FLExpr t, FLExpr e)
| argument(str a)
| literal(int i)
;
data FLOp = minus() | plus() | equal();
41 changes: 14 additions & 27 deletions topics/fl/rascal/src/Concrete.rsc
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module Concrete

import IO;
import ParseTree;

syntax Program = Function+ LO;
syntax Function = Name Name+ "=" Expr Newline ;
syntax Expr =
binary: Expr Ops Expr
syntax Program = prg: {Function "\n"}+ "\n"*;
syntax Function = fun: Name Name+ "=" Expr ;
syntax Expr
= binary: Expr Ops Expr
| apply: Name Expr+
| ifThenElse: "if" Expr "then" Expr "else" Expr
| "(" Expr ")"
| bracket "(" Expr ")"
| argument: Name
| literal: Int ;
syntax Ops =
minus: "-"
| literal: Int
;
syntax Ops
= minus: "-"
| plus: "+"
| equal: "==" ;
| equal: "=="
;

lexical Name = [a-z]+ !>> [a-z] ;
lexical Int = [0] | [1-9][0-9]* !>> [0-9] ;
lexical Newline = "\n" ;
layout LO = [\ \t]* ;

public void main(list[str] args)
{
loc src = |cwd:///|+args[0];
do(src);
}

public void main() = do(|home:///projects/slps/topics/fl/shared/factorial.txt|);

void do(loc src)
{
parse(#Program,src);
println("Done.");
}
layout LO = [\ \t]* !>> [\ \t];
keyword FLKwd = "if" | "then" | "else" ;
24 changes: 24 additions & 0 deletions topics/fl/rascal/src/FL.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module FL

import Concrete;
import Abstract;
import IO;
import ParseTree;

public void main(list[str] args)
{
loc src = |cwd:///|+args[0];
do(src);
}

public void main() = do(|home:///projects/slps/topics/fl/shared/factorial.txt|);

void do(loc src)
{
println("The Factorial Language: Rascal implementation.");
c = parse(#Program,src);
println("Parsing: done.");
a = implode(#FLPrg,c);
println("Imploding: done.");
}
4 changes: 0 additions & 4 deletions topics/fl/rascal1/Makefile

This file was deleted.

0 comments on commit 35847a7

Please sign in to comment.