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

ocamlyacc with empty string

So I have a grammar that includes the empty string. The grammar is something like this: S->ε S->expression ;; S I'm getting the error "No more states to discard" when I run my parser so I believe I'm not representing the empty string correctly. So…
Fred Ma
  • 57
  • 2
  • 9
0
votes
1 answer

OCaml function application precedence and associativity

I need to give high precedence and left associativity to function application in my OCaml parser. I have a bunch of different tokens it matches for such as %token LET REC EQ IN FUN ARROW %token IF THEN ELSE %token PLUS MINUS MUL DIV LT LE NE AND…
Anatoliy Sokolov
  • 347
  • 1
  • 4
  • 10
0
votes
1 answer

How to create a program combining both Parser and Lexer

I want to build a compiler using Ocamllex/Ocamlyacc and I want to create a main program to combine both of my OcamlParser and OcamlLexer. The thing is that I know how to do it using an input in the command line like the following code: let _ = …
0
votes
2 answers

How to define unrecognized rules in Ocamlyacc

I'm working on company projet, where i have to create a compilator for a language using Ocamlyacc and Ocamllex. I want to know if is it possible to define a rule in my Ocamlyacc Parser that can tell me that no rules of my grammar matching the…
0
votes
1 answer

Shift/reduce conflict with infix sections

I'm having trouble with a yacc-like implementation (using ocamlyacc, in particular) of a grammar that includes ordinary infix operations plus infix sections, like in Haskell. I desire all of these to be grammatical: (+1) (1+) (+) (1+1) However, I…
dubiousjim
  • 4,722
  • 1
  • 36
  • 34
0
votes
2 answers

OCaml Types not compatible - OCamlyacc

funcexpr: /* This is a function: arguments -> string list */ LPAREN HEAD arguments RPAREN { let head a = [List.hd (List.hd a)] in head << $3 } | LPAREN REAR arguments RPAREN { let rear b = List.tl…
0
votes
2 answers

Use primitive functions with user defined types

I was having a problem in ocamlyacc where the type of my start point didn't match the return type of all my rules (I was returning a string at one point and a string list -> string lift at another point), so I made a new type: type S = |…
0
votes
1 answer

C-style included file in ocamlyacc

Can anyone help me on how to enable C-style included file in ocamlyacc? For example: #include "mylib.txt";.
Herry
  • 455
  • 3
  • 14
0
votes
2 answers

OCaml Interpreter: Why my interpreter just execute only one line in my file

I'm writing an interpreter, using ocamlyacc and ocamllex to compile my parser and lexer. My problem is that, I have a file calles test, contain 2 commands that are defined in lexer: print a print b but the interpreter just execute line print a…
Trung Bún
  • 1,117
  • 5
  • 22
  • 47
0
votes
2 answers

Make a table containing tokens visible for both .mly an .mll

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

Try the first rule if the second rule fails

I have defined two sets of identifiers IDENTIFIER_ONE and IDENTIFIER_TWO which are both exculsive subsets of IDENTIFIER. I would like to write a parser such that: "i1(arg) EOS" can't be parsed (1) "i2(arg) EOS" can be parsed (2) "i1(arg) = value…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

Parse two kinds of statements, with a priority

I would like to parse both f(arg).method and f(arg) as block_statement; the first has more priority than the latter. The following elements in parser.mly can't parse f(arg), but can parse f(arg).method as follows: (* f(arg).method *) BS_MAE…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

Exception handling in parsing

I am writing an analyzer which analyzes many independent files. All the files have the same structure: it have a Initiation(), followed by several procedures. For instance: Sub Initiation() ... End Sub Sub procedure1() ... End Sub Sub…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292