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
18
votes
5 answers

what is the difference between lex and yacc

I have worked with lex for executing some code whenever some regular expression is found, Can Yacc do something more than that? If yes, then what?
Manik Mahajan
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
2 answers

Reasons for using lex/yacc alternatives?

About once a year I have to develop or at least design a grammar and a parser - that appears a constant of my working life. Every time I'm facing this task, thus about once year, I, quite a lex/yacc (flex/bison resp.) guy, consider, or reconsider,…
Solkar
  • 1,228
  • 12
  • 22
15
votes
3 answers

Any differences between terms parse trees and derivation trees?

The terms AST (Abstract Syntax Tree), parse tree and derivation tree are bandied about by different people when referring to the result of parsing texts conforming to a grammar. Assuming we are talking about parsing computer languages, are their…
Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64
15
votes
1 answer

Simple Flex/Bison C++

I already looked for my answer but I didn't get any quick response for a simple example. I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things. Searching over internet I've…
Jack
  • 131,802
  • 30
  • 241
  • 343
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
3 answers

Lex case insensitive word detection

I need to treate a string in C where certain words, if present, have to be converted to uppercase. My first choice was to work it in LEX something like this: %% word1 {setToUppercase(yytext);RETURN WORD1;} word2 {setToUppercase(yytext);RETURN…
jordi
  • 1,157
  • 1
  • 13
  • 37
14
votes
5 answers

How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)

I want my yylex() to parse a string rather than a file or standard input. How can I do it with the Lex and Yacc provided with Solaris?
ajai
  • 363
  • 3
  • 6
  • 14
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
13
votes
5 answers

Is there a Sublime Text Syntax for Flex and Bison?

I'm looking for a syntax in Sublime Text that highlights my Flex and Bison files (or lex/yacc) in a way that makes them readable... Sublime Text automatically chooses Lisp for Flex files, but that doesn't do the trick all that well. Any suggestions…
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
13
votes
5 answers

bison end of file

If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not…
user34537
12
votes
6 answers

How do I remove the following 'implicit declaration of function' warnings?

How do I compile the lex file with gcc without receiving the following warnings? lex.yy.c: In function `yy_init_buffer': lex.yy.c:1688: warning: implicit declaration of function `fileno' lex.l: In function `storeLexeme': lex.l:134: warning:…
idealistikz
  • 1,247
  • 5
  • 21
  • 35
12
votes
3 answers

Looking for a Java grammar in lex/yacc format

Does anyone know an online repository for lex/yacc format grammars? I'm looking for a Java grammar to make a quicky sourcecode converter. Thank you! edit: I'm preferably looking for lex/yacc because I want to use fslex/fsyacc with as little grammar…
12
votes
2 answers

How can I implement #include constructs with Flex and YACC?

During parsing, if I encounter a include token I want to instruct YACC to open the file specified as input and to begin parsing this. Once this parsing is finished, I want to instruct YACC to return to the file and continue parsing directly after…
Gozzy
  • 121
  • 1
  • 3
12
votes
9 answers

Flex and Yacc - Cannot find - lfl?

Hi I'm learing Lex and yacc. I created the following lex program. %{ #include %} %% [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% I'm trying to run it using the following commands: lex…
sap
  • 1,141
  • 6
  • 41
  • 62