Questions tagged [lex]

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the yacc parser generator. For questions about Amazon Lex, use the tag amazon-lex instead.

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the parser generator.

References:

See also:

Not to be confused with .

1809 questions
8
votes
1 answer

YAML parsing - lex or hand-rolled?

I am trying to write a simple YAML parser, I read the spec from yaml.org, before I start, I was wondering if it is better to write a hand-rolled parser, or use lex (flex/bison). I looked at the libyaml (C library) - doesn't seem to use…
Ani
  • 1,448
  • 1
  • 16
  • 38
8
votes
4 answers

Is it possible to have two or more Lex/Yacc parsers in the same application

I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose. Is it possible to have more than one? And if so how do you get another entry point? Thanks david allan…
David Allan Finch
  • 1,414
  • 8
  • 20
8
votes
3 answers

how to setup flex/bison rules for parsing a comma-delimited argument list

I would like to be able to parse a non-empty, one-or-many element, comma-delimited (and optionally parenthesized) list using flex/bison parse rules. some e.g. of parseable lists : 1 1,2 (1,2) (3) 3,4,5 (3,4,5,6) etc. I am using the following…
sriaudacity
  • 157
  • 1
  • 6
8
votes
2 answers

How can I eliminate the 'main' routine of the flex & bison so I can put the lexing and parsing process into a library?

I'm working on a parser that parses json string and I want to make it a library. The problem is that when I use ld to link the library I wrote, there's a error message: main.o: In function `main': main.c:(.text+0x0): multiple definition of…
mapcan
  • 81
  • 1
  • 2
8
votes
1 answer

Lex/Flex :Regular expression for string literals in C/C++?

I look here ANSI C grammar . This page includes a lot of regular expressions in Lex/Flex for ANSI C. Having a problem in understanding regular expression for string literals. They have mentioned regular expression as \"(\\.|[^\\"])*\" As I can…
sonus21
  • 5,178
  • 2
  • 23
  • 48
8
votes
1 answer

match EOF but go to endless loop in flex

I need to match EOF in flex this is the main error part of my code lex.l %{ %} %% <> {printf("match EOF\n");} %% int main(){ yylex(); } i use flex lex.l ; gcc lex.yy.c -o lex.exe -lfl ; lex.exe < text to execute and this is my text…
bengxy
  • 119
  • 1
  • 6
8
votes
2 answers

What is the difference between lex/yacc and fslex/fsyacc?

I'm learning F# because I'd like to write a lexer and parser. I have a tiny bit of experience with this sort of processing but really need to learn it properly as well as F#. When learning the lexing/parsing functionality of F#, is studying lex and…
Alex Angas
  • 59,219
  • 41
  • 137
  • 210
8
votes
4 answers

Flex: Use Text File as Input Stream

So I've used flex to generate a c file from my lex code, and then used gcc to create the corresponding actual parser .exe. However, I can't figure out how to get it to read from anything other than my own typed input. I am trying to get it to parse…
John Roberts
  • 5,885
  • 21
  • 70
  • 124
8
votes
2 answers

How To Use Flex on Windows

I apologize if this is a dumb question, but I have 0 experience with this tool and wanted to know if I'm going about using it properly. I've downloaded flex which, upon compiling my lex file, produces a C file which then needs to be compiled…
John Roberts
  • 5,885
  • 21
  • 70
  • 124
8
votes
1 answer

Lexer and Parser Generators for Common Lisp

Can you recommend lexer and parser generators for Common Lisp? I have seen the following lists on CLiki, but most on the lists seem to be in their alpha stages: http://www.cliki.net/LEXER http://www.cliki.net/parser%20generator So it would be…
user1628266
  • 81
  • 1
  • 2
7
votes
2 answers

Flex++ bad character error and more. new to flex

we are just getting started using flex to build a lexer for a project, but we cant figure out how to get it to work. I copy the example code given in tutorials and try to run flex++ with the tut file as its argument however I just receive an error…
ElFik
  • 897
  • 2
  • 13
  • 31
7
votes
1 answer

Using Yacc and Lex in Xcode

I have read that Xcode 4 (and I suppose previous versions) have built in support for Yacc and Lex which I am just learning about. I'm trying to set up a simple project to test them out but as I'm new to Xcode and Yacc/Lex I can't seem to figure out…
JPC
  • 8,096
  • 22
  • 77
  • 110
7
votes
1 answer

Using Ocamllex for lexing strings (The Tiger Compiler)

I'm trying to follow Appel's "Modern Compiler Implementation in ML" and am writing the lexer using Ocamllex. The specification asks for the lexer to return strings after translating escape sequences. The following code is an excerpt from the…
nimrodm
  • 23,081
  • 7
  • 58
  • 59
7
votes
1 answer

Flex / Lex Encoding Strings with Escaped Characters

I'll refer to this question for some of the background: Regular expression for a string literal in flex/lex The problem I am having is handling the input with escaped characters in my lexer and I think it may be an issue to do with the encoding of…
Dan
  • 33,953
  • 24
  • 61
  • 87
7
votes
6 answers

What is the regex expression for CDATA

Hi I have an example CDATA here and The CDATA regex i have is not able to recognize this "])*"]]>" this does not work…
Freddy Chua
  • 113
  • 1
  • 1
  • 11