summaryrefslogtreecommitdiff
path: root/examples/gfcc/ResImper.gf
diff options
context:
space:
mode:
authoraarne <unknown>2004-09-19 20:27:01 +0000
committeraarne <unknown>2004-09-19 20:27:01 +0000
commitdf4cbb482f0546b884eb210d825c794d14f82712 (patch)
treecc8ecc187cdd2ce07926308ee1656a1fa3a213b7 /examples/gfcc/ResImper.gf
parent3a1f403a0146f4717b210373167640a07f0248dd (diff)
report
Diffstat (limited to 'examples/gfcc/ResImper.gf')
-rw-r--r--examples/gfcc/ResImper.gf68
1 files changed, 52 insertions, 16 deletions
diff --git a/examples/gfcc/ResImper.gf b/examples/gfcc/ResImper.gf
index 8cdd4f8b7..a72aaf8c2 100644
--- a/examples/gfcc/ResImper.gf
+++ b/examples/gfcc/ResImper.gf
@@ -1,16 +1,46 @@
-resource ResImper = open Prelude, Precedence in {
+resource ResImper = {
+ -- precedence
+
+ param
+ Prec = P0 | P1 | P2 | P3 ;
oper
- PrecExp : Type = {s : PrecTerm} ;
- continue : Str -> SS -> SS = \s -> infixSS ";" (ss s);
- statement : Str -> SS = \s -> postfixSS ";" (ss s);
- ex : PrecExp -> Str = \exp -> exp.s ! p0 ;
- infixL : Prec -> Str -> PrecExp -> PrecExp -> PrecExp =
- \p,h,x,y -> {s = mkInfixL h p x.s y.s} ;
- infixN : Prec -> Str -> PrecExp -> PrecExp -> PrecExp =
- \p,h,x,y -> {s = mkInfix h p x.s y.s} ;
+ PrecExp : Type = {s : Prec => Str} ;
+ ex : PrecExp -> Str = \exp -> exp.s ! P0 ;
+ constant : Str -> PrecExp = \c -> {s = \\_ => c} ;
+ infixN : Prec -> Str -> PrecExp -> PrecExp -> PrecExp = \p,f,x,y ->
+ {s = \\k => mkPrec (x.s ! (nextPrec ! p) ++ f ++ y.s ! (nextPrec ! p)) ! p ! k} ;
+ infixL : Prec -> Str -> PrecExp -> PrecExp -> PrecExp = \p,f,x,y ->
+ {s = mkPrec (x.s ! p ++ f ++ y.s ! (nextPrec ! p)) ! p} ;
+
+ nextPrec : Prec => Prec = table {P0 => P1 ; P1 => P2 ; _ => P3} ;
+ mkPrec : Str -> Prec => Prec => Str = \str -> table {
+ P3 => table { -- use the term of precedence P3...
+ _ => str} ; -- ...always without parentheses
+ P2 => table { -- use the term of precedence P2...
+ P3 => paren str ; -- ...in parentheses if P3 is expected...
+ _ => str} ; -- ...otherwise without parentheses
+ P1 => table {
+ P3 | P2 => paren str ;
+ _ => str} ;
+ P0 => table {
+ P0 => str ;
+ _ => paren str}
+ } ;
+
+ -- string operations
- constant : Str -> PrecExp = \c -> {s = mkConst c} ;
+ SS : Type = {s : Str} ;
+ ss : Str -> SS = \s -> {s = s} ;
+ cc2 : (_,_ : SS) -> SS = \x,y -> ss (x.s ++ y.s) ;
+
+ paren : Str -> Str = \str -> "(" ++ str ++ ")" ;
+
+ 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 ++ ";");
+
+ -- taking cases of list size
param
Size = Zero | One | More ;
@@ -24,11 +54,17 @@ resource ResImper = open Prelude, Precedence in {
_ => t
} ;
--- for JVM
- Instr : Type = {s, s3 : Str} ; -- code, labels
- instr : Str -> Instr = \s -> statement s ** {s3 = []} ; ----
- instrc : Str -> Instr -> Instr = \s,i -> statement (s ++ i.s) ** {s3 = i.s3} ; ----
+ -- operations for JVM
+
+ Instr : Type = {s,s2,s3 : Str} ; -- code, variables, labels
+ instr : Str -> Instr = \s ->
+ statement s ** {s2,s3 = []} ;
+ instrc : Str -> Instr -> Instr = \s,i ->
+ ss (s ++ ";" ++ i.s) ** {s2 = i.s2 ; s3 = i.s3} ;
+ instrl : Str -> Instr -> Instr = \s,i ->
+ ss (s ++ ";" ++ i.s) ** {s2 = i.s2 ; s3 = "L" ++ i.s3} ;
+ instrb : Str -> Str -> Instr -> Instr = \v,s,i ->
+ ss (s ++ ";" ++ i.s) ** {s2 = v ++ i.s2 ; s3 = i.s3} ;
binop : Str -> SS -> SS -> SS = \op, x, y ->
ss (x.s ++ y.s ++ op ++ ";") ;
-
-} \ No newline at end of file
+}