Questions tagged [ocamllex]

ocamllex is a Lexer generator for OCaml

ocamllex is the lexer generator for OCaml. It is based on lex (now better known as flex).

It is used within the OCaml compiler, and thus, it is installed by the official OCaml distribution. ocamllex is powerful and nicely integrated within OCaml.

For simple uses, a simple lexer generator is also available in the Genlex module of the standard library, and allows to lex files with a syntax similar to OCaml ( (..) for comments, same escape sequences in strings, etc.).

References:

See also:

94 questions
0
votes
1 answer

character 0: character set expected

I want to define a table name by regular expression defined here such that: Always begin a name with a letter, an underscore character (_), or a backslash (). Use letters, numbers, periods, and underscore characters for the rest of the…
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

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

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

Why can't I use module in my lex file?

This is what I currently have for my mll file which runs just fine. { type token = EOF | Word of string } rule token = parse | eof { EOF } | ['a'-'z' 'A'-'Z']+ as word {Word(word)} | _ { token lexbuf } { let lexbuf =…
Nathan
  • 2,699
  • 5
  • 30
  • 44
0
votes
1 answer

Changing the State of Lexing.lexbuf

I am writing a lexer for Brainfuck with Ocamllex, and to implement its loop, I need to change the state of lexbuf so it can returns to a previous position in the stream. Background info on Brainfuck (skippable) in Brainfuck, a loop is accomplished…
Pandemonium
  • 7,724
  • 3
  • 32
  • 51
0
votes
1 answer

How will I implement the lexing of strings using ocamllex?

I am new to the concept of lexing and am trying to write a lexer in ocaml to read the following example input: (blue, 4, dog, 15) Basically the input is a list of any random string or integer. I have found many examples for int based inputs as most…
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

Common way to store positions in a formatter

I want to write a small editor for a specific language. In the editor, 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 white-spaces and…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

Order of precedence in lexer

I am writing a lexer and a parser for Excel formulas. In Excel, we could assign a cell a name. For example, abc is a valid name, whereas, it is forbidden to name a cell B2 to avoid the confusion with the cell B2. So once we meet a formula =B2, we…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
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
1 answer

FsLex FsYacc: How to create a language with a multi-line comment

I am playing around with FsLex and FsYacc, which is based off of ocamllex and ocamlyacc. What is the best way to define a comment in a language? Do I create a comment token in my lex file? There are a few complications to to comments that I cannot…
Phillip Scott Givens
  • 5,256
  • 4
  • 32
  • 54
0
votes
1 answer

Printing an RLE list in OCaml

If I call my runlength encode program with encode[1;1;2], I get int encode list = [Multiple (1, 2); Singles 1] How would I get a bracket () for the Singles as well so it would be like [Multiple (1, 2); Singles (1)]?
andyph666
  • 23
  • 4
0
votes
1 answer

ocamllex regex syntax error

I have some basic ocamllex code, which was written by my professor, and seems to be fine: { type token = EOF | Word of string } rule token = parse | eof { EOF } | [’a’-’z’ ’A’-’Z’]+ as word { Word(word) } | _ { token lexbuf } { (*module…
xamvolagis
  • 15
  • 1
  • 3