tomdawncats
tomdawncats

Reputation: 1

Flex and bison in c++, when compiling, it gives me an error that there are too many arguments to the function 'int yylex()'

lexer

%{
    #include "parser.tab.h"
    
    enum {
        STRING = yy::parser::token::STR
    };
    
    extern int yylval;
%}

%option noyywrap c++ debug

WORD "\""(\\.|\\\n|[^\\\"])*"\""

%%

{WORD} return STRING;

[\n\t ] ;

%%

parser

%{
    #include <iostream>
    int yylex();
%}

%skeleton "lalr1.cc"
%require "3.0.2"

%define api.value.type  variant

%token <std::string> STR
%start program

%%

program : STR[a]
            {
                std::cout << $a << std::endl;
            }
         ;

%%

int main()
{
    yy::parser parser;
    parser.parse();
}

namespace yy
{
    void parser::error(const std::string& m)
    {
        std::cerr << m << std::endl;
    }
}

error

parser.tab.c: In member function ‘virtual int yy::parser::parse()’:
parser.tab.c:531:46: error: too many arguments to function ‘int yylex()’
  531 |             yyla.kind_ = yytranslate_ (yylex (&yyla.value));
      |                                        ~~~~~~^~~~~~~~~~~~~
parser:3:13: note: declared here
    3 |         int yylex();
      |             ^~~~~

We checked various websites in different languages, including our native tongue, but found no help at all because only very difficult examples were provided. Essentially, the program should be simpler than a calculator that just receives a string interactively and outputs it.

Upvotes: 0

Views: 87

Answers (0)

Related Questions