forked from GitHub/gf-core
cleaned up gfcc ; added gfcc script
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
-- # -path=.:prelude
|
||||
--# -path=.:../../lib/prelude
|
||||
|
||||
-- Toy English phrasing of C programs. Intended use is with
|
||||
-- speech synthesis. Printed code should use HTML formatting.
|
||||
-- AR 5/10/2005.
|
||||
|
||||
concrete ImperEng of Imper = open Prelude, ResImperEng in {
|
||||
flags lexer=textvars ; unlexer=text ; startcat=Program ;
|
||||
|
||||
lincat
|
||||
Rec = {s,s2,s3 : Str} ;
|
||||
|
||||
lin
|
||||
Empty = ss [] ;
|
||||
FunctNil val stm cont = ss (
|
||||
["The function"] ++ cont.$0 ++
|
||||
"returns" ++ indef ++ val.s ++ "." ++
|
||||
["It is defined as follows :"] ++
|
||||
stm.s ++
|
||||
PARA ++
|
||||
cont.s) ;
|
||||
Funct args val rec = ss (
|
||||
["The function"] ++ rec.$0 ++
|
||||
"takes" ++ rec.s2 ++
|
||||
"and" ++ "returns" ++ indef ++ val.s ++ "." ++
|
||||
["It is defined as follows:"] ++
|
||||
rec.s ++
|
||||
PARA ++
|
||||
rec.s3) ;
|
||||
|
||||
RecOne typ stm prg = stm ** {
|
||||
s2 = indef ++ typ.s ++ stm.$0 ;
|
||||
s3 = prg.s
|
||||
} ;
|
||||
RecCons typ _ body prg = {
|
||||
s = body.s ;
|
||||
s2 = indef ++ typ.s ++ body.$0 ++ "and" ++ body.s2 ;
|
||||
s3 = prg.s
|
||||
} ;
|
||||
|
||||
Decl typ cont = continues ("let" ++ cont.$0 ++ "be" ++ indef ++ typ.s) cont ;
|
||||
Assign _ x exp = continues ("set" ++ x.s ++ "to" ++ exp.s) ;
|
||||
While exp loop = continues (["if"] ++ exp.s ++
|
||||
[", do the following :"] ++ loop.s ++
|
||||
["test the condition and repeat the loop if the condition holds"]) ;
|
||||
IfElse exp t f = continue ("if" ++ exp.s ++ [", then"] ++ t.s ++ "Else" ++ f.s) ;
|
||||
Block stm = continue (stm.s) ;
|
||||
Printf t e = continues ("print" ++ e.s) ;
|
||||
Return _ exp = statement ("return" ++ exp.s) ;
|
||||
Returnv = statement ["return from the function"] ;
|
||||
End = ss [] ;
|
||||
|
||||
EVar _ x = constant x.s ;
|
||||
EInt n = constant n.s ;
|
||||
EFloat a b = constant (a.s ++ "." ++ b.s) ;
|
||||
EMul _ _ = prefix "product" ;
|
||||
EAdd _ _ = prefix "sum" ;
|
||||
ESub _ _ x y = ss (["the subtraction of"] ++ y.s ++ "from" ++ x.s) ;
|
||||
ELt _ _ = comparison "smaller" ;
|
||||
|
||||
EAppNil val f = constant f.s ;
|
||||
EApp args val f exps = constant (f.s ++ ["applied to"] ++ exps.s) ;
|
||||
|
||||
TInt = {s = "integer"} ;
|
||||
TFloat = {s = "float"} ;
|
||||
NilTyp = ss [] ;
|
||||
ConsTyp = cc2 ;
|
||||
OneExp _ e = e ;
|
||||
ConsExp _ _ e es = ss (e.s ++ "and" ++ es.s) ;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
module JVM where
|
||||
|
||||
mkJVM :: String -> String
|
||||
mkJVM = unlines . reverse . fst . foldl trans ([],([],0)) . lines where
|
||||
trans (code,(env,v)) s = case words s of
|
||||
".method":f:ns -> ((".method " ++ f ++ concat ns):code,([],0))
|
||||
"alloc":t:x:_ -> (code, ((x,v):env, v + size t))
|
||||
".limit":"locals":ns -> chCode (".limit locals " ++ show (length ns - 1))
|
||||
t:"_load" :x:_ -> chCode (t ++ "load " ++ look x)
|
||||
t:"_store":x:_ -> chCode (t ++ "store " ++ look x)
|
||||
t:"_return":_ -> chCode (t ++ "return")
|
||||
"goto":ns -> chCode ("goto " ++ concat ns)
|
||||
"ifzero":ns -> chCode ("ifzero " ++ concat ns)
|
||||
_ -> chCode s
|
||||
where
|
||||
chCode c = (c:code,(env,v))
|
||||
look x = maybe (x ++ show env) show $ lookup x env
|
||||
size t = case t of
|
||||
"d" -> 2
|
||||
_ -> 1
|
||||
@@ -1,16 +0,0 @@
|
||||
resource ResImperEng = open Predef, Prelude in {
|
||||
|
||||
oper
|
||||
indef = pre {"a" ;
|
||||
"an" / strs {"a" ; "e" ; "i" ; "o" ; "A" ; "E" ; "I" ; "O" }} ;
|
||||
|
||||
constant : Str -> SS = ss ;
|
||||
prefix : Str -> SS -> SS -> SS = \f,x,y ->
|
||||
ss ("the" ++ f ++ "of" ++ x.s ++ "and" ++ y.s) ;
|
||||
comparison : Str -> SS -> SS -> SS = \f,x,y ->
|
||||
ss (x.s ++ "is" ++ f ++ "than" ++ y.s) ;
|
||||
continues : Str -> SS -> SS = \s,t -> ss (s ++ "." ++ t.s) ;
|
||||
continue : Str -> SS -> SS = \s,t -> ss (s ++ t.s) ;
|
||||
statement : Str -> SS = \s -> ss (s ++ ".");
|
||||
|
||||
}
|
||||
2
examples/gfcc/gfcc
Normal file
2
examples/gfcc/gfcc
Normal file
@@ -0,0 +1,2 @@
|
||||
echo "rf -file=$1 | ps -lexcode | p | pt -number=1 | l -lang=ImperJVM | wf -file=tmp.gfcc" | gf Imper.pgf
|
||||
runghc CleanJVM tmp.gfcc $1
|
||||
Reference in New Issue
Block a user