flex-lexer

How to find all word except a few in flex?

▼魔方 西西 提交于 2019-12-11 04:47:16
问题 I need to find all words except a few (e.g. "car", "bus", "train") in flex. Have you got any ideas how to do it? 回答1: This has been left unanswered for some time, and is a standard problem that new users of lex/flex encounter when starting. There is also not a clear answer elsewhere on SO. The question is asking how do you match all identifiers that are not reserved words. This is a standard computer language feature that occurs in almost every compiler. It just was not expressed in a way

Minimal bison/flex-generated code has memory leak

久未见 提交于 2019-12-11 04:22:28
问题 In debugging a memory leak on a large project, I found that the source of the leak seemed to be some flex/bison-generated code. I was able to recreate the leak with the following minimal example consisting of two files, sand.l and sand.y : in sand.l : %{ #include <stdlib.h> #include "sand.tab.h" %} %% [0-9]+ { return INT; } . ; %% in sand.y : %{ #include <stdio.h> #include <stdlib.h> int yylex(); int yyparse(); FILE* yyin; void yyerror(const char* s); %} %token INT %% program: program INT {

Flex error negative range in character class

别说谁变了你拦得住时间么 提交于 2019-12-11 03:15:01
问题 I am writing a parser using Flex and Bison and have defined various tokens as: [0-9]+ { yylval.str=strdup(yytext); return digit; } [0-9]+\.[0-9]* { yylval.str=strdup(yytext); return floating; } [a-zA-Z_][a-zA-Z0-9_]* { yylval.str=strdup(yytext); return key; } [a-zA-Z/][a-zA-Z_-/.]* { yylval.str=strdup(yytext); return string; } [a-zA-Z0-9._-]+ { yylval.str=strdup(yytext); return hostname; } ["][a-zA-Z0-9!@#$%^&*()_-+=.,/?]* { yylval.str=strdup(yytext); return qstring1; } [a-zA-Z0-9!@#$%^&*()_-

Yacc and Lex inclusion confusion

送分小仙女□ 提交于 2019-12-11 01:48:01
问题 I am wondering how to correctly compile a program with a Makefile that has calls to yyparse in it? This is what I do: I have a Makefile that compiles all my regular files and they have no connections to y.tab.c or lex.yy.c (Am I supposed to have them?) I do this on top of my code: #include "y.tab.c" #include "lex.yy.c" #include "y.tab.h" This is what happens when I try to make the program: When I just type in "make", it gives me many warnings. Some of the examples are shown below. In function

Bison token is rest of the string

可紊 提交于 2019-12-11 01:31:27
问题 I have written a flex and bison, I am facing a problem which is illustrated via the below program. The program is intended to parse the key-value pairs separated by an equals (=) sign I am hoping that my bison script tokenizes the key and values and prints them. Below is the snippet of my flex program %{ /* file : kvp.l */ #include <stdio.h> #define YYSTYPE char* #include "kvp.tab.h" %} %% [a-zA-Z0-9][_a-zA-Z0-9]* { yylval=yytext; return IDENTIFIER; } "=" { yylval=yytext; return EQUALS_OP; }

Undefined reference to `yylex'

情到浓时终转凉″ 提交于 2019-12-11 00:58:10
问题 I am trying to parse one input file using flex and bison but I am facing one difficulty while compiling my program. I am attaching my flex and bison code and error which I am getting. Please help me out to solve these errors lex.l %{ #include <iostream> #include <stdio.h> #include "yacc.tab.h" #define YY_DECL extern "C" int yylex() using namespace std; %} DOT "." COLON ":" SEMICOLON ";" COMMA "," ANGLE_LEFT "<" ANGLE_RIGHT ">" AT "@" EQUAL "=" SQUARE_OPEN "[" SQUARE_CLOSE [^\\]"]" OPENBRACE "

Can't compile flex & bison (Symbols not found x86_64)

流过昼夜 提交于 2019-12-11 00:12:30
问题 I am trying to compile a simple program on Flex & Bison on my Mac running Yosemite but get the following error: Undefined symbols for architecture x86_64: "_yyerror", referenced from: _yyparse in pr1-19c182.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) My two files look like this, they compile on my teacher's Ubuntu installation but I can't get them to work on my Mac: pr1.y %{ #include <stdio.h> %} %% expr :

lex : How to override YY_BUF_SIZE

这一生的挚爱 提交于 2019-12-10 21:27:18
问题 According to the manual YY_BUF_SIZE is 16K and we need to override it. However, the manual does not specify how to override it, nor could I find any command line option for this. Can someone please indicate how to change this. In the generated source YY_BUF_SIZE is defined as follows: #ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 #endif so there may be a way to override it before this. 回答1: In your own code, simply #define YY_BUF_SIZE to whatever value you want. As long as you compile your

compiling flex and bison into cpp

杀马特。学长 韩版系。学妹 提交于 2019-12-10 21:24:42
问题 Usually, when we compile .l and .y files, we get .tab.h,.tab.c and .yy.c files. However, I need to use these in a C++ environment with types that are only available in C++. How do you modify your code so as to do this? 回答1: You can compile the generated files using your trustworthy C++ compiler, so you don't have to rewrite the whole thing. If you want to go "full c++", keep reading. For Flex , you need to specifiy %option c++ in the file. You can also change the generated C++ lexer name

Using Flex (the lexical analizer) on OS X

回眸只為那壹抹淺笑 提交于 2019-12-10 20:47:48
问题 I've got a file, test.lex, which I run through as $ flex test.lex That gives me lex.yy.c, which I try to compile with: $ gcc lex.yy.c -lfl This gives me the error ld: library not found for -lfl. I know the Flex specification is correct and lex.yy.c compiles fine on a Linux machine. Any suggestions? Edit: I'm using the flex supplied by Apple. 回答1: Some systems make libfl a separate package from flex, as it is rarely needed. The libfl library just contains two functions: int main() { while