Questions tagged [menhir]

Menhir is a parser generator for OCaml

Menhir is a LR(1) parser generator for the Objective Caml programming language. That is, Menhir compiles LR(1) grammar specifications down to Objective Caml code. It is mostly compatible with ocamlyacc, and can be used with ocamllex.

References:

See also:

76 questions
14
votes
3 answers

OCaml + Menhir Compiling/Writing

I'm a complete newbie when it comes to OCaml. I've only recently started using the language (about 2 weeks ago), but unfortunately, I've been tasked with making a syntax analyzer (parser + lexer, whose function is to either accept or not a sentence)…
Lopson
  • 1,202
  • 1
  • 8
  • 20
9
votes
1 answer

Using menhir with sedlex

I need to use menhir with sedlex for whatever reason (utf-8), but don't know how to make the generated parser depend on Sedlexing instead of Lexing. Any tips? When I run menhir --infer parser.mly the generated program has lines with Lexing.... I…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
7
votes
1 answer

Generate dump/explain files of Menhir when using ocamlbuild

I discovered that Menhir provides --dump and --explain options and it helps debugging a lot. But how can I enable these options under ocamlbuild so that Menhir always generates dump files at compile time? I tried to write myocamlbuild file handling…
7
votes
3 answers

How to use modules with js_of_ocaml?

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…
Thomash
  • 6,339
  • 1
  • 30
  • 50
7
votes
1 answer

Specifying a dynamic priority and precedence for an operator in Menhir/Ocamlyacc

I'm trying to parse a language where the operators have a dynamic attributes (priority and precedence) using the Menhir parser (similar to Ocamlyacc). During the lexing phase, all the operators fill a OP:string token (so "+" turns into (OP "+"),…
CharlieP
  • 993
  • 7
  • 19
6
votes
2 answers

menhir - associate AST nodes with token locations in source file

I am using Menhir to parse a DSL. My parser builds an AST using an elaborate collection of nested types. During later typecheck and other passes in error reports generated for a user, I would like to refer to source file position where it occurred.…
krokodil
  • 1,326
  • 10
  • 18
6
votes
1 answer

multiple error reporting with menhir: which token?

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…
orm
  • 2,835
  • 2
  • 22
  • 35
5
votes
2 answers

Suppress "never useful" precedence warning in modular parser specifications?

Is it possible to suppress unused precedence warnings in menhir? Background: I have a core parser Lib.mly with several rules and, separately, a host of additional parsers (A.mly, B.mly, ...) which use definitions from Lib.mly. To support using a…
ztatlock
  • 190
  • 2
  • 9
5
votes
2 answers

OCaml + Menhir: How to parse OCaml like tuple-pattern?

I'm a quite beginner of menhir. I'm wondering how to parse OCaml like tuple-pattern in my own language, which is quite similar to OCaml. For example, in the expression let a,b,c = ..., a, b, c should be parsed like Tuple (Var "a", Var "b", Var…
nomaddo
  • 416
  • 3
  • 12
4
votes
0 answers

Multiple parsing files with menhir

I'm trying to have two different parsers with different entry points. I have the following project hierarchy: . ├── bin │   ├── dune │   ├── lexer.mll │   ├── main.ml │   ├── parser.messages │   ├── parser.mly │   └── test_parser.mly ├──…
Lhooq
  • 4,281
  • 1
  • 18
  • 37
4
votes
1 answer

ocaml menhir parser production is never reduced

I'm in the middle of learning how to parse simple programs. This is my lexer. { open Parser exception SyntaxError of string } let white = [' ' '\t']+ let blank = ' ' let identifier = ['a'-'z'] rule token = parse | white {token lexbuf} (*…
Seneca
  • 2,392
  • 2
  • 18
  • 33
4
votes
2 answers

Using Batteries in .mly file with ocamlbuild

I have a project with OCaml .ml files and a Menhir .mly file. I use ocamlbuild to compile the project. My _tags file contains this single line: true: use_menhir, package(batteries) Everything works well, except when I want to use Batteries in the…
p4bl0
  • 3,846
  • 1
  • 22
  • 21
3
votes
1 answer

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

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…
Alexey B.
  • 1,106
  • 8
  • 17
3
votes
0 answers

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

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…
hugomg
  • 68,213
  • 24
  • 160
  • 246
3
votes
1 answer

ocaml menhir - end of stream conflict for simple grammar

I am trying out Menhir to generate a very simple expression parser with (+, -, *, / operators), but I get end of stream conflicts. Here's the grammar: %token INT %token ADD %token SUB %token MUL %token DIV %token EOF %token LPAREN %token…
soumik
  • 349
  • 2
  • 12
1
2 3 4 5 6