|
|
|
|
|
by loup-vaillant
2776 days ago
|
|
I've just written a little parser I OCaml, and the file goes like this: Module declarations ( 3 lines)
Parser type declaration ( 1 line )
Implementation details you don't care about (47 lines)
Actual grammar (20 lines)
In that order. In Haskell, I would probably have put the grammar at the top of the file, so you can get the big picture right away. But the language reads stuff from top to bottom, so I have to put the big picture at the bottom.An alternative would be separate the details from the grammar, but then I would expose those implementation details in an interface, while in fact the rest of the program is only interested in one function that parses everything. Or, you could write from bottom to top. It's OCaml, so you know the big picture cannot be at the top. Now a case could be made for a language that reads toplevel statements from bottom to top… |
|