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

Can a flex/bison parser accept at most one token from a set in any order

In my language, at a specific point I need to accept at most one token from a set of tokens. To give an example, a parenthesized expression may be followed by at most one of !^& in any order, so the following 2 lines should be…
0
votes
1 answer

best way to scan number of files with a specific header using Lex/yacc?

I have defined my own grammar using yacc.My language gives user a flexibility to supply a extra header explicitly while invoking compiler which will be applicable to each of file to be compiled using my compiler. I can think of two solutions to work…
Ankur Gautam
  • 1,412
  • 5
  • 15
  • 27
0
votes
1 answer

My Lex code receiving segmentation fault (core dump) at line *yy_cp = yy_hold_char

Here a snippet of generated .c code from .Lex. And the Coredump is coming at the very first Iteration while (1) /* loops until end-of-file is reached */{ yy_cp = yy_c_buf_p; /* Support of yytext. */ *yy_cp = yy_hold_char; //…
mik
  • 73
  • 8
0
votes
1 answer

Compilation error. How to parse variable name using lex / yacc?

In my lex file I have: [a-zA-Z][a-zA-Z0-9]* { yylval.val = _strdup(yytext); // <- error here yylval.length = yylen; return id; } ... for parsing text such as "myid2" This is causing a compilation error: error C2143: syntax error :…
gornvix
  • 3,154
  • 6
  • 35
  • 74
0
votes
1 answer

How to get more parse error information from lex / yacc?

How to get more parse error information from lex / yacc? Currently in the lex file I am using: int yyerror(const char *msg) { fprintf(stderr, "Parse error: %s\n", msg); return 0; } But when I run my program yyerror outputs a blank message. …
gornvix
  • 3,154
  • 6
  • 35
  • 74
0
votes
1 answer

Compilation errors in a C++ program for parsing a file using lex and yacc

I want to read a file in a C++ program and pass it on to lex and yacc for parsing, but I am getting compilation errors. Here is my main.cpp file (with the first error): extern "C" { #include "parser_iface.h" #include "parser.h" …
gornvix
  • 3,154
  • 6
  • 35
  • 74
0
votes
1 answer

Lexical Analyzer with YACC, identifing for loop

lex file %% ^((for)|(while))[(][)] return FORWHILE; [ ]* return SPACE; ([a-z ]+[;])+ return LINE; . ; %% yacc file %start s %token FORWHILE %token SPACE %token LINE %% s: FORWHILE SPACE '{' SPACE LINE SPACE '}' SPACE { printf("Data…
Signer3
  • 101
  • 1
  • 1
  • 8
0
votes
2 answers

How to disable parsing for a piece of text in a file?

Structure of my file is : `pragma TOKEN1_NAME TOKEN1_VALUE `pragma TOKEN2_NAME TOKEN2_VALUE `pragma TOKEN3_NAME TOKEN3_VALUE `pragma TOKEN4_NAME TOKEN4_VALUE VHDL_TEXT{ // A valid VHDL text goes here. } `pragma TOKEN2_NAME TOKEN2_VALUE …
Ankur Gautam
  • 1,412
  • 5
  • 15
  • 27
0
votes
1 answer

Can't get my head around creating unambiguous grammar for if else

This is from a tutorial our professor wrote and I can't get my head around it. I can come up with derivation but I can't come up with grammar by just analyzing the derivation. What does "matched" refer to in this context? Can you explain how…
mmswe
  • 707
  • 2
  • 8
  • 20
0
votes
1 answer

Why is lex trying to match the whole line instead of just a token?

I have this lex file: COMMENT \#.*\n SPACE [\x20\n\r\t] L [a-zA-Z_] D [0-9] %% {COMMENT} | {SPACE}+ ; {L}({L}|{D})* { printf("identifier token: %s\n", yytext); return 1; } -?{D}* …
Luis Masuelli
  • 12,079
  • 10
  • 49
  • 87
0
votes
1 answer

Segmentation fault yacc/lex

I've got this segmentation fault on my code. It seems that it appears right after the first variable declaration. Any ideas how can I get rid of this error? Here is a part of my code. lex file: %{ #include #include "comp-func.h" #include…
user3586734
0
votes
1 answer

recognize fractional numbers in JFlex 1.4.3

in my SL.lex file i have this regular expression for fractional numbers: Digit = [1-9] Digit0 = 0|{Digit} Num = {Digit} {Digit0}* Frac = {Digit0}* {Digit} Pos = {Num} | '.' {Frac} | 0 '.' {Frac} | {Num} '.' {Frac} PosOrNeg = -{Pos} | {Pos} Numbers…
kitsuneFox
  • 1,243
  • 3
  • 18
  • 31
0
votes
1 answer

Does this example lex code leak file handles?

I'm including files within the scope of my lex grammar, and looking at the example code taken from the flex manual, I wondered if the file handles being consumed were not being released. I drilled through the generated code starting at…
Jamie
  • 7,075
  • 12
  • 56
  • 86
0
votes
2 answers

How to re-launch the scan in LEX

I am trying to do a conversor from markdown syntax to Latex and vice versa. But I am facing a problem I can not solve so far. Lets say, we have the following text: * item * item * _Italic_ item * Item with __nested _italic_ text__ Right now, my…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
0
votes
2 answers

How to tell if an identifier is being assigned or referenced? (FLEX/BISON)

So, I'm writing a language using flex/bison and I'm having difficulty with implementing identifiers, specifically when it comes to knowing when you're looking at an assignment or a reference, for example: 1) A = 1+2 2) B + C (where B and C have…
Chris Phillips
  • 1,997
  • 2
  • 19
  • 34
1 2 3
99
100