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
0
votes
1 answer

Using OCaml Menhir, is there a way to access something before it is processed?

I am writing a parser to parse and compute function derivatives in a calculator. I got a problem with implementing product and quotient rules : for a product the derivation formula is (u*v)' = u'v+uv', thus I need the value of u and u' in the final…
Zeti
  • 3
  • 3
0
votes
1 answer

Menhir- get values between interval

I got this rule in parser.mly: intervalue: | c = CST(* True False 1 7 89 "sfr" *) { Ecst c } | id = ident (* a-z [a-z]* *) { Eident id } | iv = LSQ l = separated_list(TWOPoints, intervalue) RSQ /* [1..4]*/ { Elist l } ; I need to pass…
user48571
  • 27
  • 8
0
votes
1 answer

Getting tokens from OCaml lexer

I am currently working on a terminal-based text editor. I want to support a type of syntax highlighting for .ml files I open up in the text editor. I was thinking that if there was a way that I could access the lexer used for OCaml in general, then…
Shiv
  • 109
  • 6
0
votes
1 answer

Menhir: --external-tokens can't seem to find Tokens module

I have a tokens.ml file which has a type token statement in it. I also have a tokens.mli with the same type token statement. Now, I have a parser.mly which uses the tokens from tokens.mly. I want to keep my tokens in tokens.ml/mli and my parser in…
Enrico Borba
  • 1,877
  • 2
  • 14
  • 26
0
votes
1 answer

Branching at the parser lever based on the content of a token

I'm working on a simple example parser/lexer for a tiny project, but I've run into a problem. I'm parsing content along these lines: Name SEP Gender SEP Birthday Name SEP Gender SEP Birthday … where SEP is any one (but not multiple!) of |, ,, or…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
0
votes
1 answer

shift/reduce conflict with nested lists

I've been working through "Modern Compiler Implementation in ML", converting SML to OCaml as I go. The book defines a language called Tiger that has a let ... in ... end syntax for declaring types, variables, and functions in scope for a given…
nirvdrum
  • 2,319
  • 17
  • 26
0
votes
1 answer

Menhir separated_nonempty_list generates code with type error

I have a simple recursive rule: i_stmt: | CHAIN LPAREN c=separated_nonempty_list(i_stmt, COMMA) RPAREN {Chain c} | ASSIGN LPAREN n=i_var COMMA e=i_expr RPAREN {Assign (n,e)} | CRETURN LPAREN i=i_expr RPAREN { Return i } ; It is compiled OK…
krokodil
  • 1,326
  • 10
  • 18
0
votes
1 answer

Type error when equipping Menhir with an abstract syntax tree

EDIT: My below question still stands but I appreciate that it's hard to answer without sifting through a pile of code. Therefore, to ask a somewhat similar question, does anyone have any examples of Menhir being used to implement an AST? Preferably…
daire16
  • 13
  • 4
0
votes
1 answer

I am trying to make a Parser with ocamlyacc for a Language, but what type should I put?

I have the following code also have more after like expr: int {} | BOOL {} etc but i dont know what is the type that i should write in type of this parser, i have a calculator example that works with int and the type is int , but in my program i…
0
votes
1 answer

Shift/reduce conflits on ocamlyacc

I have the following parser: %{ open t open Lexer %} %token INT %token FLOAT %token CHAR %token BOOL %token PLUS Menos Mult Div Bigger Smaller MINUS TIMES %token Equals Atribuicao SoE BoE And Or %token IF…
Joao Saraiva
  • 91
  • 2
  • 15
0
votes
0 answers

Error: generates empty language using Menhir and OCaml

I am currently working on a Pascal Parser using OCaml and Menhir. When I compile my parser.mly, which contains the following scriptlet of code, Menhir simply says "Warning: if_cmd generates empty language" This might happen when the rule "if_cmd"…
stamblew
  • 138
  • 1
  • 11
0
votes
1 answer

Installing Compcert-2.6 on 64bit Mac

I got the following error when compiling compcert 2.6 on 64bit macos $./configure ia32-macosx ... $make ... /Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile.extr ccomp ocamlfind: Package `menhirLib' not found OCAMLOPT…
Ugur Koc
  • 53
  • 7
0
votes
1 answer

OCaml compilation with corebuild

I currently have a project (Go to Python compiler) with the following files ast.ml parser.mly lex.mll weeder.ml prettyPrint.ml main.ml Here are the dependencies: parser: ast lexer: parser, Core, Lexing weeder: ast prettyPrint: ast main: ast, lex,…
Olivier Melançon
  • 21,584
  • 4
  • 41
  • 73
0
votes
2 answers

Error trying to parse imaginary programming language

I'm working on a language interpreter for a programming language I made up. Here's some example code, which should work but currently dies with Syntax error at offset 45. when reading this testcase. { foo = { "min" : 1 ,"max" : 5}; …
Joshua Snider
  • 705
  • 1
  • 8
  • 34
0
votes
2 answers

Conflict while parsing a set of expressions

I would like to parse a set of expressions: R[3]C, R[2]C, R[3]C-R[2]C... There is a conflict I cannot solve... Here is a part of lexer.mll: rule token = parse | 'R' { R } | 'C' { C } | "RC" { RC } |…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292