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

Is this an example of casting in Ocaml, unclear on what this line is doing?

I am looking at a codegen.ml file being used to create LLVM IR. I am unfamilar with Ocaml so just require some clarification let i32_t = L.i32_type context and float_t = L.double_type context let ltype_of_typ = function A.Int…
Shisui
  • 1,051
  • 1
  • 8
  • 23
0
votes
0 answers

Is there precedence to listing out tokens in a parser.mly file?

Like if I have some tokens listed at the beginning of my parser like so %{ open Ast %} %token SEMI LPAREN RPAREN LBRACE RBRACE COMMA PLUS MINUS TIMES DIVIDE ASSIGN %token NOT EQ NEQ LT LEQ GT GEQ AND OR %token RETURN IF ELSE FOR WHILE INT BOOL…
Shisui
  • 1,051
  • 1
  • 8
  • 23
0
votes
1 answer

I have difficulties with two problems with the langage OCaml

Important: I am only allowed to use List.head, List.tail and List.length No List.map List.rev ...........etc Only List.hd, List.tl and List.length How to duplicate the elements of a list in a list of lists only if the length of the list is odd Here…
TAB ALI
  • 9
  • 3
0
votes
2 answers

OCaml: pell function with int lists

I am trying to write a simple function in OCaml let rec pell (i: int) = (if i <= 2 then i (*if given n is less tahn 2 then return 2, else return previous n-1 th term and n-2 nd term recursively*) else if i>2 then 2 * pell i - 1 + pell i -…
Vicky
  • 25
  • 5
0
votes
2 answers

OCaml: simple assignment to represent a list of ints

Hello I am learning the OCaml language and working on an assignment. infinite precision natural numbers can be represented as lists of ints between 0 and 9 Write a function that takes an integer and represents it with a list of integers between 0…
Vicky
  • 25
  • 5
0
votes
1 answer

Set a rule based on the value of a global variable

In my lexer & parser by ocamllex and ocamlyacc, I have a .mly as follows: %{ open Params open Syntax %} main: | expr EOF { $1 } expr: | INTEGER { EE_integer $1 } | LBRACKET expr_separators RBRACKET { EE_brackets (List.rev $2)…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

Make lexer consider parser before determining tokens?

I'm writing a lexer and parser in ocamllex and ocamlyacc as follows. function_name and table_name are same regular expression, i.e., a string containing only english alphabets. The only way to determine if a string is function_name or table_name is…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

Parser stop mid-parse

I am completely out of ideas. I spend every free minute this day on this, but I am completely out of ideas. This is my Ocamlyacc grammar: input: /* empty */ { } | input stmt { } stmt: extern { print_endline "Got an extern import" } |…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
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
2 answers

Ocaml stringmap calculator AST parse not adding or finding

Very close to getting this to work but having trouble with StringMap from OCaml. Essentially I'm making a calculator which takes in from ocamllex the lexical stream ... so here commas are supposed to separate out our expressions while equal signs…
0
votes
0 answers

ocaml parser "values do not match" error

IHello! I'm trying to code a lexer and parser for computer algebric system. When I'm compiling the code with my makefile, I have problems on the value of some functions. Here is the code of function.ml : (**************************************** …
0
votes
1 answer

Ocamlyacc seemingly not returning a full record

I have the following parser which should return a record with globalVars and globalFns, but it doesn't appear to. %start program %type program %% program: decls EOF { $1 } decls: /* nothing */ { { globalVars =…
Nathan
  • 2,699
  • 5
  • 30
  • 44
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
2 answers

Yacc NULL in OCaml?

I am implementing the following grammar in OCamlyacc and OCamllex: The OCaml type declaration for my IF-ELSE clauses is as such: (* Some code not shown *) and stmt = ASSIGN of lv * exp | IF of exp * stmt * stmt | WHILE of exp * stmt …
Code Doggo
  • 2,146
  • 6
  • 33
  • 58
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