bison

Flex, Bison, and C: Looking for a very basic introduction

荒凉一梦 提交于 2019-12-03 01:04:56
I am looking for a very short working example of flex and bison with an accompanying Makefile which makes use of the builtin rules. I've tried several google results that were messy, wouldn't build, or were in C++ which isn't acceptable. Good online resources and short sample code is appreciated. ADDITIONAL # Makefile example -- scanner and parser. # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c" # LEX = flex YACC = bison -y YFLAGS = -d objects = scan.o parse.o myprogram.o myprogram: $(objects) scan.o: scan.l parse.c parse.o: parse.y myprogram.o: myprogram.c I would like a

What is the difference between Flex/Lex and Yacc/Bison?

我与影子孤独终老i 提交于 2019-12-03 00:37:22
问题 What is the difference between Flex & Lex and Yacc & Bison. I searched the Internet wildly and I didn't find any solid answer. Can I install pure Lex and Yacc on Ubuntu, or I can install only flex and bison. I am confused. Is Lex or Yacc still being maintained by someone? Are all of them free? If Lex is not free why do I have it installed on my Ubuntu distribution? lex --version lex 2.5.35 回答1: There are some differences between Lex and Flex, but you have to be abusing Lex to run into the

Trouble building gcc 4.6: undefined reference to `yylex'

梦想与她 提交于 2019-12-02 20:13:37
I'm trying to build gcc 4.6, but I'm getting some linker errors that look like it means bison or flex isn't getting linked to. When the makefile issues this command: gcc -g -fkeep-inline-functions -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Wold-style-definition -Wc++-compat -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE -o build/gengtype \ build/gengtype.o build/errors.o build/gengtype-lex.o build/gengtype-parse.o build/version.o ../../build-x86_64-unknown

Flex/Bison: cannot use semantic_type

只愿长相守 提交于 2019-12-02 20:12:01
问题 I try to create a c++ flex/bison parser. I used this tutorial as a starting point and did not change any bison/flex configurations. I am stuck now to the point of trying to unit test the lexer. I have a function in my unit tests that directly calls yylex, and checks the result of it: private: static void checkIntToken(MyScanner &scanner, Compiler *comp, unsigned long expected, unsigned char size, char isUnsigned, unsigned int line, const std::string &label) { yy::MyParser::location_type loc;

Bison loop for conflict

自闭症网瘾萝莉.ら 提交于 2019-12-02 18:18:51
问题 to solve the dangling else problem, I used the following solution: stmt : stmt_matched | stmt_unmatched ; stmt_unmatched : IF '(' exp ')' stmt | IF '(' exp ')' stmt_matched ELSE stmt_unmatched ; stmt_matched : IF '(' exp ')' stmt_matched ELSE stmt_matched | stmt_for | ... ; For defining the rules of grammar about the for loop, I produce a conflict shift/reduce due to the same problem: stmt_for : FOR '(' exp ';' exp ';' exp ')' stmt ; How can I solve this problem? 回答1: Not all for statements

Writing compilers … what's right and what's wrong? [closed]

血红的双手。 提交于 2019-12-02 17:34:31
Okay, in my quest to figure out the necessary stuff to write a compiler, I've reached a bit of a roadblock. It seems that every technology or tool that I find has some opposition somewhere. I use Bison and Flex right now but I'm getting the feeling that this method is outdated. Is this true? Is this a good forward-compatible way to proceed with writing a full fledged programming language? In a sea of different concepts and tools (ANTLR, LL(k), GLR, LALR, LLVM, Flex, Bison) What's the current trend and best practices for writing compilers? Is the dragon book out of date? Unless you want to

bison's reduction didn't work as expected

邮差的信 提交于 2019-12-02 16:50:28
问题 I'm trying to write a EPL parser,so I'm learning flex and bison.I try using it with following rules(SQL): SELECT { cout<<"SELECT detected"<<endl;return SELECT; } FROM { cout<<"FROM detected"<<endl;return FROM;} [a-zA-Z][0-9a-zA-Z]* { cout<<"IDENTIFIER detected"<<endl;yylval.c=yytext; return IDENTIFIER; } '$' { return DOL;} [ \t] { cout<<"space founded:"<<int(yytext[0])<<endl; } \n { return EOL;} . {} and bison rules are: sel_stmt : {cout<<"VOID"<<endl;} | SELECT identifier_expr FROM

Error in the output of my flex file

自闭症网瘾萝莉.ら 提交于 2019-12-02 15:49:42
问题 I've written a .l file and want to output the contents in "c17.isc". But there is an error I don't know why. I've given the file I plan to read, the flex file and the execution result. This is the c17.isc file The contents means number gate_name gate_type output_number input_number fault The line with "from" means fanout. The line with 2 numbers only means input list. *c17 iscas example (to test conversion program only) *--------------------------------------------------- * * * total number

how to resolve 2+2 and 2++2 conflict

不羁岁月 提交于 2019-12-02 14:51:13
问题 In larger program I have given the following (flex/bison) In flex: pn [\+|\-] dig [0-9]+ exp [e|E]{dig}+ . . . "+" {printf("+ detected\n"); return PLUS_SIGN;} {pn}?{dig}+ { printf("digit detected - %s\n",yytext); sscanf(yytext, "%d", (int*)&yylval); return TYPE_INT;} In Bison: expr: expr PLUS_SIGN expr { $$ = $1 + $3; printf(" $$=%f\n",$$); } | TYPE_INT { $$ = (int)$1; printf(" $$=%f\n",$$); } ; The problem is: When I give 2+2 it recognizes 2 and +2 instead of 2 , + , 2 How can I get it to do

END OF FILE token with flex and bison (only works without it)

走远了吗. 提交于 2019-12-02 10:12:55
问题 OK this is kind of an odd question because what I have here works the way I want it to. What I'm doing is writing a parser for a lambda calculus expression. So an expression can be one of four things: variable constant (expression expression) (lambda variable.expression) Now as you can see, the last two expressions have expressions within them. What I was trying to do was determine the overall expression so I can report which type it is. So for example the expression ((lambda x.(f1 x)) 100)