This repository has been archived on 2024-01-18. You can view files and clone it, but cannot push or open issues or pull requests.
compilation/tp/tp-menhir/code/printer.ml

18 lines
403 B
OCaml
Raw Normal View History

2023-10-02 09:39:12 +02:00
open AST
let string_of_exp e =
let rec aux = function
| Id x ->
x
| LInt x ->
string_of_int x
| Add (e1, e2) ->
Printf.sprintf "(%s + %s)" (aux e1) (aux e2)
| Mul (e1, e2) ->
Printf.sprintf "(%s * %s)" (aux e1) (aux e2)
| Sum (x, start, stop, exp) ->
Printf.sprintf "sum(%s, %s, %s, %s)"
x (aux start) (aux stop) (aux exp)
in
aux e