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

How to pass the yytext from the lex file to yacc?

Please i am facing a simple problem.. here is the issue, In my lex file i have something similiar to: char *ptr_String; "name = " { BEGIN sName; } .+ { ptr_String = (char *)calloc(strlen(yytext)+1, sizeof(char)); …
CompilingCyborg
  • 4,760
  • 13
  • 44
  • 61
6
votes
1 answer

How to use yylval in flex

I'm trying to build a lexical analyser with FLEX on windows. I'm getting always an error: "undefined reference to `yylval'" I declared yylval as a extern type up where all definitions are made as follows: %option noyywrap %{ …
ofer gertz
  • 89
  • 1
  • 6
6
votes
2 answers

Indentation control while developing a small python like language

I'm developing a small python like language using flex, byacc (for lexical and parsing) and C++, but i have a few questions regarding scope control. just as python it uses white spaces (or tabs) for indentation, not only that but i want to implement…
sap
  • 1,188
  • 1
  • 14
  • 25
6
votes
2 answers

what should the output of a lexer be in c?

#include int main() { int a,b; a=a+b; printf("%d",a); return 0; } what should be the output if this code is passed through a lexer
Hick
  • 35,524
  • 46
  • 151
  • 243
6
votes
2 answers

fatal error:y.tab.h: No such file or directory on fedora

I am running my fedora on VMware Workstation. I am having a lex and yacc program. Compilation of program is working fine but when i go to run the program through gcc y.tab.c lex.yy.c -ll it gives fatal error: y.tab.h: No such file or directory. Same…
AJ.
  • 4,526
  • 5
  • 29
  • 41
6
votes
5 answers

Are the JSON arrays LL(1) parsable?

I've heard if you parse something LL(1) it's faster so I was wondering if you want to parse a JSON string can this be done by using a LL(1) parser
Spidfire
  • 5,433
  • 6
  • 28
  • 36
6
votes
2 answers

Bison build warning: "-s option given but default rule can be matched"

I get the warning warning, -s option given but default rule can be matched if you google "option given but default rule can be matched", you'll find the Flex manual's chapter on Diagnostics and this entry in an old Flex manpage in the Diagnostics…
user34537
6
votes
1 answer

regular expression for IPV6 address in CIDR notation

I am trying to write a lex pattern that will allow me to recognize IPV6 addresses including IPV6 addresses with CIDR notation.The pattern that I use is given below. IPV4ADDRESS_CIDR […
liv2hak
  • 14,472
  • 53
  • 157
  • 270
6
votes
2 answers

lex error y.tab.h

I am trying to get this example code working but i keep getting the error: fatal error: 'y.tab.h' file not found #include "y.tab.h" . What can I do about this? %{ #include void yyerror(char *); #include "y.tab.h" %} %% [0-9]+ …
codenamejupiterx
  • 1,589
  • 9
  • 23
  • 34
6
votes
7 answers

Regular expression to recognize variable declarations in C

I'm working on a regular expression to recognize variable declarations in C and I have got this. [a-zA-Z_][a-zA-Z0-9]* Is there any better solution?
davepmiller
  • 2,620
  • 3
  • 33
  • 61
6
votes
3 answers

Start states in Lex / Flex

I'm using Flex and Bison for a parser generator, but having problems with the start states in my scanner. I'm using exclusive rules to deal with commenting, but this grammar doesn't seem to match quoted tokens: %x COMMENT // {…
Dan
  • 33,953
  • 24
  • 61
  • 87
6
votes
3 answers

semicolon insertion ala google go with flex

I'm interested in adding semi-colon insertion ala Google Go to my flex file. From the Go documentation: Semicolons Like C, Go's formal grammar uses semicolons to terminate statements; unlike C, those semicolons do not appear in the source.…
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
5
votes
1 answer

error handling in YACC

hi there i'm trying to make a simple parser and using lex and yacc. the thing is i wanna print my own error messages rather than error symbol used by yacc which prints syntax error. for example this is my yacc code; %{ #include #include…
quartaela
  • 2,579
  • 16
  • 63
  • 99
5
votes
3 answers

Using lex generated source code in another file

i would like to use the code generated by lex in another code that i have , but all the examples that i have seen is embedding the main function inside the lex file not the opposite. is it possible to use(include) the c generated file from lex into…
Ahmed Kotb
  • 6,269
  • 6
  • 33
  • 52
5
votes
2 answers

warning Bison compilation

am developping a compiler using flex/bison. I have this warning in my build output. warning: type clash ('s' '') on default action any help please?
Aymanadou
  • 1,200
  • 1
  • 14
  • 36