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
5
votes
1 answer

Emacs TAGS table is confused by #line directive in lex/yacc files

I am trying to generate TAGS tables using etags for a large software project. The TAGS file ends up having entries to non-existent files at top level instead of the existent ones in a sub-directory due to #line directives in the lex/yacc generated…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
5
votes
1 answer

Common difficulty with Flex++

Note: Someone with over 1500 rep.. please add flex++ and bison++ as tags :). Seems like people all over the Internet have been getting the following errors with Flex++: scanner.l:1: bad character: % scanner.l:1: unknown error processing section…
ale
  • 11,636
  • 27
  • 92
  • 149
5
votes
4 answers

How can I use the flex lexical scanner generator as part of my program?

How can I use a scanner I've written using Flex as part of a program I'm designing? Specifically, within a c++ class as a method of the class, and from a separate file with just a main method to perform testing. I don't wish to use the %option c++,…
mcorley
  • 767
  • 12
  • 21
5
votes
3 answers

How do lexical analyzers handle comment and escape sequences?

Comment and escape sequence (such as string literal) are very exceptional from regular symbolic representation. It's hard to understand for me how does regular lexical analyzers tokenize them. How do lexical analyzers like lex, flex, or etc..…
eonil
  • 83,476
  • 81
  • 317
  • 516
5
votes
3 answers

How do you deal with keywords in Lex?

Suppose you have a language which allows production like this: optional optional = 42, where first "optional" is a keyword, and the second "optional" is an identifier. On one hand, I'd like to have a Lex rule like optional { return OPTIONAL; },…
wvxvw
  • 8,089
  • 10
  • 32
  • 61
5
votes
1 answer

Dart - Split String by RegEx

I am trying to split a string like this: x^-5 - 3 into a list like this: [x^-5, -, 3] The first minus after the ^ must be at the same list index as the x, because it's just the negative exponent. However, I want other minuses, which are not an…
OhMad
  • 6,871
  • 20
  • 56
  • 85
5
votes
3 answers

Change yyin to argv[1] Flex & Bison

I'm working on a Flex & Bison project. I got my flex & bison perfectly working but I'm trying to give argv as the input (yyin). So I've changed yyin so that it took the argv[1] but it's actually not working. It seem that it took the argv[1] but then…
G.Courmont
  • 187
  • 2
  • 10
5
votes
2 answers

In lex, how do I differentiate between '-' (subtraction) operator and an integer '-3'?

I am writing lex for a specific language where operations are carried out in prefix notation : (+ a b) --> (a + b) An integer is defined as follows : An integer can have a negative sign (–) but no positive sign. It can be with or without space(s)…
ronakshah725
  • 290
  • 3
  • 10
5
votes
2 answers

How to create a regex without certain group of letters in lex

I've recently started learning lex , so I was practicing and decided to make a program which recognises a declaration of a normal variable. (Sort of) This is my code : %{ #include "stdio.h" %} dataType "int"|"float"|"char"|"String" alphaNumeric…
mariuss
  • 1,177
  • 2
  • 14
  • 30
5
votes
2 answers

When is it practical to use a parser generator?

I'm writing a simple text-template language for a web application I'm writing (think google's ctemplate). When finished, it'll feature only a small number of possible actions, simple stuff like "evaluate and execute", "evaluate and print", "evaluate…
lazyconfabulator
  • 477
  • 2
  • 6
  • 13
5
votes
2 answers

unrecognized rule in lex

I'm writing a program in lex, and it gives me the following error: scanner.l:49: unrecognized rule Line 49 is: {number} {return(NUM);} EDIT: However, the error seems related to the line directly before that, {id} {return(ID);}. It will list…
Max
  • 65
  • 1
  • 2
  • 6
5
votes
1 answer

how to detect error line number using yacc parser

We have no idea on how to track errors in yacc parser. We're trying to use yylineno in our lex file and tried adding %option yylineno but it's still not workin', we cannot access these variables in yacc. All we want is to print out the syntax error…
Aron
  • 129
  • 1
  • 3
  • 13
5
votes
2 answers

Library to parse ERB files

I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type manner. The files I am attempting to parse contain HTML fragments intermixed with dynamic content generated using ERB (standard rails view files) I am looking for a…
Douglas Sellers
  • 652
  • 2
  • 7
  • 13
5
votes
3 answers

Bison : Line number included in the error messages

OK, so I suppose my question is quite self-explanatory. I'm currently building a parser in Bison, and I want to make error reporting somewhat better. Currently, I've set %define parse.error verbose (which actually gives messages like syntax error,…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
5
votes
2 answers

where to find a real example on flex and bison?

i need a n example on flex and bison , so i can learn how to build ast tree and symbol table and do semantic analysis
Radi
  • 6,548
  • 18
  • 63
  • 91