-(* 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>
*)
structure A = Ast
+structure T = Type
structure AU = AstUtils
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 *)
Symbol.bogus )
%%
-%header (functor L4LrValsFn (structure Token : TOKEN))
+%header (functor L5LrValsFn (structure Token : TOKEN))
%term
EOF
| 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
| 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 *)
%eop EOF
%noshift EOF
-%name L4
+%name L5
+%right QUESTION COLON
%left LOGOR
%left LOGAND
%left BITOR
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)
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])
(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
| 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)