summaryrefslogtreecommitdiff
path: root/examples/gfcc/ResImper.gf
diff options
context:
space:
mode:
authoraarne <unknown>2004-09-24 08:46:03 +0000
committeraarne <unknown>2004-09-24 08:46:03 +0000
commit33ea630d4d431045c13e96c51e953ce0bafb4f0f (patch)
treefbac8eb1c4b9c2344e4ddfcd8a281e859aaf7f42 /examples/gfcc/ResImper.gf
parent2c60a2d82a0d7b90924e7dbbcacf36afb8549d17 (diff)
bug fixes in parsing etc; improved ImperC
Diffstat (limited to 'examples/gfcc/ResImper.gf')
-rw-r--r--examples/gfcc/ResImper.gf42
1 files changed, 26 insertions, 16 deletions
diff --git a/examples/gfcc/ResImper.gf b/examples/gfcc/ResImper.gf
index beea5f549..c392f078e 100644
--- a/examples/gfcc/ResImper.gf
+++ b/examples/gfcc/ResImper.gf
@@ -2,27 +2,37 @@ resource ResImper = open Predef in {
-- precedence
+ param PAssoc = PN | PL | PR ;
+
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 = 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 {
+ Prec : PType = Predef.Ints 4 ;
+ PrecExp : Type = {s : Str ; p : Prec ; a : PAssoc} ;
+
+ mkPrec : Prec -> PAssoc -> Str -> PrecExp = \p,a,f ->
+ {s = f ; p = p ; a = a} ;
+
+ usePrec : PrecExp -> Prec -> Str = \x,p ->
+ case <<x.p,p> : Prec * Prec> of {
+ <3,4> | <2,3> | <2,4> => paren x.s ;
+ <1,1> | <1,0> | <0,0> => x.s ;
+ <1,_> | <0,_> => paren x.s ;
+ _ => x.s
+ } ;
+
+ constant : Str -> PrecExp = mkPrec 4 PN ;
+
+ infixN : Prec -> Str -> (_,_ : PrecExp) -> PrecExp = \p,f,x,y ->
+ mkPrec p PN (usePrec x (nextPrec p) ++ f ++ usePrec y (nextPrec p)) ;
+ infixL : Prec -> Str -> (_,_ : PrecExp) -> PrecExp = \p,f,x,y ->
+ mkPrec p PL (usePrec x p ++ f ++ usePrec y (nextPrec p)) ;
+ infixR : Prec -> Str -> (_,_ : PrecExp) -> PrecExp = \p,f,x,y ->
+ mkPrec p PR (usePrec x (nextPrec p) ++ f ++ usePrec y p) ;
+
+ nextPrec : Prec -> Prec = \p -> case <p : Prec> of {
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} ;