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
10
votes
2 answers

Jison global variables

In previous versions of Jison, it was possible to have a Flex-like feature that allowed defining variables accessible in both the lexer and parser contexts, such as: %{ var chars = 0; var words = 0; var lines = 0; %} %lex %options flex %% \s [^…
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
10
votes
3 answers

How should I handle lexical errors in my Flex lexer?

I'm currently trying to write a small compiler using Flex+Bison but I'm kinda of lost in terms of what to do with error handlling, specially how to make everything fit together. To motivate the discussion consider the following lexer fragment I'm…
hugomg
  • 68,213
  • 24
  • 160
  • 246
10
votes
3 answers

What are the disadvantages of using ANTLR compared to Flex/Bison?

I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about ANTLR. Would you recommend that I learn ANTLR or better to brush up Flex/Bison? Does ANTLR…
user855
  • 19,048
  • 38
  • 98
  • 162
10
votes
1 answer

in lex how to make yyin point to a file with the main function in yacc?

I am storing the arguments passed to main in yacc in a file. Now I want the lex to read its input from this file rather than the terminal. I know I can point yyin to a file like yyin = fopen("fn","r"); but this works only when main is in lex. When…
ajai
  • 363
  • 3
  • 6
  • 14
10
votes
5 answers

How to fix a missing ld library for -lfl while compiling?

I am trying to translate my .spl file into a C file (because there is no compiler). I have an example "Hello World" .spl file, and I have downloaded the Shakespeare Programming Language .tar and extracted it, but I have no idea what to do next. I…
9
votes
2 answers

Creating comments in Lex and Yacc

How does one make a comment in Lex and Yacc? So far I haven't tried Yacc, but in Lex I have tried /* comment */ and // comment, but neither of these compile. I am on a Mac, using the builtin Lex and Yacc compilers, (or maybe the X-Code ones, I don't…
jellies
  • 639
  • 1
  • 5
  • 17
9
votes
2 answers

Emacs modes for flex and bison, or removing auto indent for these modes?

Emacs has poor handling of auto-indentation in Flex and Bison. In fact, it seems to have no support for flex mode. So, how does an emacs user cope with these? I like VIm but I would prefer not to switch because I am much faster and more comfortable…
Kizaru
  • 2,443
  • 3
  • 24
  • 39
9
votes
1 answer

What is the meaning of yytext[0]?

What is the meaning of yytext[0]? And why should we use in the lex and yacc program? I'm learner so don't mind if it is a silly question.
sandy
  • 149
  • 1
  • 2
  • 8
9
votes
1 answer

Writing re-entrant lexer with Flex

I'm newbie to flex. I'm trying to write a simple re-entrant lexer/scanner with flex. The lexer definition goes below. I get stuck with compilation errors as shown below (yyg issue): reentrant.l: /* Definitions */ digit [0-9] letter …
Viet
  • 17,944
  • 33
  • 103
  • 135
9
votes
2 answers

Using Flex (the lexical analizer) on OS X

I've got a file, test.lex, which I run through as $ flex test.lex That gives me lex.yy.c, which I try to compile with: $ gcc lex.yy.c -lfl This gives me the error ld: library not found for -lfl. I know the Flex specification is correct and…
Haden Pike
  • 259
  • 2
  • 7
9
votes
1 answer

Flex seems do not support a regex lookahead assertion (the fast lex analyzer)

When I tried to use regex in flex as following to define an int type: int (?
stanleyerror
  • 728
  • 1
  • 9
  • 23
9
votes
1 answer

Flex yylineno set to 1

I'm writing a simple parser for tcpdump logs, could you please tell me why I can't get proper line number? %{ char str[80]; %} %option yylineno ... %% ^{HOURS}:{MINUTES}:{MINUTES} if(input()=='.') { strcpy(str, yytext); BEGIN(A); } else…
Wojciech Reszelewski
  • 2,656
  • 2
  • 18
  • 27
9
votes
2 answers

Regular expressions - Matching whitespace

I am having a big problem to write a regexp that will trim all the whitespace in my input. I have tried \s+ and [ \t\t\r]+ but that don't work. I need this because I am writing a scanner using flex, and I am stuck at matching whitespace. The…
mrjasmin
  • 1,230
  • 6
  • 21
  • 37
9
votes
3 answers

Is there a flex - bison parser for javascript?

Is there a parser available in the open ? Else, i'm planning to write one using the grammar rules in http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf Thanks.
trinity
  • 10,394
  • 15
  • 49
  • 67
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