]> Joshua Wise's Git repositories - snipe.git/blobdiff - parse/l5.grm
Initial import of l5c
[snipe.git] / parse / l5.grm
similarity index 88%
rename from parse/l4.grm
rename to parse/l5.grm
index 3f14c331a0c69ea61e14bf378c47e1e0590724a9..7195271967c36fc6e62d3c8e700402ba9966bdc8 100644 (file)
@@ -1,5 +1,5 @@
-(* L4 Compiler
- * L4 grammar
+(* L5 Compiler
+ * L5 grammar
  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
  * Modified: Frank Pfenning <fp@cs.cmu.edu>
  * Modified: Joshua Wise <jwise@andrew.cmu.edu>
@@ -7,6 +7,7 @@
  *)
 
 structure A = Ast
+structure T = Type
 structure AU = AstUtils
 structure AUP = AstUtils.Program
 
@@ -16,7 +17,7 @@ structure AUP = AstUtils.Program
 fun mark (e, (left, right)) = A.Marked (Mark.mark' (e, ParseState.ext (left, right)))
 fun markstm (e, (left, right)) = A.MarkedStm (Mark.mark' (e, ParseState.ext (left, right)))
 fun markfunction (e, (left, right)) = A.MarkedFunction (Mark.mark' (e, ParseState.ext (left, right)))
-fun marktypedef (e, (left, right)) = A.MarkedTypedef (Mark.mark' (e, ParseState.ext (left, right)))
+fun marktypedef (e, (left, right)) = T.MarkedTypedef (Mark.mark' (e, ParseState.ext (left, right)))
 
 (* create lval from expression; here just an id *)
 (* generates error if not an identifier *)
@@ -27,7 +28,7 @@ fun make_lval (A.Var(id)) ext = id
                        Symbol.bogus )
 
 %%
-%header (functor L4LrValsFn (structure Token : TOKEN))
+%header (functor L5LrValsFn (structure Token : TOKEN))
 
 %term 
    EOF
@@ -42,7 +43,8 @@ fun make_lval (A.Var(id)) ext = id
  | LBRACE | RBRACE
  | LPAREN | RPAREN
  | UNARY | ASNOP (* dummy *)
- | EXTERN | VAR | INT | COLON | COMMA | STRUCT | NULL | LBRACKET | RBRACKET | ARROW | DOT | NEW
+ | EXTERN | VAR | INT | QUESTION | COLON | COMMA | STRUCT | NULL | LBRACKET | RBRACKET | ARROW | DOT | NEW
+ | PLUSPLUS | MINUSMINUS
 
 %nonterm 
    program of A.program
@@ -59,17 +61,17 @@ fun make_lval (A.Var(id)) ext = id
  | simpoption of A.stm option
  | elseoption of A.stm list option
  | idents of A.ident list
- | vtype of A.vtype
+ | vtype of T.vtype
  | decls of A.program
  | extdecl of A.ident * A.function
- | paramlist of A.variable list
- | param of A.variable
- | typedecl of A.ident * A.typedef
- | memberlist of (A.ident * A.vtype) list
- | member of (A.ident * A.vtype)
+ | paramlist of T.variable list
+ | param of T.variable
+ | typedecl of T.ident * T.typedef
+ | memberlist of (T.ident * T.vtype) list
+ | member of (T.ident * T.vtype)
  | function of A.ident * A.function
- | vardecl of A.variable list
- | vardecls of A.variable list
+ | vardecl of T.variable list
+ | vardecls of T.variable list
 
 %verbose                                (* print summary of errors *)
 %pos int                                (* positions *)
@@ -77,8 +79,9 @@ fun make_lval (A.Var(id)) ext = id
 %eop EOF
 %noshift EOF
 
-%name L4
+%name L5
 
+%right QUESTION COLON
 %left LOGOR
 %left LOGAND
 %left BITOR
@@ -99,11 +102,11 @@ program    : programx               (programx)
 programx   : decls                  (decls)
            | programx function      (AUP.append_function programx function)
 
-vtype      : INT                    (A.Int)
-           | IDENT                  (A.Typedef IDENT)
-           | vtype STAR             (A.Pointer vtype)
+vtype      : INT                    (T.Int)
+           | IDENT                  (T.Typedef IDENT)
+           | vtype STAR             (T.Pointer vtype)
            | vtype LBRACKET RBRACKET
-                                    (A.Array vtype)
+                                    (T.Array vtype)
 
 decls      :                        (Symbol.empty, Symbol.empty)
            | typedecl decls         (AUP.append_typedef decls typedecl)
@@ -120,9 +123,9 @@ paramlist  : param COMMA paramlist  (param :: paramlist)
 param      : IDENT COLON vtype      (IDENT, vtype)
 
 typedecl   : STRUCT IDENT LBRACE RBRACE SEMI
-                                    (IDENT, marktypedef (A.Struct ([]), (STRUCTleft, SEMIright)))
+                                    (IDENT, marktypedef (T.Struct ([]), (STRUCTleft, SEMIright)))
            | STRUCT IDENT LBRACE memberlist RBRACE SEMI
-                                    (IDENT, marktypedef (A.Struct (memberlist), (STRUCTleft, SEMIright)))
+                                    (IDENT, marktypedef (T.Struct (memberlist), (STRUCTleft, SEMIright)))
 
 memberlist : member memberlist      (member :: memberlist)
            | member                 ([member])
@@ -154,6 +157,10 @@ simp       : exp ASSIGN exp %prec ASNOP
                                     (A.Assign(exp1, exp2))
            | exp asnop exp %prec ASNOP
                                     (A.AsnOp(asnop, exp1, exp2))
+           | exp PLUSPLUS %prec ASNOP
+                                    (A.AsnOp(A.PLUS, exp, A.ConstExp(0w1)))
+           | exp MINUSMINUS %prec ASNOP
+                                    (A.AsnOp(A.MINUS, exp, A.ConstExp(0w1)))
            | exp                    (markstm (A.Effect (exp), (expleft, expright)))
 
 control    : IF LPAREN exp RPAREN block elseoption
@@ -212,6 +219,8 @@ exp        : LPAREN exp RPAREN      (exp)
            | MINUS exp %prec UNARY  (mark (A.OpExp (A.NEGATIVE, [exp]), (MINUSleft,expright)))
            | BITNOT exp %prec UNARY (mark (A.OpExp (A.BITNOT, [exp]), (BITNOTleft,expright)))
            | BANG exp %prec UNARY   (mark (A.OpExp (A.BANG, [exp]), (BANGleft,expright)))
+           | exp QUESTION exp COLON exp
+                                    (mark (A.Conditional (exp1, exp2, exp3), (exp1left, exp3right)))
 
 explist    : exp                    ([exp])
            | exp COMMA explist      (exp :: explist)
This page took 0.029119 seconds and 4 git commands to generate.