menhir

Is there a way to export more things when I generate a parser with menhir?

廉价感情. 提交于 2020-01-06 03:39:07
问题 I'm using menhir to generate a parser and right now, the parser.mli file that it generated from my parser.mly file looks like this: (* The type of tokens. *) type token = (* ... huge ADT definition goes here ... *) (* This exception is raised by the monolithic API functions. *) exception Error (* The monolithic API. *) val start: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Types.ast Is there a way to include more stuff in my parser's interface? In particular, I would like to be able to also

Seemingly equivalent Menhir rules change the shift/reduce conflicts found in grammar

你离开我真会死。 提交于 2020-01-06 03:05:40
问题 I'm using Menhir to create a parser, and there's a behaviour that always trips me, and I don't understand it. I have created the following minimal example to demonstrate it; this shows the declaration of the receiver argument in a method declaration in the Go language (http://golang.org/ref/spec#Method_declarations): %{ %} %token <string> T_identifier %token T_star %start <unit> demo %% (* This rule has a shift/reduce conflict demo: | option(T_identifier) option(T_star) T_identifier { () } *)

How to use modules with js_of_ocaml?

本秂侑毒 提交于 2020-01-02 03:14:07
问题 I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml but I would like to include several modules in my project. How can I do that ? The other modules are actually a lexer and a parser poduced by ocamllex and menhir. I have read a tutorial on how to use

Make menhir add user-defined functions from .mly to .mli

感情迁移 提交于 2019-12-24 06:48:28
问题 Menhir allows to add arbitrary ocaml code to the end of the .mly file, where I want to declare a few functions. But I could not find a way to make menhir add my functions to the .mli file, so that they are visible from the other modules. Is it possible? 回答1: The answer is simple, it's no . The code defined in the .mly file is only used by the parser. As stated in the manual : A header is a piece of OCaml code, surrounded with %{ and %} . It is copied verbatim at the beginning of the .ml file.

multiple error reporting with menhir: which token?

ぃ、小莉子 提交于 2019-12-10 14:05:21
问题 I am writing a small parser with Menhir + Ocamllex and I have two requirements I cannot seem to meet at the same time I would like to keep parsing after an error (to report more errors). I would like to print the token at which the error ocurred. I can do only 1) easily, by using the error token. I can also do only 2) easily, using the approach suggested for this question. However, I don't know of an easy way to achieve both. The way I handle errors right now goes something like this: pair: |

How to use modules with js_of_ocaml?

左心房为你撑大大i 提交于 2019-12-05 05:36:00
I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml but I would like to include several modules in my project. How can I do that ? The other modules are actually a lexer and a parser poduced by ocamllex and menhir. I have read a tutorial on how to use ocamllex and menhir with js_of_ocaml but it makes wrong assumptions on where js_of_ocaml is installed