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

Record tokens and their position to use them outside the front-end

I want to write a small beautifier for a specific language. In the beautifier, we will be able to indent one or several lines (ie, adding white-spaces on the left hand of each line); we will also be able to format the whole code (ie, alter…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
1 answer

Attempting to resolve shift-reduce parsing issue

I'm attempting to write a grammar for C and am having an issue that I don't quite understand. Relevant portions of the grammar: stmt : types decl SEMI { marks (A.Declare ($1, $2)) (1, 2) } | simp SEMI { marks $1…
dalastboss
  • 225
  • 2
  • 8
1
vote
1 answer

Get list in grammar

I'm trying to build a compiler and am quite lost at the moment. I have a main class and want to be able to declare additional classes with inheritance, i.e class newClass extends classThatHasBeenDeclaredBefore { } My input looks like input: …
novalain
  • 2,181
  • 19
  • 36
1
vote
2 answers

Operator :: OCaml

I am a beginner in OCaml and trying to build a parser, I want to have a list that stores all the methods in my class. This is one part that I have in my .mly file. init_method_list: { [] } | method_list method_decl { List.rev($1)…
novalain
  • 2,181
  • 19
  • 36
1
vote
1 answer

wrong expression type on ocamlyacc

As part of a school project I have to recognize a .dot file and produce the corresponding parse tree. To accomplish this, I have to use ocamllex and ocamlyacc which whom I've difficulties... This is my ocaml .mli types file : type id = string and…
user3450044
  • 117
  • 9
1
vote
2 answers

What does $1 and $3 in a OCaml parser indicate?

Here's the sample code of an OCaml parser: %{ open Ast %} %token PLUS MINUS TIMES DIVIDE EOF %token LITERAL %left PLUS MINUS %left TIMES DIVIDE %start expr %type < Ast.expr> expr %% expr: expr PLUS expr { Binop($1, Add, $3) } | expr…
P.C.
  • 651
  • 13
  • 30
1
vote
2 answers

OCaml interpreter: evaluate a function inside a function

I'm trying to write an interpreter in OCaml and I have a problem here. In my program, I want to call a function like this, for example: print (get_line 4) // print: print to stdout, get_line: get a specific line in a file How can I do that? The…
Trung Bún
  • 1,117
  • 5
  • 22
  • 47
1
vote
1 answer

OCamllex: regular expression

Currently i'm trying to write an interpretter in Ocaml and this is my lexer.mll: { open Parser exception Eof } rule main = parse [ ' ' '\t' ] { main lexbuf } | [ '\n' ] { EOL } | ['0'-'9']+ as lxm {…
Trung Bún
  • 1,117
  • 5
  • 22
  • 47
1
vote
1 answer

Retrieve a part of parsing by making separate .mly and .mll

I am writing a front-end to parse a set of txt files, each file contains a set of procedures, for instance one txt file looks like: Sub procedure1 ... End Sub Sub procedure2 ... End Sub ... syntax.ml contains: type ev = procedure_declaration…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
1 answer

A table of 2 directions (string <-> token) in parsing

I have defined a hash table keyword_table to store all the keywords of my language. Here is part of the code: (* parser.mly *) %token CALL CASE CLOSE CONST ... reserved_identifier: | CALL { "Call" } | CASE { "Case" } | CLOSE { "Close" } | CONST {…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
2 answers

if then else in ocamlyacc

Can anyone brief how can I implement if then else in Ocamlyacc. I've defined tokens from lexical analyzer(ocamllex) namely IF, THEN, ELSE. For the if statement, I have defined tokens: GREATERTHAN, LESSERTHAN, EQUALTO for integers. I've searched many…
user2352241
  • 81
  • 1
  • 9
1
vote
2 answers

Integer in rules for parser definition - Ocaml

I am running into a problem when compiling the following rule for my parser: %% expr: | expr ASN expr { Asn ($1, $2) } This is an assignment rule that takes an integer, then the assignment (equal sign) and an expression, as defined in my…
Irina
  • 1,333
  • 3
  • 17
  • 37
0
votes
1 answer

Not able to compile MLY file using Dune

I am writing my first Ocamllex and Ocamlyacc program by following this tutorial My dune file looks like (executable (public_name Calculator) (name main)) (ocamllex lexer) (ocamlyacc parser) My lexer.mll file is { open Parser } rule read =…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

How to scan with ocamllex until end of file

I am trying to implement a parser that read regular expression. It ask the user to enter a valid input of string/integers/float. If is valid and the user press ctrl^d, then print the number. Otherwise shows an error. But the problem in the following…
0
votes
1 answer

What does `_ -> ()` mean in OCaml function?

I'm looking at this chun of code (the first 2 lines are pseudo code for context) typ = Void | Bool | Int type bind = typ * string let check_binds (kind : string) (binds : bind list) = List.iter (function (Void, b) -> raise (Failure…
Shisui
  • 1,051
  • 1
  • 8
  • 23