summaryrefslogtreecommitdiff
path: root/examples/gfcc/ImperC.gf
diff options
context:
space:
mode:
authoraarne <unknown>2004-09-18 09:24:51 +0000
committeraarne <unknown>2004-09-18 09:24:51 +0000
commit3a1f403a0146f4717b210373167640a07f0248dd (patch)
treeaf1fe17319c7dd20117b9b842c01b52b35fe96fd /examples/gfcc/ImperC.gf
parent6ec3a53d3cd1666696430d25e1d0c746f3c7dde8 (diff)
doc
Diffstat (limited to 'examples/gfcc/ImperC.gf')
-rw-r--r--examples/gfcc/ImperC.gf45
1 files changed, 31 insertions, 14 deletions
diff --git a/examples/gfcc/ImperC.gf b/examples/gfcc/ImperC.gf
index 9fdf6f6af..ec78504f3 100644
--- a/examples/gfcc/ImperC.gf
+++ b/examples/gfcc/ImperC.gf
@@ -3,36 +3,44 @@
concrete ImperC of Imper = open Prelude, Precedence, ResImper in {
flags lexer=codevars ; unlexer=code ; startcat=Stm ;
+
+-- code inside function bodies
+
lincat
Stm = SS ;
Typ = SS ;
- Exp = {s : PrecTerm} ;
+ Exp = PrecExp ;
Var = SS ;
lin
Decl typ cont = continue (typ.s ++ cont.$0) cont ;
- Assign _ x exp = statement (x.s ++ "=" ++ ex exp) ;
+ Assign _ x exp = continue (x.s ++ "=" ++ ex exp) ;
Return _ exp = statement ("return" ++ ex exp) ;
- While exp loop = statement ("while" ++ paren (ex exp) ++ loop.s) ;
- Block stm = ss ("{" ++ stm.s ++ "}") ;
- None = ss ";" ;
- Next stm cont = ss (stm.s ++ cont.s) ;
-
+ While exp loop = continue ("while" ++ paren (ex exp) ++ loop.s) ;
+ Block stm = continue ("{" ++ stm.s ++ "}") ;
+ End = statement [] ;
+
EVar _ x = constant x.s ;
EInt n = constant n.s ;
EFloat a b = constant (a.s ++ "." ++ b.s) ;
+ EMulI = infixL p3 "*" ;
+ EMulF = infixL p3 "*" ;
EAddI = infixL p2 "+" ;
EAddF = infixL p2 "+" ;
+ ELtI = infixN p1 "<" ;
+ ELtF = infixN p1 "<" ;
TInt = ss "int" ;
TFloat = ss "float" ;
+
+-- top-level code consisting of function definitions
lincat
Program = SS ;
Typs = SS ;
Fun = SS ;
- Body = {s,s2 : Str} ;
- Exps = SS ;
+ Body = {s,s2 : Str ; size : Size} ;
+ Exps = {s : Str ; size : Size} ;
lin
Empty = ss [] ;
@@ -43,12 +51,21 @@ flags lexer=codevars ; unlexer=code ; startcat=Stm ;
cont.s
) ;
- BodyNil stm = stm ** {s2 = []} ;
- BodyCons typ _ body = {s = body.s ; s2 = typ.s ++ body.$0 ++ "," ++ body.s2} ;
+ NilTyp = ss [] ;
+ ConsTyp = cc2 ;
- EApp args val f exps = constant (f.s ++ paren exps.s) ;
+ BodyNil stm = stm ** {s2 = [] ; size = Zero} ;
+ BodyCons typ _ body = {
+ s = body.s ;
+ s2 = typ.s ++ body.$0 ++ separator "," body.size ++ body.s2 ;
+ size = nextSize body.size
+ } ;
- NilExp = ss [] ;
- ConsExp _ _ e es = ss (ex e ++ "," ++ es.s) ;
+ EApp args val f exps = constant (f.s ++ paren exps.s) ;
+ NilExp = ss [] ** {size = Zero} ;
+ ConsExp _ _ e es = {
+ s = ex e ++ separator "," es.size ++ es.s ;
+ size = nextSize es.size
+ } ;
}