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
5
votes
3 answers

Bison and doesn't name a type error

I have the following files: CP.h #ifndef CP_H_ #define CP_H_ class CP { public: enum Cardinalite {VIDE = '\0', PTINT = '?', AST = '*', PLUS = '+'}; CP(Cardinalite myCard); virtual ~CP(); private: Cardinalite…
GlinesMome
  • 1,549
  • 1
  • 22
  • 35
5
votes
1 answer

How to make semantic check using flex/bison?

I have created a context free grammar in bison and a scanner in flex. Now i also want to make a semantic check, for example, suppose the input is something like this: int m=5; c=c+5; This input is syntactically correct but there is an undeclared…
user2110714
5
votes
1 answer

Parsing errors with Bison

I'm writing my own scripting language using flex and bison. I have a grammar and I'm able to generate a parser which works fine with a correct script. I would like to be able to add also some meaningful error message for special error situations.…
Salvatore
  • 1,145
  • 3
  • 21
  • 42
5
votes
1 answer

Using character literals as terminals in bison

I'm trying to understand flex/bison, but the documentation is a bit difficult for me, and I've probably grossly misunderstood something. Here's a test case: http://namakajiri.net/misc/bison_charlit_test/ File "a" contains the single character 'a'. …
melissa_boiko
  • 153
  • 10
5
votes
1 answer

Flex/Bison: Bad token management?

I've a problem in my lexer and in my parser. First, in my lexer I've a line like that: "if" beginScope(stOTHER); return IF; And in my parser: stmt: IF '(' exp ')' stmts ... stmts: stmt | '{' stmt_list '}' | '{' '}' In a code like…
Unarelith
  • 495
  • 3
  • 13
4
votes
2 answers

Converting EBNF to BNF for an LALR parser

I know there are several posts with a similar title. Most link to a dead site - and I have a more specific question anyways. I'm trying to convert the EBNF in the XPath spec to straight BNF so that I can easily create a Bison-compatiable grammar…
Steve
  • 31,144
  • 19
  • 99
  • 122
4
votes
1 answer

Common tokens for flex and bison

I have one file with declarations of my tokens declarations.h: #define ID 257 #define NUM 258 ... In my flex code i return one of this values or symbol(for example '+', '-', '*'). And everything works. The problem in bison file. If i write…
kobra
  • 1,285
  • 2
  • 12
  • 15
4
votes
1 answer

Lex/Yacc: Print message before input

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…
cola
4
votes
1 answer

CMake FindFLEX produces NOTFOUND on windows

I installed flex and bison with chocolatey choco install winflexbison3 and created this CMakeLists.txt find_package(BISON) find_package(FLEX) message("FLEX_FOUND: ${FLEX_FOUND}") message("FLEX_EXECUTABLE:…
alagris
  • 1,838
  • 16
  • 31
4
votes
1 answer

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…
samoz
  • 56,849
  • 55
  • 141
  • 195
4
votes
1 answer

C/Bison grammar error

I've got a short question regarding my grammar in bison. The files compile, but it does not give the result I actually wanted. ;-) My example file that I want to parse: L1: ldh [23] The lexer file looks like this: ... digit [0-9] digit_s…
johnloom
  • 63
  • 3
4
votes
4 answers

How to make flex try the second longest matching regular expression?

This question might sound a little confusing. I'm using Flex to pass tokens to Bison. The behavior I want is that Flex matches the longest regular expression and passes that token (it DOES work like this), but if that token doesn't work with the…
Casey Patton
  • 4,021
  • 9
  • 41
  • 54
4
votes
1 answer

Flex&Bison: define main function in a separate file

I am trying to make a small interpreter using Flex and Bison. Now I have two files: parser.l and parser.y. Usually, main function is put in parser.y file. What I want to do is to put the main function in a different file main.cpp which makes my…
deryk
  • 131
  • 2
  • 7
4
votes
2 answers

How to tell flex and bison to stop processing input?

What is the best way to flex and bison to stop processing when an error is encountered. If I call yyerror, it does not stop scanning and parsing my file. While the input is syntactically correct, there is an user error, such as they tried to load…
Juan
  • 3,667
  • 3
  • 28
  • 32
4
votes
1 answer

How to implement better error messages for flex/bison

I need to have proper error messages for syntax errors for a grammar I'm writing. I've figured out that I can define a rule (? not sure about the terminology) for newlines in the flex file that increments a line-number counter, and I can use that in…
greetings
  • 43
  • 1
  • 4