Questions tagged [flex-lexer]

Flex (fast lexical analyzer generator) is a free software that generates lexical analyzers ("scanners" or "lexers").

Flex (fast lexical analyzer generator) is a free software that generates lexical analyzers ("scanners" or "lexers"). It is frequently used with the free Bison parser generator. Unlike Bison, flex is not part of the GNU Project. You can (and should) read the manual which can be found here.

See also:

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

How can I debug my flex/bison grammar?

This is a very silly problem. There are no errors in the grammar rules afaik but its not giving the right output. I have been staring at it but the mistake is not visible to me. What tools are available to me to help me see what is going on in a…
afsara_ben
  • 542
  • 1
  • 11
  • 30
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
5 answers

How can I parse a C string (char *) with flex/bison?

In my programming project I want to parse command line attributes using flex/bison. My program is called like this: ./prog -a "(1, 2, 3)(4, 5)(6, 7, 8)" filename Is it possible to parse this string using flex/bison without writing it to a file and…
Philipp Riegger
  • 127
  • 1
  • 1
  • 6
8
votes
2 answers

Problems with reentrant Flex and Bison

I'm learning how to use reentrant Bison and Flex together. I already got a simple calculator working without the reentrant capability. However when I activated the reentrant feature and made the necessary modifications, I couldn't get this to work.…
Fabricio
  • 343
  • 1
  • 5
  • 11
8
votes
1 answer

freeing the string allocated in strdup() from flex/bison

I have flex code that copies a string lexeme using strdup(). %{ #include "json.tab.h" #define YY_DECL extern "C" int yylex() %} %option noyywrap %% [ \t\n]+ ; \"[a-zA-Z]+\" {yylval.sval = strdup(yytext); return STRING; } [0-9]+ {yylval.ival…
prosseek
  • 182,215
  • 215
  • 566
  • 871
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
2 answers

malloc() returning address that I cannot access

I have a C++ program that calls some C routines that are generated by Flex / Bison. When I target a Windows 8.1 64-bit platform, I hit the following exception at runtime: Unhandled exception at 0x0007FFFA70F2C39 (libapp.dll) in application.exe:…
tomocafe
  • 1,425
  • 4
  • 20
  • 35
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
3 answers

Compiling and executing the Shakespeare Programming Language translator spl2c on Mac OS X 10.6 results in warnings/errors

I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make. The compilation of spl2c executes with a couple warnings: scanner.l:600: warning, rule cannot be…
Redwood
  • 66,744
  • 41
  • 126
  • 187
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
5 answers

flex: undefined reference to `yywrap' only when compiling/linking separately

I've been learning to use Flex (the lexical analyser) and I've been compiling with the following command: gcc -lfl -o test lex.yy.c and all is well. However, I want to link it with other files, so I compile and link it separately with gcc -c…
Flukiluke
  • 85
  • 1
  • 1
  • 3
8
votes
2 answers

How do I implement a two-pass scanner using Flex?

As a pet-project, I'd like to attempt to implement a basic language of my own design that can be used as a web-scripting language. It's trivial to run a C++ program as an Apache CGI, so the real work lies in how to parse an input file containing…
dmercer
  • 397
  • 5
  • 17