open Scanf (* "%c" citeste caracter; "%0c" obtine caracterul fara sa-l consume *) let rec expr () = scanf " %0c" (function '0'..'9' -> scanf "%d" (fun n -> n) _ -> scanf "%c" (function '+' -> expr() + expr() '-' -> let e1 = expr() in e1 - expr() '*' -> expr() * expr() '/' -> let e1 = expr() in e1 / expr() _ -> failwith "illegal character") ) let _ = print_int(expr())
This document was generated using caml2html