bison

String input to flex lexer

故事扮演 提交于 2019-11-26 09:35:27
问题 I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there anyway to do this? One suggestion has been to create a pipe, feed it the string and open the file descriptor and send to the lexer. This is fairly simple but it feels convoluted and not very platform independent. Is there a better way? 回答1: The following routines are available for setting up input buffers for scanning in

Reforming the grammar to remove shift reduce conflict in if-then-else

◇◆丶佛笑我妖孽 提交于 2019-11-26 09:08:53
问题 How do I remove shift-reduce conflict for bison for the given grammar? selection-stmt -> if ( expression ) statement | if ( expression ) statement else statement A solution giving the modified grammar would be highly appreciated. 回答1: There is a much simpler solution. If you know how LR parsers work, then you know that the conflict happens here: if ( expression ) statement * else statement where the star marks the current position of the cursor. The question the parser must answer is "should

How to compile LEX/YACC files on Windows?

廉价感情. 提交于 2019-11-26 08:48:27
问题 I\'m having Lex and YACC files to parse my files ( .l file and .y file). How to compile those files and how to make equivalent .c file for them in windows platform? 回答1: As for today (2011-04-05, updated 2017-11-29) you will need the lastest versions of: flex-2.5.4a-1.exe bison-2.4.1-setup.exe After that, do a full install in a directory of your preference without spaces in the name . I suggest C:\GnuWin32 . Do not install it in the default (C:\Program Files (x86)\GnuWin32) because bison has

Why does this bison code produce unexpected output?

前提是你 提交于 2019-11-26 06:50:30
问题 flex code: 1 %option noyywrap nodefault yylineno case-insensitive 2 %{ 3 #include \"stdio.h\" 4 #include \"tp.tab.h\" 5 %} 6 7 %% 8 \"{\" {return \'{\';} 9 \"}\" {return \'}\';} 10 \";\" {return \';\';} 11 \"create\" {return CREATE;} 12 \"cmd\" {return CMD;} 13 \"int\" {yylval.intval = 20;return INT;} 14 [a-zA-Z]+ {yylval.strval = yytext;printf(\"id:%s\\n\" , yylval.strval);return ID;} 15 [ \\t\\n] 16 <<EOF>> {return 0;} 17 . {printf(\"mistery char\\n\");} 18 bison code: 1 %{ 2 #include \

Is there an alternative for flex/bison that is usable on 8-bit embedded systems?

有些话、适合烂在心里 提交于 2019-11-25 21:40:31
问题 I\'m writing a small interpreter for a simple BASIC like language as an exercise on an AVR microcontroller in C using the avr-gcc toolchain. However, I\'m wondering if there are any open source tools out there that could help me writing the lexer and parser. If I would write this to run on my Linux box, I could use flex/bison. Now that I restricted myself to an 8-bit platform I have to do it all by hand, or not? 回答1: I've implemented a parser for a simple command language targeted for the