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
3
votes
2 answers

Make a table containing tokens visible for both .mly and .mll by menhir

I would like to define a keyword_table which maps some strings to some tokens, and I would like to make this table visible for both parser.mly and lexer.mll. It seems that the table has to be defined in parser.mly, %{ open Utility (* where…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
3
votes
1 answer

Example of grammar (lex/yacc) for tree description

I want to parse a tree from a file that will describe this tree (which actually is a taxonomy). I am looking for examples of grammar (ideally lex/yacc files) that provides description of trees. It would be better if that described trees were not…
2
votes
1 answer

Understand potential conflicts

I have a small parser of expression built by Menhir. I'm trying to recover parenthesis-incomplete expressions during parsing by writing recovery grammars in parser.mly: %{ open AST %} %token LINT %token ID %token LPAREN RPAREN…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
2
votes
1 answer

Type Sedlexing.lexbuf is not compatible with type Lexing.lexbuf

I would like to add incremental API and error handling of menhir to my project by sedlex+menhir; I'm trying to adopt attempt2 and fail of this sample to my code. Here is the attempt2 of the sample: let attempt2 filename text = (* Allocate and…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
2
votes
1 answer

Is it possible to debug the Menhir lexer?

It's possible to debug the parser generated by Menhir, e.g. menhir --interpret --interpret-show-cst parser.mly. Is it also possible to debug which tokens are created by the lexer? I didn't find anything in the Manhir manual page or online. For…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
2
votes
2 answers

How to use Menhir error messages generation via OCamlbuild?

I am using the --compile-errors functionality of menhir and I'm quite happy with it. I'm also using ocamlbuild to manage the compilation of my project. Since the project is quite basic, the build infrastructure has remained trivial so far. I have a…
Abdallah
  • 335
  • 1
  • 7
2
votes
1 answer

make menhir find all alternatives?

I would like to change the behavior of menhir's output in follwoing way: I want it to look up all grammatical alternatives if it finds any, and put them in a list and get me back this ambigouus interpretation. It shall not reduce conflicts, just…
Prodiction
  • 187
  • 12
2
votes
1 answer

In Menhir is it possible to make a rule left-associative if it does not have an operator?

I am trying to use Menhir to write a parser for language of regular expressions. My desired grammar, before I modify it to remove ambiguities, looks a bit like the following example. Note that the "sequencing / concatenation" is implicit and there…
hugomg
  • 68,213
  • 24
  • 160
  • 246
2
votes
1 answer

OCaml Menhir: Grammar is not working

I am using menhir to define the Tiger language described in Modern Compiler Implementation in ML, here is the manual: exp: | lv = lvalue { Lvalue lv } | i = INT { Int i } | s = STRING { String s } ...... lvalue: | i =…
齐天大圣
  • 1,169
  • 5
  • 15
  • 36
2
votes
1 answer

Pass values as arguments to rules

When implementing real world (TM) languages, I often encounter a situation like this: (* language Foo *) type A = ... (* parsed by parse_A *) type B = ... (* parsed by parse_B *) type collection = { as : A list ; bs : B list } (* parser…
choeger
  • 3,562
  • 20
  • 33
2
votes
1 answer

expand ocamllex for a bigger lexicon

is there a way to get ocammlex work with more keywords? i've written an interpreter and parser for the german language, which "compiles" german text into latex-pictures for sake of language analysis. it works really fine and is really new in the…
2
votes
1 answer

Add source code position information to a frontend

I am writing a static analyser including a frontend for programs in a specific language. The front-end succeeds to generate an AST from a program, on which the analyser works well: it either proves the program correct (for some specific properties),…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
2 answers

How to properly tokenize over whitespaces with ocamllex/Menhir?

I am writing a simple shell in OCaml. My grammar looks a little like this at the moment /* program: command* command: WORD WORD* redirection* redirection: NUMBER? > FILENAME | < FILENAME */ Simple enough. I have a lexer file that looks like…
Lou Falkes
  • 73
  • 6
1
vote
1 answer

Manually tweak env/stack/semantic value to achieve an error recovery

I'm trying to implement error recovery in this version of the project (make followed by ./parse e1.input to test). Given (1 in e1.input, I would like the parser to act as if it parsed ) and build an AST Paren (Int 1). Thus, I tried let (startp,…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
1 answer

Understand .messages file generated by menhir

I'm trying to understand .messages file generated by menhir. From this sample, we could use menhir parser.mly --list-errors > parser.messages to generate parser.messages. An error is like follows: main: INT MINUS TIMES ## ## Ends in an error in…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292