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
Filter by
Sorted by
Tagged with
1 vote
1 answer
392 views

Bison/Yacc still printing debug messages despite tracing being explicitly disabled

I am using flex and bison on windows from this repository along with Visual Studio 2019 to produce a small calculator application. Earlier I enabled bison debug messages through the build properties ...
BenLewis's user avatar
  • 127
-1 votes
1 answer
118 views

Regular expression matching with re but not lex

I am trying to parse a file in order to reformat it. For this, I need to be able to distinguish between full line comments and end of line comments. I have been able to get lex to recognize full line ...
Eric's user avatar
  • 3
1 vote
2 answers
957 views

Handling new lines in Flex/Bison

I am trying to make a C-like language using Flex/Bison. My problem is that I can't find a proper way to handle new lines. I have to ignore all new lines so I don't returnt them as a token to Bison ...
John Baker's user avatar
0 votes
1 answer
119 views

Yacc parse won't finish reduction of a production

I am working on building a small interpreter through lax and yacc that works on a basic programming language that performs addition and multiplication as well as printing lists of ints. For example ...
Geoffery Crawford's user avatar
0 votes
1 answer
203 views

Yacc not accepting valid input

I am using Bison/Flex to create a compiler for a C-like (simplified version of C) language. I am trying to implement arrays and I am running into an issue and I can not find the source of the error. I ...
sengineer23's user avatar
0 votes
1 answer
342 views

How to make a parse function receiving string as argument regarding lex and yacc? [duplicate]

I want to write a parser that provides API like const char *convertA2B(const char *input). It looks like: lex_and_yacc(input) -> myADT myADT.intepret() -> ouptut In yacc, there's int yyparse(...
delta's user avatar
  • 3,808
0 votes
0 answers
113 views

Way to create productions for boolean operands in Bison

I'm creating a parser in Bison, and I am trying to convert the rules: E := E op E op := + | - | > | & There are other rules for E, such as negation, and of course, E can be a number. I was ...
Naz1706's user avatar
0 votes
1 answer
528 views

How to invoke yyerror() from flex?

I have yyerror() defined in my Bison file: parser.y ... %code { void yyerror(YYLTYPE* yyllocp, yyscan_t unused, const char** errorReturn, const char* msg); } ... void yyerror(YYLTYPE* yyllocp, ...
Tom's user avatar
  • 1,235
1 vote
1 answer
476 views

How to write a regex in lex that negates the whitespaces

I am new to Lex (Flex) and I am solving a question that asks me to write a lex program that copies a file, replacing each non-empty sequence of whitespace by a single blank. Here is what I have tried %...
Prithvi singh's user avatar
0 votes
1 answer
58 views

flex's unrecognized rule (about an optional phrase)

I wrote a simple flex file: %{ #include "question.tab.h" %} %% COMMON(/[45]\.0)? return GOTCHA; [a-z]+ return ETC; %% and tried to compile.(flex -d question.l) Then the ...
plhn's user avatar
  • 5,177
0 votes
1 answer
974 views

cannot find -ll collect2: error: ld returned 1 exit status

I got a similar error when I tried to compile my lex.yy.c file generated from lex helloworld.l using gcc lex.yy.c -ll in cygwin. The helloworld.l contains %% [0-9]+ { printf("saw an integer:%s\n&...
Free Man's user avatar
0 votes
1 answer
633 views

How to print shift or reduce grammar rule? (flex,bison)

I'm trying to implement a C grammar parser with lex & yacc and show the reducing procedure. I have to print token list on the left and shift or reduce rule on the right. Like: 2*4+4/2 //iniput ...
Hwing's user avatar
  • 1
0 votes
2 answers
271 views

regex detecting single line

Need regex for detecting string in only single line,i tried this regex \"(\\.|[^"\\])*\" but this works also with multiline input: Example : this is a "string and the string ends ...
Hassene's user avatar
0 votes
2 answers
898 views

regular expression in lex

I want to print only when the whole line matches the pattern. But that's if even part of the line matches the pattern, it prints out. How should I use regular expressions?
boyman's user avatar
  • 1
0 votes
1 answer
342 views

Syntax error by Yacc even though the syntax is per grammar

My yacc parser is showing syntax error even though the syntax is as per grammar. my Yacc code: %{ void yyerror (char *s); #include <stdio.h> #include <stdlib.h> #include &...
vashist99's user avatar
0 votes
0 answers
195 views

Why `string` `vector` etc does not work in union in bison?

I was trying to write a parser for a subset of C language . But when I include string or vector inside the %union , it throws error . Using char* or array seems to be fine . %union{ string s; ...
Zarif's user avatar
  • 465
1 vote
1 answer
190 views

Bison/Flex parsing issue

I am working with bison and flex and am currently have some issues. Currently the first character is read and passed to Bison, but immediately yyerror() is thrown. It should print 1 as 'w' is an ...
sengineer23's user avatar
1 vote
2 answers
472 views

Flex & Bison: "true" being interpreted as and ID

I am writting a parser and a scanner in Ubuntu OS. In my flex code "scanner.l" I have an IDENTIFIER token and BOOL_LITERAL token. IDENTIFIER is any word and BOOL_LITERAL is either true or ...
Christopher Barrios Agosto's user avatar
0 votes
0 answers
95 views

Implement LEX program by using EBNF & Syntax diagram

I have created the following syntax diagram and EBNF meta-language structure of it. My ENBF structure, var_part = var [identifier { "," identifier } ":" type "κ" { }]. ...
Alex_Pap's user avatar
  • 442
0 votes
3 answers
153 views

Regex that does not match ( and ), but matches '(' and ')'

I am trying to fix a regular expression used in tokenization so as to match everything (including '(' and ')', but not match ( and ) without being surrounded by apostrophes). Use case examples which ...
Theodor Badea's user avatar
0 votes
0 answers
40 views

how can i use ^ expression properly in Flex?

I am trying to use the ^ expression to get any string that is not certain characters, but I can't seem to figure it out. this is what I am trying to do STRING [^<>"<!...
bendush's user avatar
  • 23
0 votes
1 answer
1k views

Starting a parser for scheme language

I am writing a basic parser for a Scheme interpreter and here are the definitions I have set up to define the various type of tokens: # 1. Parens Type: PAREN Subtype: LEFT_PAREN Value: '(' ...
carl.hiass's user avatar
  • 1,656
0 votes
1 answer
126 views

Regular expression in FLEX finding text

I got lex file with this rule: %option noyywrap %{ %} LNA [^<>] LNANA [^<>!] %% (<!!) fprintf(yyout, "begin_comment\t\t\t%s\n", yytext); (!!>) fprintf(yyout, &...
Max Boyar's user avatar
1 vote
1 answer
690 views

How to achieve capturing groups in flex lex?

I wanted to match for a string which starts with a '#', then matches everything until it matches the character that follows '#'. This can be achieved using capturing groups like this: #(.)[^(?1)]*(?1)(...
Sourav Kannantha B's user avatar
0 votes
1 answer
133 views

Rule-patterns used by (f)lexers

I walked through a number of lex files and in some I found some strange constructs regarding the usage of the square brackets. I would expect that inside square brackets it is possible to use other ...
albert's user avatar
  • 8,613
1 vote
1 answer
1k views

Can we use BNF for parsing AND lexing instead of regex?

With a Backus-Naur form grammar (BNF), we can specify the syntax of the programming language in order to parse it and produce an abstract syntax tree (AST). <if> ::= "if" <...
Xitog's user avatar
  • 29
0 votes
1 answer
32 views

Unable to find cause of 'syntax error' in Bison code

I'm trying to connect simple flex and bison code that would just recognize a character for now. Yet I'm facing this error. I've read through a lot of answers to figure out what is wrong but am lost. ...
koulini k satya's user avatar
1 vote
0 answers
209 views

Error when trying to run parsing program using lex and yacc

i am trying to use lex and yacc for a laboratory on linux but i got an error. These are my 3 commands in the terminal: lex scan.l -> generates lex.yy.c (the lexical analyser) yacc -d gram.y -> ...
Jurca Bg's user avatar
0 votes
2 answers
64 views

What decides which production the parser tries?

I am trying to build a parser for a desk calculator and am using the following bison code for it. %union{ float f; char c; // int } %token <f> NUM %token <c> ID %type <f&...
Chaitanya Chavali's user avatar
0 votes
1 answer
280 views

How to pick only first N number of characters and drop remaining while matching pattern in LEX/FLEX

I need to write Lex/Flex code to recognize Identifiers. Here, Identifiers is defined as - Identifiers- It can have alpha (lowercase) numeric combination, start with alphabet or underscore and only ...
Akash Dahane's user avatar
1 vote
0 answers
512 views

Using yacc and lex, I got a compile error : usr/bin/ld: cannot find -ly

I'm reading compiler book that Jhon R. Levine's lex and yacc Even after following the first example in Chapter 3, the first example is as follows. /*parser.y*/ %token NAME NUMBER %% statement: NAME ...
Any morning's user avatar
0 votes
1 answer
104 views

How to implement the grammar for this exercise in lex & yacc

Exercise I'm trying to implement the grammar of this exercise using lex & yacc, but it throws this conflict: warning: 5 shift/reduce conflicts [-Wconflicts-sr] and takes every string as invalid, I ...
Juan Posso's user avatar
0 votes
2 answers
317 views

Lex program to check the structure(struct)

I'm trying to create program to check if the input such as struct st{ int j; real i; } it should print correct otherwise not correct. but I have this error prog.l: In function 'yylex': gyg.l:10:5: ...
lena's user avatar
  • 729
0 votes
1 answer
321 views

Flex Bison and Gnu Automake

I wrote a small text-filter based on flex-lexer and bison. A boolean expression is applied to the specified string(logvar). Boolean expression consists of strings and boolean operations. example: *...
Max's user avatar
  • 848
2 votes
1 answer
492 views

Flex/Lex: Regular Expression matches double characters

I have a flex program written in C++ that needs to complete the following rules: I want yytext to accept the following: ○ Zero or one of the following characters ABCDEFGH For example - input: "...
Costas_'s user avatar
  • 145
0 votes
1 answer
151 views

Defining lex include files for (f)lexers

When having multiple lexers one sees that, especially, in the pattern part some definitions are repeated in each lexer (e.g. whiteSpace [ \t]+ ), this is not nice that one has to do define it each ...
albert's user avatar
  • 8,613
1 vote
1 answer
401 views

Rule cannot be matched in Flex (LEX) when using ^

I'm trying to run some simple regex in Flex but I cannot get the operator "^" to work as a negation. This is my code:` %% [^abc] printf("rule triggered\n"); . \n It ...
Johnny Lerec's user avatar
1 vote
1 answer
617 views

Why premature eof on this flex program?

I am making a program in flex that takes a user's input in the form of a string that describes a shape. Now my code seems correct, but I get a premature eof on compilation. I have also tried doing ...
AlVa's user avatar
  • 11
2 votes
1 answer
303 views

C/Lex/Yacc - How To Write The Most Basic Parser Generator Using Yacc

I found it easy to learn about Lex/Flex however learning Yacc/Bison seemed a lot more confusing due to the lack of simple example programs. From my observations, the first example parser introduced to ...
HamzaKerem's user avatar
0 votes
1 answer
905 views

Not getting output of LEX program

I am trying to run a lex program to find number of vowels and consonants in a given string. The program accepts the input but not giving the output. After giving the input , the program accepts the ...
Amit Kumar's user avatar
0 votes
0 answers
102 views

how to convert a XML table to HTML table using lex(flex) yacc(bison)

**from this type of xml code (program will take this type of xml code as input)** <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl"...
Sutrisna Anjoy's user avatar
1 vote
2 answers
1k views

How to install and use Lex on Cygwin?

I need to use Lex for my Compiler Design course but how do I install and use it on the Cygwin environment?
arunkumaraqm's user avatar
1 vote
1 answer
88 views

C# writing a first parser, early stackoverflow detection

I've just started writing a simple parser in C# that you can find here: https://github.com/JohnnyErnest/LexerParser/blob/main/Program.cs#L1078 The main feature being that I wanted to be able to write ...
John Ernest's user avatar
1 vote
1 answer
64 views

why are these bison rules useless?

I am trying to create a simple compiler using flex and bison, however all the rules i've written down have shown to be useless "14 useless nonterminals and 66 useless rules". What makes a ...
sterling128's user avatar
1 vote
1 answer
75 views

Lex: rule cannot be matched

I get a warning for "[" and "]", but I don't know what the problem is. lex.l:27: warning, rule cannot be matched lex.l:28: warning, rule cannot be matched %{ #include <stdio.h&...
Killlin's user avatar
  • 23
2 votes
2 answers
2k views

YACC grammar for WHILE loop and statements wouldn't work

I am trying to generate intermediate code of the following grammar for while loop and general statements, but I keep encountering syntax error. Though earlier, the grammar for statements and ...
Hamza Hussain's user avatar
0 votes
0 answers
374 views

cannot convert 'char*' to 'float' in assignment flex/bison

i am making a programming language using bison/flex but i get errors i just found a simple programming language tutorial in dev.to then made some changes now im making a variable system or anything ...
Ariya1234gamer's user avatar
0 votes
0 answers
65 views

YACC expression grammar wont execute

I am trying to generate intermediate code using the following grammar, but the output i am getting is as if my parser isn't evaluating the input based on this grammar. below is my lex.l file: %{ #...
Hamza Hussain's user avatar
0 votes
1 answer
51 views

Problem when try get $4 with some arguments- YACC -> C

i was stack when i tried got 2 or more arguments to another condition. The big idea is to build Symbol Table to identify errors in code, i was build a tree but now we need build the table, but i didnt ...
Almog Sofer's user avatar
1 vote
0 answers
481 views

Get numbers Yacc & Lex

I need to write parsers and lexers for a specific file type and store the information I need. But it doesn't even come out to get a list of digits from the test file text.txt port ( 3, 5, 7, ...
Killlin's user avatar
  • 23

1
3 4
5
6 7
37