bison

Using $x to grab string from rule

I'm trying to do something like this in Bison... loop_for: FOR var_name COLONEQUALS expression TO {printf("%s<=", $2);} expression STEP {printf("%s+=", $2);} expression {printf(")\n");} Code ENDFOR What I'm trying to do is convert a for statement from the fake language's syntax to C's. However, th...

Typedef issue with bison and gnu flex

In my parser, I have %union { SYMTABLE *p_entry ; QUAD *p_quad ; } ; Now, SYMTABLE is the typedef for a struct. The struct and typedef are in an included file. There are no issues with this. QUAD is the typedef for a struct (typedef struct quad QUAD). The struct and typedef are in an included file. There is no problem doing: b...

Is it possible to generate a parser for a language using the Reverse Polish notation with bison/yacc?

Is it possible to generate a parser for a scripting language that uses the Reverse Polish notation (and a Postscript-like syntax) using bison/yacc? The parser should be able to parse code like /fib { dup dup 1 eq exch 0 eq or not { dup 1 sub fib exch 2 sub fib add } if } def ...

Calling lex/yacc from a separate program

I've been reading up on lex/yacc. The books and examples are not hard to follow. In fact, the whole concept is clear as a bell. With one exception. Lex/yacc seem to generate standalone programs. What if I wanted to call them as a parser function? Yacc seems to generate a main function, so how would I call from my own without conflicts. ...

Space issue with Flex/Bison

Im currently working on an HTML parser/template library using Flex/Bison. I am having some issues with my if statement. The expression parses fine ( if you > me ) but when it comes to the statement between the beginning and ending if tags, it is only getting the first word and dying on the space between them. Just wondering how I can en...

Splitting a grammar rule in Bison

I have a Bison rule block: LBRACE { some code } decls stmts RBRACE {more code } ; The issue is in the "more code" section, I have $$ = $3 ; Basically, I want the return value of block to be stmts. When I do this, Bison says "$3 of block has no type." If I remove the code block containing some code and stick it into the latt...

How to use Bison (Yacc) to produce 64bit parser in C++?

Can anyone shed some light on this? From Bison's documentation, I didn't see anything related to this topic. Thanks very much in advance. Mark ...

Bison: Implementing the code after rules

Hey Guys, i'd like to ask someone who implemented a language in bison. How long does it take to implement the code side after you finish all of the rules? I dont know if i should do it or not. Currently i am at 600 LoC (counting the middle part of the %%) How long would it take to implement the code? I know it will vary but how long di...

Define comment and quote in flex and bison and lexical errors.

I have to create a lexical and syntax analyzer for a c-like language. In this language we define as comment "everything that exists after the symbol % until the end of line". Are the following declarations correct? Flex ... [%][^\n]*[\n] { return T_COMMENT; } [\n] { return T_NEWLINE; } Bison ... comment:com text newline; text: |name...

request for member in something not a structure or union

Hi! I've been working for hours and I can't figure out how to print the token from the bison file, the bison file is this: (it's a short simple file) This is the modified version: the solution to the problem: %{ #include <stdio.h> #include <stdlib.h> void yyerror(const char *); int yylex(void); int id; %} %union { int d; } %error-v...

C++ overloading typecast operator for pointers

I have a conversion like this: Class1 *p1; Class2 *p2 = new Class2(); p1 = (Class1 *) p2; Can I override the typecast operator above to return a custom Class1 object pointer? If yes how? EDIT: My exact problem is that I have code like this: if (*$1 == ArrayType(AnyType())) { $$ = ((ArrayType *) $1)->getElementsType(); } Operat...

When to free memory?

I'm working on a lexer / parser combination with Bison and Flex, and am slightly worried about memory leaks. The grammar is quite a simple one, and (so far) I have been able to get away with the following definition: #define YYSTYPE char const * In Flex, when I read a string, I allocate enough memory for that string and then copy it ...

How should binary operators be defined in bison?

I'm writing a parser in C with bison, and while it appears to work correctly in all circumstances I've tried so far, I get a bunch of shift/reduce warnings on my binary operators (and one on my unary NOT operator as well). binary_op : PLUS { } | MINUS { } | TIMES { } | SLASH { } | POWER { } | AND { } ...

Optimizing Bison Grammar

I have this grammar of a C# like language, and I want to make a parser for it, but when I put the grammar it tells me about Shift/Reduce conflicts. I tried to fix some but I can't seem to find another way to improve this grammar. Any help would be greatly appreciated :D Here's the grammar: Program: Decl | Program Decl ; D...