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

filename.l:16: EOF encountered inside an action

I have a lex file like this %{ #include "y.tab.h" %} %% "print" {return print;} "exit" {return exit_command;} [a-zA-Z] {yylval.id = atoi(yytext); return identifier;} [0-9]+ {yylval.num =…
user2493476
7
votes
2 answers

Unable to compile output of lex

When I attempt to compile the output of this trivial lex program: # lex.l integer printf("found keyword INT"); using: $ gcc lex.yy.c I get: Undefined symbols: "_yywrap", referenced from: _yylex in ccMsRtp7.o _input in ccMsRtp7.o …
dstnbrkr
  • 4,305
  • 22
  • 23
7
votes
3 answers

JFlex match nested comments as one token

In Mathematica a comment starts with (* and ends with *) and comments can be nested. My current approach of scanning a comment with JFlex contains the following code %xstate IN_COMMENT "(*" { yypushstate(IN_COMMENT); return…
halirutan
  • 4,281
  • 18
  • 44
7
votes
3 answers

Non-Greedy Regular Expression Matching in Flex

I have just started with Flex and can't seem to figure out how to match the following Expression : "Dog".*"Cat" ------------------ Input : Dog Ca Cat Cc Cat ------------------ Output: Dog Ca Cat Cc Cat But I want a non-greedy matching, with the…
Kyuubi
  • 1,228
  • 3
  • 18
  • 32
7
votes
7 answers

Dynamic (?) parser

Does there exist a parser that generates an AST/parse tree at runtime? Kind of like a library that would accept a string of EBNF grammar or something analogous and spit out a data structure? I'm aware of antlr, jlex and their ilk. They generate…
Ellery Newcomer
  • 1,594
  • 1
  • 11
  • 23
7
votes
3 answers

Lexical Analysis of Python Programming Language

Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: http://www.quut.com/c/ANSI-C-grammar-l-1998.html FYI, I am trying to write code highlighting…
pokstad
  • 3,411
  • 3
  • 30
  • 39
7
votes
5 answers

Multiple flex/bison parsers

What is the best way to handle multiple Flex/Bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from…
Jack
  • 131,802
  • 30
  • 241
  • 343
6
votes
2 answers

SQL lex yacc grammar

All, Developing a validating application for embedded sql i'll use ansi c or c++ as developement language Where do i get an sql grammar for lex and yacc?
user1119406
6
votes
1 answer

What does the ? mean in the tokenization section of the W3C CSS specification?

Ever since my awful experience with cssparser, I have set myself the task of implementing a CSS parser in Java using Parboiled. I already have all color specification covered, but of course I need all the rest... So, I went to look for the CSS…
fge
  • 119,121
  • 33
  • 254
  • 329
6
votes
2 answers

ply lexmatch regular expression has different groups than a usual re

I am using ply and have noticed a strange discrepancy between the token re match stored in t.lex.lexmatch, as compared with an sre_pattern defined in the usual way with the re module. The group(x)'s seem to be off by 1. I have defined a simple…
murftown
  • 1,287
  • 1
  • 10
  • 13
6
votes
3 answers

Parsing: library functions, FSM, explode() or lex/yacc?

When I have to parse text (e.g. config files or other rather simple/descriptive languages), there are several solutions that come to my mind: using library functions, e.g. strtok(), sscanf() a finite state machine which processes one char at a…
Philip
  • 5,795
  • 3
  • 33
  • 68
6
votes
3 answers

What does $$ = $1 + $3 mean in yacc?

Lex part : %% [0-9]+ { yyval = atoi (yytext); return num; } %% Yacc part : %token num %% exp:num '+' num ; {$$ = $1 + $3;} %% In this part of the code what do $$, $1 and $2 stand for? How can I print $$ now? And if I send 5+9 as input to this…
πTh0n
  • 75
  • 1
  • 1
  • 6
6
votes
1 answer

How to use Boost::Spirit::Lex to lex a file without reading the whole file into memory first?

I'm looking at writing a lexer using boost::spirit::lex, but all the examples I can find seem to assume that you've read the entire file into RAM first. I'd like to write a lexer that doesn't require the whole string to be in RAM, is that possible?…
Brian
  • 61
  • 2
6
votes
3 answers

Lex and Yacc without Dynamic Memory Allocation

I'm in the process of designing software to run in an embedded environment where the use of dynamic memory is prohibited. Lex and Yacc are well suited for the application. Can I configure Lex and Yacc to not use dynamic memory allocation at all? …
Chris G
  • 61
  • 1
6
votes
1 answer

Is there any active Lex and Yacc IRC?

Please I am searching for an active Lex and Yacc or Bison IRC - (Internet Relay Chat). Any suggestions are highly appreciated. Thanks in advance for your help!
CompilingCyborg
  • 4,760
  • 13
  • 44
  • 61