progs/parser-combinators/comb2.sc
changeset 812 2f9a0dcf61ae
parent 803 d4fb8c7fc3bf
child 828 bdcaecdee9eb
equal deleted inserted replaced
811:86406d70d6f0 812:2f9a0dcf61ae
   153   ((p"skip".map[Stmt]{_ => Skip }) ||
   153   ((p"skip".map[Stmt]{_ => Skip }) ||
   154    (IdParser ~ p":=" ~ AExp).map[Stmt]{ case x ~ _ ~ z => Assign(x, z) } ||
   154    (IdParser ~ p":=" ~ AExp).map[Stmt]{ case x ~ _ ~ z => Assign(x, z) } ||
   155    (p"write(" ~ IdParser ~ p")").map[Stmt]{ case _ ~ y ~ _ => Write(y) } ||
   155    (p"write(" ~ IdParser ~ p")").map[Stmt]{ case _ ~ y ~ _ => Write(y) } ||
   156    (p"if" ~ BExp ~ p"then" ~ Block ~ p"else" ~ Block)
   156    (p"if" ~ BExp ~ p"then" ~ Block ~ p"else" ~ Block)
   157      .map[Stmt]{ case _ ~ y ~ _ ~ u ~ _ ~ w => If(y, u, w) } ||
   157      .map[Stmt]{ case _ ~ y ~ _ ~ u ~ _ ~ w => If(y, u, w) } ||
   158    (p"while" ~ BExp ~ p"do" ~ Block).map[Stmt]{ case _ ~ y ~ _ ~ w => While(y, w) }) 
   158    (p"while" ~ BExp ~ p"do" ~ Block).map[Stmt]{ case _ ~ y ~ _ ~ w => While(y, w) })   
       
   159  
   159  
   160  
   160 // statements
   161 // statements
   161 lazy val Stmts: Parser[String, Block] =
   162 lazy val Stmts: Parser[String, Block] =
   162   (Stmt ~ p";" ~ Stmts).map[Block]{ case x ~ _ ~ z => x :: z } ||
   163   (Stmt ~ p";" ~ Stmts).map[Block]{ case x ~ _ ~ z => x :: z } ||
   163   (Stmt.map[Block]{ s => List(s) })
   164   (Stmt.map[Block]{ s => List(s) })