bison

Problem calling std::max

江枫思渺然 提交于 2019-11-27 20:03:45
问题 I compiled my bison-generated files in Visual Studio and got these errors: ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' The corresponding code is: inline void columns (int count = 1) { column = std::max (1u, column + count); } I think the problem is with std::max; if I change std:

bison end of file

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:00:02
问题 If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not finish the rule. How do I solve this? I tried making <<EOF>> return MY_EOF BUT when I do that lex crashes a horrible death. I guess there's code in its default EOF that I am not calling. I have no idea what functions they may be. Using EOF create the

How do I use C++ in flex and bison?

纵饮孤独 提交于 2019-11-27 16:46:59
问题 I have a project for school where we need to use flex and bison. I want to use C++ so that I have access to STL and my own classes that I wrote. We were provided with the following Makefile: CC = gcc CFLAGS = -g OBJs = parse.tab.o symtab.o attr.o lex.yy.o default: parser parser: ${OBJs} ${CC} ${CFLAGS} ${OBJs} -o parser -lfl lex.yy.c: scan.l parse.tab.h attr.h flex -i scan.l parse.tab.c: parse.y attr.h symtab.h bison -dv parse.y parse.tab.h: parse.tab.c clean: rm -f parser lex.yy.c *.o parse

Integrating Bison/Flex/Yacc into XCode

£可爱£侵袭症+ 提交于 2019-11-27 11:03:19
问题 Is there a simple way for integrating Bison/Flex/Yacc into XCode? I want to write my own language to be parsed, which interacts with my ObjC objects. But the tools will only take STDIN as input, and will only produce C code, instead of ObjC. They're basically only seem useful for command-line tools, otherwise they need massive pain to override the output every time I regenerate the parser code. 回答1: In a nutshell, give your grammar files a .ym extension instead of .y. Xcode will then run

goto label in the same loop in Bison

故事扮演 提交于 2019-11-27 08:31:32
问题 I am making a parser with Bison and Flex and I want to create a "goto label" statement, but I want to check if the label exists in the same block of code (between brackets { }, loop, etc). Is there a function that checks such things? 回答1: Your question implies that you are missing some background context in building language translators/compilers, so perhaps a small tutorial will assist you in solving your problem. I hope you don't mind. The processing of computer languages is conventionally

Is it possible to have two or more Lex/Yacc parsers in the same application

断了今生、忘了曾经 提交于 2019-11-27 07:45:21
问题 I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose. Is it possible to have more than one? And if so how do you get another entry point? Thanks david allan finch 回答1: I think you can to this by using the --name-prefix option to Bison, and the --prefix option to Flex. In both cases they allow you to replace the default " yy " prefix used on the functions generated with a prefix of your own choice. 回答2: Yes

String input to flex lexer

一笑奈何 提交于 2019-11-27 03:47:34
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? The following routines are available for setting up input buffers for scanning in-memory strings instead of files (as yy_create_buffer does): YY_BUFFER_STATE yy_scan_string(const char *str) :

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

邮差的信 提交于 2019-11-27 00:51:41
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. 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 I shift, or should I reduce". Usually, you want to bind the else to the closest if , which means you want to

How to compile LEX/YACC files on Windows?

谁都会走 提交于 2019-11-26 23:40:41
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? 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 problems with spaces in directory names, not to say parenthesis. Also, consider installing Dev-CPP in the

Include struct in the %union def with Bison/Yacc

夙愿已清 提交于 2019-11-26 22:53:58
问题 I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token <string> CD WORD PWD EXIT %type <args> arg_list Anyone know what I am doing wrong? 回答1: Even better, use the %code directive with the "requires" option, i.e.: %code requires { struct node { char * val; struct