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

Haskell parsing tools - yacc:lex :: happy:?

So, it seems like Happy is a robust replacement for yacc in Haskell. Is there an equally robust lexer generator to replace lex/flex?
Geoff
  • 873
  • 1
  • 7
  • 14
11
votes
2 answers

REPL for interpreter using Flex/Bison

I've written an interpreter for a C-like language, using Flex and Bison for the scanner/parser. It's working fine when executing full program files. Now I'm trying implement a REPL in the interpreter for interactive use. I want it to work like the…
Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
11
votes
1 answer

Boost.Spirit: Lex + Qi error reporting

I am writing a parser for quite complicated config files that make use of indentation etc. I decided to use Lex to break input into tokens as it seems to make life easier. The problem is that I cannot find any examples of using Qi error reporting…
Paul Graphov
  • 306
  • 4
  • 11
11
votes
1 answer

Generating a compiler from lex and yacc grammar

I'm trying to generate a compiler so I can pass him a .c file after. I've downloaded both YACC and LEX grammars from http://www.quut.com/c/ANSI-C-grammar-y.html and named them clexyacc.l and clexyacc.y When generating it on terminal I did : yacc -d…
ChasingCars
  • 125
  • 1
  • 1
  • 6
11
votes
2 answers

Getting: warning, rule cannot be matched

I am working on building a lexical and syntax analyzer. I am getting the following warning when I try to use flex with my .l file. littleDuck.l:26: warning, rule cannot be matched Rule 26 is the one that starts with {cteI}, my rules section is the…
gabrielbaca
  • 123
  • 1
  • 2
  • 10
10
votes
1 answer

Unable to recognize single line comments in Lex

Am learning lex in this process, I'm generating tokens for the C language, and am trying to recognize single line comments "//", but am having a conflict with the division operator [1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return…
user265867
  • 101
  • 1
  • 5
10
votes
6 answers

how to use yy_scan_string in lex

I want to parse a string which I give to the parser in the main function of yacc . I know that this could be done by using yy_scan_string but I don't know how to use it. I searched the web and the man pages but it is still not clear to me. Please…
ajai
  • 363
  • 3
  • 6
  • 14
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
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
9
votes
2 answers

Lex - How to run / compile a lex program on commandline

I am very new to Lex and Yacc. I have a Lex program. Example: wordcount.l I am using windows and putty. I am just trying to run this file.. Does the wordcount.l file go on the C drive? Do I compile the Lex program and it generates a .c program and…
user249375
9
votes
2 answers

Ply Lex parsing problem

I'm using ply as my lex parser. My specifications are the following : t_WHILE = r'while' t_THEN = r'then' t_ID = r'[a-zA-Z_][a-zA-Z0-9_]*' t_NUMBER = r'\d+' t_LESSEQUAL = r'<=' t_ASSIGN = r'=' t_ignore = r' \t' When i try to parse…
Karan
  • 11,509
  • 8
  • 34
  • 38
9
votes
1 answer

Fatal error: start symbol does not derive any sentence

Iam trying to develop a program for a calculator using lex and yacc. I keeping getting the following error: calc.y: warning: 5 nonterminals useless in grammar [-Wother] calc.y: warning: 8 rules useless in grammar [-Wother] calc.y:8.1: fatal error:…
Anoop saju
  • 480
  • 3
  • 17
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

Problems with PLY LEX and YACC

I am trying to run the first part of a simple example of the PLY but I encounter a strange error. When I run the following code, it gives me an error regarding lex.lex() Anyone knows what the problem is? import ply.lex as lex tokens = […
sabzdarsabz
  • 343
  • 5
  • 15
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