progs/while.scala
changeset 472 372f9801b76d
parent 471 9476086849ad
parent 470 8df654e9eb4e
equal deleted inserted replaced
471:9476086849ad 472:372f9801b76d
    84   def parse(ts: List[Token]) = ts match {
    84   def parse(ts: List[Token]) = ts match {
    85     case T_ID(s)::ts => Set((s, ts)) 
    85     case T_ID(s)::ts => Set((s, ts)) 
    86     case _ => Set ()
    86     case _ => Set ()
    87   }
    87   }
    88 }
    88 }
       
    89 
       
    90 def len(xs: List[(Int, Int)]): Int = xs match {
       
    91   case Nil => 0
       
    92   case (1, x)::xs => len(xs) + 1
       
    93   case (_, x)::xs => len(xs) 
       
    94 }
       
    95 
       
    96 def fst(p: (Int, Int)): Int = p match {
       
    97   case Nil => 0
       
    98   case (1, x)::xs => len(xs) + 1
       
    99   case (_, x)::xs => len(xs) 
       
   100 }
       
   101 
    89 
   102 
    90 
   103 
    91 // arithmetic expressions
   104 // arithmetic expressions
    92 lazy val AExp: Parser[List[Token], AExp] = 
   105 lazy val AExp: Parser[List[Token], AExp] = 
    93   (T ~ T_OP("+") ~ AExp) ==> { case ((x, y), z) => Aop("+", x, z): AExp } ||
   106   (T ~ T_OP("+") ~ AExp) ==> { case ((x, y), z) => Aop("+", x, z): AExp } ||