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
22
votes
13 answers

How much time would it take to write a C++ compiler using flex/yacc?

How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it?
Madhu
  • 1,176
  • 1
  • 13
  • 18
20
votes
2 answers

CMake and Flex/Bison

I am converting my build system from configure/make to a cmake system The system has some autogenerated files, from bison/flex. The original makefile commands are: bison --defines=tokens.h --output=parser.cpp parser.y flex --outfile=scanner.cpp…
LordAro
  • 1,269
  • 3
  • 18
  • 35
19
votes
4 answers

What does the "yy" in lex.yy.c stand for?

What does the "yy" in lex.yy.c stand for?
phillipwei
  • 1,243
  • 2
  • 12
  • 25
18
votes
1 answer

Is it possible to set priorities for rules to avoid the "longest-earliest" matching pattern?

Another simple question : is there any way to tell flex to prefer a rule that matches a short thing over a rule that matches a longer thing ? I can't find any good documentation about that. Here is why I need that : I parse a file for a pseudo…
m09
  • 7,490
  • 3
  • 31
  • 58
18
votes
3 answers

How to do python-like indentation with flex/bison

I want my language to have two features that make Python such a nicely formatted language: One statement per line Blocks begin with another indentation level and go on until that's ended Can anyone give me a detailed hint on how to achieve that…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
17
votes
1 answer

Lex/Flex - Scanning for the EOF character

Other people have had the following problem that I am having but I can't find anyone that has reported a solution.. getting Flex to spot the EOF (end of file). I need Flex to find EOF and return a token indicating that it has found it so it can…
ale
  • 11,636
  • 27
  • 92
  • 149
17
votes
1 answer

%option noinput nounput: what are they for?

I am new in this, so I wondered why do I need to use these directives %option nounput %option noinput Yeah, I am aware that otherwise I'd have these warnings: lex.yy.c:1237:17: warning: ‘yyunput’ defined but not used [-Wunused-function] static…
zeroDivider
  • 1,050
  • 13
  • 29
16
votes
6 answers

Flex/Bison IDE?

I'm looking for a good development environment in which to work on flex or bison or both. Are there any IDE's that have these capabilities and/or are suitable for this? (If not the next most general question is are there lexer/parser generators with…
machinaut
  • 495
  • 2
  • 4
  • 17
15
votes
2 answers

premature eof error in flex file

I have the following code and it gives an error" "hello.l",line 31: premature EOF" when I run the following command flex hello.l %{ #include #include "y.tab.h" %} %% ("hi"|"oi")"\n" {return HI; } ("tchau"|"bye")"\n" …
Waseem
  • 1,392
  • 5
  • 21
  • 30
15
votes
3 answers

Bison: Optional tokens in a single rule

I'm using GNU Bison 2.4.2 to write a grammar for a new language I'm working on and I have a question. When I specify a rule, let's say: statement : T_CLASS T_IDENT '{' T_CLASS_MEMBERS '}' { // create a node for the statement ... } If I…
Simone Margaritelli
  • 4,584
  • 10
  • 45
  • 70
15
votes
2 answers

#error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"

I have been trying to follow the tutorial at http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/5/ (using flex, bison and llvm) but when typing the line g++ -o parser parser.cpp tokens.cpp main.cpp I get the following errors: In file…
user1361491
15
votes
1 answer

Undefined reference to `_yyerror' when compiling with Flex and Bison

I'm trying to make a compiler for a mini Pascal-like language. I'm using Flex and Bison for this and I came up with this error. My Flex file: %{ #include "y.tab.h" #include #include #include void yyerror(char…
fanulis
  • 175
  • 1
  • 1
  • 9
15
votes
4 answers

Undefined reference to 'yylex()'

I'm trying to use flex and bison to create a simple scripting language. Right now, I'm just trying to get a calculator working. I can't get it to compile, though. When I run this makefile: OBJECTS = hug.tab.o hug.yy.o PROGRAM = hug.exe CPP =…
Micah
  • 183
  • 1
  • 2
  • 9
14
votes
4 answers

Why are multi-line comments in flex/bison so evasive?

I'm trying to parse C-style multi-line comments in my flex (.l) file: %s ML_COMMENT %% ... "/*" BEGIN(ML_COMMENT); "*/" BEGIN(INITIAL); [.\n]+ { } I'm not returning…
adelarge
  • 143
  • 1
  • 5
13
votes
2 answers

How do I write a non-greedy match in LEX / FLEX?

I'm trying to parse a legacy language (which is similar to 'C') using FLEX and BISON. Everything is working nicely except for matching strings. This rather odd legacy language doesn't support quoting characters in string literals, so the following…
stusmith
  • 14,003
  • 7
  • 56
  • 89