while.scala
changeset 71 7717f20f0504
parent 70 e6868bd2942b
child 72 d65525aeca08
equal deleted inserted replaced
70:e6868bd2942b 71:7717f20f0504
   103 
   103 
   104 lazy val Stmt: Parser[List[Token], Stmt] =
   104 lazy val Stmt: Parser[List[Token], Stmt] =
   105   (T_KWD("skip") ==> ((_) => Skip: Stmt)) ||
   105   (T_KWD("skip") ==> ((_) => Skip: Stmt)) ||
   106   (IdParser ~ T_OP(":=") ~ AExp) ==> { case ((x, y), z) => Assign(x, z): Stmt } ||
   106   (IdParser ~ T_OP(":=") ~ AExp) ==> { case ((x, y), z) => Assign(x, z): Stmt } ||
   107   (T_KWD("if") ~ BExp ~ T_KWD("then") ~ Block ~ T_KWD("else") ~ Block) ==>
   107   (T_KWD("if") ~ BExp ~ T_KWD("then") ~ Block ~ T_KWD("else") ~ Block) ==>
   108     { case (((((x,y),z),u),v),w) => If(y, u, w): Stmt }
   108     { case (((((x,y),z),u),v),w) => If(y, u, w): Stmt } ||
   109 
   109   (T_KWD("while") ~ BExp ~ T_KWD("do") ~ Block) ==> { case (((x, y), z), w) => While(y, w) } 
       
   110  
   110 lazy val Stmts: Parser[List[Token], Block] =
   111 lazy val Stmts: Parser[List[Token], Block] =
   111   (Stmt ~ T_SEMI ~ Stmts) ==> { case ((x, y), z) => x :: z : Block } ||
   112   (Stmt ~ T_SEMI ~ Stmts) ==> { case ((x, y), z) => x :: z : Block } ||
   112   (Stmt ==> ((s) => List(s) : Block))
   113   (Stmt ==> ((s) => List(s) : Block))
   113 
   114 
   114 lazy val Block: Parser[List[Token], Block] =
   115 lazy val Block: Parser[List[Token], Block] =