Questions tagged [bison]

Bison is the GNU parser generator. It generates LALR parsers, but can also generate GLR parsers for grammars that are not LALR. It has a mode of compatibility with its old predecessor Yacc (yet another compiler compiler).

Bison is the GNU parser generator. It generates LALR parsers, but can also generate GLR parsers for grammars that are not LALR. In POSIX mode, Bison is compatible with Yacc (yet another compiler compiler). flex, an automatic lexical analyser, is often used with Bison, to tokenise input data and provide Bison with tokens.

Websites:

See also:

2588 questions
0
votes
0 answers

Way to create productions for boolean operands in Bison

I'm creating a parser in Bison, and I am trying to convert the rules: E := E op E op := + | - | > | & There are other rules for E, such as negation, and of course, E can be a number. I was wondering what the best way would be to create these…
Naz1706
  • 5
  • 3
0
votes
1 answer

How to invoke yyerror() from flex?

I have yyerror() defined in my Bison file: parser.y ... %code { void yyerror(YYLTYPE* yyllocp, yyscan_t unused, const char** errorReturn, const char* msg); } ... void yyerror(YYLTYPE* yyllocp, yyscan_t unused, const char** errorReturn, const…
Tom
  • 1,235
  • 9
  • 22
0
votes
1 answer

flex's unrecognized rule (about an optional phrase)

I wrote a simple flex file: %{ #include "question.tab.h" %} %% COMMON(/[45]\.0)? return GOTCHA; [a-z]+ return ETC; %% and tried to compile.(flex -d question.l) Then the output was as follows. question.l:7: unrecognized…
plhn
  • 5,017
  • 4
  • 47
  • 47
0
votes
1 answer

How do I parse the type of custom defined datatypes in header file of a C code using bison/flex?

I am learning bison/flex. I successfully parse a simple c code file with bison/flex. Now I was wondering on parsing the included header file in a test c code using bison/flex. Will it can do that ? To put in a simpler way, I am attaching sample code…
0
votes
1 answer

IF-ELSE statement for a compiler using flex and bison

I don't know why my approach fails: if_stmt: CONTROL_IF '(' expr ')' '{' lines '}' { if(($3.int_value != 0)||($3.float_value != 0)){ yyerror("hello"); } } Test Code: line14 if(b == 1){ line15 …
user14895999
0
votes
1 answer

How to combine two flex (.l) files and use them in one Bison file (.y)?

I am very new to Bison/Flex. I created a program to read the c file and identify the function defined. It worked. I was wondering, how can I use some predefined lex file from another open source and use its token into my lex file and produce the…
0
votes
1 answer

How to print shift or reduce grammar rule? (flex,bison)

I'm trying to implement a C grammar parser with lex & yacc and show the reducing procedure. I have to print token list on the left and shift or reduce rule on the right. Like: 2*4+4/2 //iniput 2 shift 2 2 2 …
Hwing
  • 1
0
votes
0 answers

Shift/reduce conflict with LALR grammar

I am writing a grammar where I'd like certain functions to be only at the top-level of the expression while arithmetic operations can be anywhere. E.g. 4 + (5 * 9) is correct, FUNC(2 + 4) * 8 - FUNC(4) is also correct, but FUNC(2 * FUNC(8)) is…
Milos Ljumovic
  • 403
  • 4
  • 16
0
votes
0 answers

Why can't I `return 1` with this grammar?

As followup on this post: I wrote a grammar that should be able to parse both of these inputs: class x implements x: method hi() return ho1/* hi*/; end; end; class x implements x: method hi() return 1 /* hi*/; end; end; The first one parses fine,…
Fabian Schneider
  • 799
  • 1
  • 13
  • 40
0
votes
0 answers

bison i need to access the expr

I can use this very nicely but in the expr i want to validate the expr tADD etc i created, but i can not access the expr inside operation, how do i access it ? it just returns the result that is 0 %{ #include void yyerror (const char…
Ahmed Can Unbay
  • 2,694
  • 2
  • 16
  • 33
0
votes
1 answer

Bison yyerror ignore next token on grammar

So I'm having a litle problem on my Bison program, first be aware that my program works and is fully function what you see here is just an exerpt and sufficiant to help me. basicaly the parser reads "vector(x,2)" the program is checking if the…
RGO
  • 15
  • 5
0
votes
0 answers

Why `string` `vector` etc does not work in union in bison?

I was trying to write a parser for a subset of C language . But when I include string or vector inside the %union , it throws error . Using char* or array seems to be fine . %union{ string s; vectorv; } I have seen in some place that…
Zarif
  • 445
  • 5
  • 12
0
votes
1 answer

Yocto cross compiling, bitbake glibc error: bison

I'm trying to bitbake glibc 2.27 (https://layers.openembedded.org/layerindex/recipe/80771/) in my yocto project but I have an error like this: | checking for gnumake... make | checking version of make... 4.2.1, ok | checking for gnumsgfmt... no |…
user10838321
0
votes
1 answer

How to skip parts of bison if yyparse fails

So basically, in my bison file if yyparse fails (i.e there is syntax error) I want to print 'ERROR' statement and not print anything else that I do in the above part of bison file in fac the stmt part. if yyparse returns 1 is there any way to skip…
Beg
  • 21
  • 6
0
votes
1 answer

Printing multi-character tokens in YACC error messages

If a syntax error is detected by Yacc and verbose errors is defined, an error message is printed, for example unexpected '[', expecting BECOMES Is there a way to replace the token name for multi-character tokens (e.g. BECOMES) with the actual…
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60