bison

Flex/Bison-like functionality within PHP

I'm looking for a way to get Flex/Bison (or Lex/Yacc, et. al.) support in PHP. Specifically, I'm implementing a boolean query parser in a web UI and would rather keep all operations inside of PHP (as opposed to calling a C parser, or passing things off to Python, etc.). ...

How to solve Bison warning "... has no declared type"

Hi, Running Bison on this file: %{ #include <iostream> int yylex(); void yyerror(const char*); %} %union { char name[100]; int val; } %token NUM ID %right '=' %left '+' '-' %left '*' %% exp : NUM {$$.val = $1.val;} | ID {$$.val = vars[$1.name];} | exp '+' exp {$$.val = $1.val + $3.val;} | ID '...

Bison (and flex) coding conventions

Hi, What are coding conventions and guidelines you suggest for writing Bison (.y) and flex (.lex) files? Please address the length of the code sections and their style. Thanks, Asaf P.S., There's an old thread about it here, but I'm looking for a more detailed answer (and to have it on SO!). ...

Flex and Bison Associativity Problem

Using Flex and Bison, I have a grammar specification for a boolean query language, which supports logical "and", "or", and "not" operations, as well as nested subexpressions using "()". All was well until I noticed that queries like "A and B or C and D" which I'd like parsed as "(A & B) | (C & D)" was actually being interpreted as "A & ...

yyparse is printing a leading tab

In my bison/flex program, right after yyparse() is called, a leading tab is printed, but I don't know why. Can you see what's wrong? This calls the bison code, and right after yyparse() returns, a tab is printed. void parseArguments(int argc, char** argv) 130 { 131 int i; 132 133 int sum = 0; 134 // calculate the length of...

can Flex return a string match to bison

I'm writing a Bison/Flex program to convert LaTeX into MathML. At the moment, dealing with functions (i.e. \sqrt, \frac, etc) works like this, with a token for every function \\frac {return FUNC_FRAC;} and passes the token FUNC_FRAC back to bison, which plays its part in the description of this subtree: function: FUNC_FRAC L...

How can I use flex on windows?

I'm trying to compile a project on windows and it uses flex/bison. Compiling the flex and bison files went fine after I installed MinGW, but when I get to the final step of the build of: g++ -o hexciting CommandParser.tab.o CommandParser.yy.o Command.o -lfl It says the library can't be found. After some time on google, I tried chang...

How to correctly destruct token semantic values (symbol records) and avoid memory leaks using GNU Bison?

I'm writing a simplified Pascal parser/interpreter and now I'm thinking about segmentation faults. I'm not getting them yet, everything is running fine, but since I'm developing under Cygwin, I can't test the program through valgrind. Basically what I'm doing is described below: typedef struct{ char idType; //Integer (i), Real (r),...

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 // { BEGIN(COMMENT); } <COMMENT>[^\n] ; <COMMENT>\n { BEGIN(INITIAL); } "==" ...

Flex/Bison IDE?

I'm looking for a good development environment in which to work on flex or bison or both. Are there any IDE's that have these capabilities and/or are suitable for this? (If not the next most general question is are there lexer/parser generators with IDE's?) Thanks ~Alex ...

Best way to add generated files to distribution?

I have a quite complex (C++) project using autoconf / automake, which includes some "generated" files (foo.yy -> foo.cc). Actual builds are done using a "control script" (Gentoo .ebuild for those familiar with the concept), on various platforms. Now, one of the target platforms does not properly support the foo.yy -> foo.cc step, and ha...

what is the use of tokens.h when I am programming a lexer?

I am programming a lexer in C and I read somewhere about the header file tokens.h. Is it there? If so, what is its use? ...

Use bison and flex with vc6

When i use bison & flex with vc6, i got got below errors lex.yy.c(395) : error C2146: syntax error : missing ';' before identifier 'YY_PROTO' lex.yy.c(395) : fatal error C1004: unexpected end of file found what would be the cause for this?? please help. Copied from Comment: #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus extern "C" in...

How to initialize Bison's %union value?

In Bison I have a union %union { std::string* sval; } And I want to use it like this In Lex: *(yylval->sval) = "ABCD"; Rather than yylval->sval = new std::string("ABCD"); To prevent memory leaks easily However I need some way to allocated a std::string to sval to begin with. How can I do that? ...

Creating a foreach keyword with yacc or Bison and Flex

I have developed a interpreted programming language. It is strongly based on C. The problem is, I want to add a foreach directive and have no clue how to. I am using Bison and Flex as the parser and lexer generator. ...

Yacc/Bison, minimize amount by grouping math ops

I am looking at the calc source here http://epaperpress.com/lexandyacc/ I see theses lines in calc.y | expr '+' expr { $$ = opr('+', 2, $1, $3); } | expr '-' expr { $$ = opr('-', 2, $1, $3); } | expr '*' expr { $$ = opr('*', 2, $1, $3); } | expr '/' expr { $$ = opr('/', 2, $1, $3); } | expr '<' expr ...

How to use indentation as block delimiters with bison and flex

I wounder how to implement indentation as block delimiters in bison + flex. Just like in python. I'm writing my own programming language ( mostly for fun, but I intend to use it together with a game engine ), I'll try to come up with something special that minimizes boilerplate and maximizes dev speed. I have already written an compiler...

Allowing variable length lists in yacc

I'd like to be able to parse the following structure: blah { "string-1", "string-2", ..., "string-n" } I'm using flex to tokenize, and that's working perfectly. I'm using yacc (bison) for the parsing. What's the recommended way to allow this structure? Right now, in my test.y file, I've got: blah_command: BLAH OP...

How to build an Array with Bison/Yacc and a Recursive Rule

With Bison, I figured out how to get everything into one long string as follows: arg_list: WORD arg_list { strcat( $1, "IFS" ); $$ = strcat($1, $2); } | WORD ; and: WORD arg_list { printf("%s, %s\n", $1, $2); } But the problem is that I will then have to split up $2 in the second rule again to parse it. Is there a way...

Include struct in the %union def with Bison/Yacc

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 ...