bison

Is Good To Know Regular Expressions To Build a Language?

I'm reading Flex & Bison from O'Reilly, and would like to know if learning Regular Expressions beforehand will help in developing a programming language? ...

Am i forced to use %glr-parser?

I have been keeping the shift/reduce errors away. Now finally i think i met my match. Int[] a a[0] = 1 The problem is int[] is defined as Type OptSquareBrackets while a[0] is defined as Var | Var '[' expr ']' Var and Type both are defined as VAR which is any valid variable [a-zA-Z][a-zA-Z0-9_]. Apart from adding a dummy token ...

Why do i have a shift reduce/conflict on the ')' and not '('?

I have syntax like %(var) and %var and (var) My rules are something like optExpr: | '%''('CommaLoop')' | '%' CommaLoop CommaLoop: val | CommaLoop',' val Expr: MoreRules | '(' val ')' The problem is it doesnt seem to be able to tell if ) belongs to %(CommaLoop) or % (val) but it complains on the ) inst...

Telling Bison/Yacc to shift and not reduce to resolve a conflict

I have a situation where there is a rule with a shift/reduce conflict that i understand. I want a rule to never reduce until at the last moment possible (end of line). So I would like to say always shift. How do i do this? ...

How to use yylval with strings in yacc

I want to pass the actual string of a token. If I have a token called ID, then I want my yacc file to actually know what ID is called. I thing I have to pass a string using yylval to the yacc file from the flex file. How do I do that? ...

yylval and union

What is the purpose of union in the yacc file? Is it directly related to yylval in the flex file? If you don't use yylval, then you don't need to use union? ...

lex/yacc and parser/scanner

lex and yacc are supposed to be used together. Which ones is the scanner and which one is the parser? Which one creates a scanner and which one creates a parser? ...

How to create an array of an array of structs

I am trying to create a symbol table using an array of an array of structs. Right now I just have an array of structs and it's created like this: #define MAXSIZE 20 /* maximum number of symbols */ #define MAXSCOPE 10 /* maximum number of scope levels */ struct tableEntry { char *name; char *args; int value; int scope; char *type...

Compiling and executing the Shakespeare Programming Language translator spl2c on Mac OS X 10.6 results in warnings/errors

I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make. The compilation of spl2c executes with a couple warnings: scanner.l:600: warning, rule cannot be matched <stdout>:5808: warning: ‘yyunput’ defined but not used And then when it at...

How much time would it take to write a C++ compiler using flex/yacc?

How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it? ...

How to parse an if statement in bison

I'm using bison to build a compiler for a simple language. Here's part of the grammar: stmt: IF '(' exp ')' stmt{ if(exp) $$=$5; } |PRINT ';' { cout<<"hi"; } ; exp: true|false ; I encountered a problem in parsing this if statement: Say I have this code: if(false) print; "hi" will be printed anywa...

how to create a gui for my compiler ?

i am using flex as lexical analyzer and bison as parser generator , but the result of both is console window and i want to have a gui (like ide) for it so how to do that . thanks ...

Using $n for n < 0 in Bison

Is there a way in Bison to check the current token stack size? I'd like to use $n with n as a negative number to access a semantic value of another rule but only if the stack is large enough. Thank you. ...

Shift/reduce problem with C-like grammar under Bison

Hello folks, I've been working on a C-like grammar for my personal amusement. However, I've been running into shift/reduce conflicts, and I'm quite sure they could be resolved. Right now my expressions look like this, in a simplified form, stripped of actions: %left '+' '-' %% expr : NUMBER | IDENTIFIER | expr '+' expr | expr '-'...

How can I tell Bison I also expect reduce-reduce conflicts?

My C#-ish toy grammar now has its first reduce-reduce conflicts! I'm so proud of me. It seems all right to me, however (I switched off to a GLR parser for the occasion). The problem is, while I know the %expect directive can shut up Bison about shift/reduce conflicts, I can't find the equivalent for reduce/reduce conflicts. So what shou...

where to find a real example on flex and bison ?

i need a n example on flex and bison , so i can learn how to build ast tree and symbol table and do semantic analysis ...

How to write a bison file to automatically use a token enumeration list define in a C header file ?

Hi everyone, I am trying to build a parser with Bison/Yacc to be able to parse a flow of token done by another module. The token different token id are already listed in a enumeration type as follow: // C++ header file enum token_id { TokenType1 = 0x10000000, TokenType2 = 0x11000000, TokenType3 = 0x1110000...

Is there rule of thumb for catching errors in Lex/Yacc parsing?

Should we catch errors while parsing general purpose language as early as possible (in Lex) or where it is more convenient and give us more information (in Yacc)? How various languages solve this problem? ...

using qt : how to build a gui ontop of a console application ?

i have a console application that generated from bison (a parser) and i want to build a simple gui for it so i can send input from this gui to the console and get output from the console into the gui . i tried to do that using java process class but it doesnt work for me , please help me to do that using qt . ...

Enable/disable grammar rules in Yacc/Bison

Like the title says, I would like to enable/disable certain grammar rules in a yacc or bison grammar file. Is there a way to do so? ...