bison

How do I implement a two-pass scanner using GNU Flex?

As a pet-project, I'd like to attempt to implement a basic language of my own design that can be used as a web-scripting language. It's trivial to run a C++ program as an Apache CGI, so the real work lies in how to parse an input file containing non-code (HTML/CSS markup) and server-side code. In my undergrad compiler course, we used Fl...

Advantages of Antlr (versus say, lex/yacc/bison)

I've used lex and yacc (more usually bison) in the past for various projects, usually translators (such as a subset of EDIF streamed into an EDA app). Additionally, I've had to support code based on lex/yacc grammars dating back decades. So I know my way around the tools, though I'm no expert. I've seen positive comments about Antlr in ...

Clearing parser state of a bison generated parser

I am using a C lexer that is Flex-generated, and a C++ parser that is Bison-generated. I have modified the parser to acccept only string input. I am calling the parser function yyparse() in a loop, and reading line by line of user input. I stop the loop if the input is "quit". The problem I am facing is that when input doesn't match an...

Is there a modern ( e.g. CLR ) replacement for bison / yacc ?

I have just been re-working an old bit of compiler-like code written using bison. While I was doing this, I was wondering what the modern equivalent is? Is there a nice .NET ( or similar ) compiler writing framework that takes a BNF grammar and splits out a DLL that does the parsing? ...

Developing a simple parser

My day job includes working to develop a Pascal-like compiler. I've been working all along on optimizations and code generation. I would also like to start learning to build a simple parser for the same language. I'm however, not really sure how to go about this. Flex and Bison seem to be the choice. But, isn't it possible to write a p...

Debugging Bison generated code with GDB

I am trying to step into my yyparse function, which is defined in Bison generated code, but I get a message from GDB saying Reading file "foo.tab.c"...No such file or directory. The file generated by Bison is called foo.cc. Why is it looking for foo.tab.c, instead? ...

When is an ambiguous grammar or production rule OK? (bison shift/reduce warnings)

There are certainly plenty of docs and howtos on resolving shift/reduce errors. The bison docs suggest the correct solution is usually to just %expect them and deal with it. When you have things like this: S: S 'b' S | 't' You can easily resolve them like this: S: S 'b' T | T T: 't' My question is: Is it better to leave the gram...

How does flex support bison-location exactly?

Hi, I'm trying to use flex and bison to create a filter, because I want get certain grammar elements from a complex language. My plan is to use flex + bison to recognize the grammar, and dump out the location of elements of interest. (Then use a script to grab text according the locations dumped.) I found flex can support a bison feat...

Lexer/parser tools

Which lexer/parser generator is the best (easiest to use, fastest) for C or C++? I'm using flex and bison right now, but bison only handles LALR(1) grammars. The language I'm parsing doesn't really need unlimited lookahead, but unlimited lookahead would make parsing a lot easier. Should I try Antlr? Coco/R? Elkhound? Something else? ...

Bison does not appear to recognize C string literals appropriately

Hi Folks, My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly...

Using yyparse() to make a two pass assembler?

I'm writing an assembler for a custom micro controller I'm working on. I've got the assembler to a point where it will assemble instructions down to binary. However, I'm now having problems with getting labels to work. Currently, when my assembler encounters a new label, it stores the name of the label and the memory location its referr...

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

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

Lex/Yacc: Print message before input

Hi, I'm trying to figure out how I can display a message/prompt when using lex/yacc (flex/bison). For instance, main looks like so: int main(int argc, char *argv[]) { yyparse(); } Which calls yacc, which calls yylex(). This yields a blank line waiting on STDIN. How can i display a message like... message $ _ instead of _ Whe...

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

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

String input to flex lexer

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

Using a parser generator such as BISON, while still handling bad input gracefully

I need a parser for a language that isn't all that complicated. The only catch is, I never want the parser to raise an error when it receives malformed input. Rather, I want it to just continue, making as much sense of the input as it can, similar to what the HTML parsers in a web browser do. I naturally thought to use a parser generato...

ANTLR equivalent to bison REJECT action ?

I'm trying to parse a list of Name=Value pairs, where the value can contain anything except whitespace (i.e. values can contain equal signs). The name is restricted to usual identifier characters. The problem is, the 'Value' token matches everything. For example, for the input: dude=sweet the parser will match the whole input with a ...

How to fix YACC shift/reduce conflicts from post-increment operator?

I'm writing a grammar in YACC (actually Bison), and I'm having a shift/reduce problem. It results from including the postfix increment and decrement operators. Here is a trimmed down version of the grammar: %token NUMBER ID INC DEC %left '+' '-' %left '*' '/' %right PREINC %left POSTINC %% expr: NUMBER | ID | ...

How do I implement forward references in a compiler?

I'm creating a compiler with Lex and YACC (actually GNU Flex and Bison). The language allows unlimited forward references to any symbol (like C#). The problem is that it's impossible to parse the language without knowing what an identifier is. The only solution I know of is to lex the entire source, and then do a "breadth-first" parse, ...

Can Bison parse UTF-8 characters?

I'm trying to make a Bison parser to handle UTF-8 characters. I don't want the parser to actually interpret the Unicode character values, but I want it to parse the UTF-8 string as a sequence of bytes. Right now, Bison generates the following code which is problematic: if (yychar <= YYEOF) { yychar = yytoken = YYEOF; ...