summaryrefslogtreecommitdiff
path: root/examples/gfcc/ResImper.gf
diff options
context:
space:
mode:
authoraarne <unknown>2004-09-23 14:41:42 +0000
committeraarne <unknown>2004-09-23 14:41:42 +0000
commit2c60a2d82a0d7b90924e7dbbcacf36afb8549d17 (patch)
tree0a04734e741c294cb9f58cfdcafa2ff2b55894dd /examples/gfcc/ResImper.gf
parentd5b4230d6dbee8c03eedf8d181dfa2badf1a954b (diff)
Ints n
Diffstat (limited to 'examples/gfcc/ResImper.gf')
-rw-r--r--examples/gfcc/ResImper.gf37
1 files changed, 16 insertions, 21 deletions
diff --git a/examples/gfcc/ResImper.gf b/examples/gfcc/ResImper.gf
index 62097bdc3..beea5f549 100644
--- a/examples/gfcc/ResImper.gf
+++ b/examples/gfcc/ResImper.gf
@@ -1,33 +1,28 @@
-resource ResImper = {
+resource ResImper = open Predef in {
-- precedence
- param
- Prec = P0 | P1 | P2 | P3 ;
- oper
- PrecExp : Type = {s : Prec => Str} ;
- ex : PrecExp -> Str = \exp -> exp.s ! P0 ;
- constant : Str -> PrecExp = \c -> {s = \\_ => c} ;
+ oper
+ Prec : PType = Predef.Ints 4 ;
+ PrecExp : Type = {s : Prec => Str} ;
+ ex : PrecExp -> Str = \exp -> exp.s ! 0 ;
+ 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} ;
+ {s = mkPrec (x.s ! (nextPrec ! p) ++ f ++ y.s ! (nextPrec ! p)) ! p} ;
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}
+ nextPrec : Prec => Prec = table {
+ 4 => 4 ;
+ n => Predef.plus n 1
} ;
+ mkPrec : Str -> Prec => Prec => Str = \str ->
+ \\p,q => case Predef.lessInt p q of {
+ Predef.PTrue => paren str ;
+ _ => str
+ } ;
+
-- string operations
SS : Type = {s : Str} ;