Questions tagged [ocamlyacc]

ocamlyacc is a Parser generator for OCaml (mostly deprecated by Menhir)

ocamlyacc is a Parser generator for OCaml, derived from yacc.

Used to build the OCaml compiler, it is included in the official distribution. However, it is not supported anymore, and the official policy is that OCaml users should use Menhir[2] instead. Indeed, Menhir is mostly backward compatible (it can read ocamlyacc source files), but improves over ocamlyacc in many directions (grammars can be combined, symbols can be named, etc.)

[2] http://gallium.inria.fr/~fpottier/menhir/

See also:

84 questions
16
votes
3 answers

ocamlyacc parse error: what token?

I'm using ocamlyacc and ocamllex. I have an error production in my grammar that signals a custom exception. So far, I can get it to report the error position: | error { raise (Parse_failure (string_of_position (symbol_start_pos ()))) } But, I…
Arjun Guha
  • 486
  • 4
  • 11
9
votes
3 answers

Using external type declarations with OCamlyacc

I have a type expr in an expr.ml file. In parser.mly (OCamlyacc file), I define the expr rule and give the type : %start expr %type expr However, I get : File "parser.mli", line 34, characters 48-52: Error: Unbound type…
rochem
  • 303
  • 1
  • 5
9
votes
3 answers

On ocamlyacc, function application grammar and precedence

I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I can't figure this out. My grammar allows something like this: let sub = fun x -> fun y -> x - y;; However, if I want to use the function so defined, I can write: (sub 7) 3…
Amadan
  • 191,408
  • 23
  • 240
  • 301
7
votes
1 answer

Return multiple tokens in ocamllex

Is there any way to return multiple tokens in OCamlLex? I'm trying to write a lexer and parser for an indentation based language, and I would like my lexer to return multiple DEDENT tokens when it notices that the indentation level is less than it…
Joe Bloggs
  • 571
  • 3
  • 6
  • 14
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
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
6
votes
3 answers

Feed ocamlyacc parser from explicit token list?

Is it possible to feed an OCamlYacc-generated parser an explicit token list for analysis? I'd like to use OCamlLex to explicitly generate a token list which I then analyze using a Yacc-generated parser later. However, the standard use case…
Christian Lindig
  • 1,216
  • 1
  • 9
  • 24
4
votes
1 answer

Ocamlyacc token not visible when performing semantic action

I am using ocamlyacc for a small parser which also performs some semantic actions on most parsing rules. I have defined a set of tokens in the beginning: %token T_plus %token T_minus %token T_int_const %left T_plus T_minus A parser rule…
VHarisop
  • 2,816
  • 1
  • 14
  • 28
4
votes
1 answer

Parser/Lexer ignoring incomplete grammar rules

I have a parser and lexer written in ocamlyacc and ocamllex. If the file to parse ends prematurely, as in I forget a semicolon at the end of a line, the application doesn't raise a syntax error. I realize it's because I'm raising and catching EOF…
nlucaroni
  • 47,556
  • 6
  • 64
  • 86
3
votes
1 answer

Translation from Python to CIL(C Intermediate Language)

I have worked on the static analysis on Python source code recently. There is already a static analyzer written in Ocaml for CIL(C Intermediate Language) in our group. We want to reuse this analyzer, so our ideal approach is to translate Python to…
Yao
  • 31
  • 2
3
votes
2 answers

Representing optional syntax and repetition with OcamlYacc / FsYacc

I'm trying to build up some skills in lexing/parsing grammars. I'm looking back on a simple parser I wrote for SQL, and I'm not altogether happy with it -- it seems like there should have been an easier way to write the parser. SQL tripped me up…
Juliet
  • 80,494
  • 45
  • 196
  • 228
3
votes
2 answers

Using ocamllex/ocamlyacc to parse part of a grammar

I've been using regexes to go through a pile of Verilog files and pull out certain statements. Currently, regexes are fine for this, however, I'm starting to get to the point where a real parser is going to be needed in order to deal with nested…
aneccodeal
  • 8,531
  • 7
  • 45
  • 74
2
votes
2 answers

reduce/reduce conflicts using ocamlyacc

I am struggling with a grammar that involves typed expressions as well as variable access. The result type of this access is not ascertainable during parsing and is evaluated in a second step. This evaluation is not a problem, but it seems hard to…
Fynn
  • 4,753
  • 3
  • 32
  • 69
2
votes
1 answer

Specifying ocamllex encoding

I'm currently developing a parser according to a specification, and I'm completely unable to find anywhere in the docs information about text encoding. It sounds weird to me that the docs of a lexing library wouldn't mention text encoding at all, so…
MrAnima
  • 555
  • 1
  • 4
  • 13
2
votes
1 answer

Using ocamlyacc with sedlex

I am trying to figure out how to use ocamlyacc with sedlex. lexer.ml (using sedlex): let rec lex (lexbuf: Sedlexing.lexbuf) = match%sedlex lexbuf with | white_space -> lex lexbuf (* ... other lexing rules ... *) | _ -> failwith…
Flux
  • 9,805
  • 5
  • 46
  • 92
1
2 3 4 5 6