bison выдает ошибку

Делал себе матричный калькулятор через flex и bison, но тут у меня выдает ошибку. Почему?

calc.y:54.64-65: $2 из `expression' не имеет описанного типа
calc.y:55.64-65: $2 из `expression' не имеет описанного типа
calc.y:56.64-65: $2 из `expression' не имеет описанного типа
calc.y:57.64-65: $2 из `expression' не имеет описанного типа
calc.y:58.64-65: $2 из `expression' не имеет описанного типа
calc.y:59.64-65: $2 из `expression' не имеет описанного типа
calc.y:60.70-71: $2 из `expression' не имеет описанного типа
calc.y:61.67-68: $2 из `expression' не имеет описанного типа
calc.y:62.67-68: $2 из `expression' не имеет описанного типа

flex файл:

%{
#include <iostream>
#include <cstdlib>
#include "parser.tab.h"
%}

%%
"+" { return ADD; }
"-" { return SUB; }
"*" { return MUL; }
"/" { return DIV; }
"^" { return POW; }
"%" { return MOD; }
"//" { return FLOOR_DIV; }
"++" { return INC; }
"--" { return DEC; }
"transpose" { return TRANSPOSE; }
"inverse" { return INVERSE; }
"determinant" { return DETERMINANT; }

[0-9]+ { yylval.num = atof(yytext); return NUMBER; }
\n    { return EOL; }
[ \t]  { /* skip whitespace */ }
. { return yytext[0]; }
%%

int yywrap(void) {
    return 1;
}

bison файл:

%{
#include <iostream>
#include <cmath>
using namespace std;

extern "C" int yylex();
extern "C" int yyparse();
extern "C" FILE *yyin;

void yyerror(const char *s);

double** evaluate_expression(double** left, int op, double** right);
double** perform_unary_operation(double** matrix, int op);
double calculate_determinant(double** matrix);
double** calculate_inverse(double** matrix);
double** transpose_matrix(double** matrix);

double** create_matrix(int rows, int cols);
void print_matrix(double** matrix, int rows, int cols);
void free_matrix(double** matrix, int rows);

%}

%union {
    double num;
    double** matrix;
}

%token <num> NUMBER
%token ADD SUB MUL DIV POW MOD FLOOR_DIV INC DEC
%token TRANSPOSE INVERSE DETERMINANT
%token EOL

%type <matrix> expression

%left ADD SUB
%left MUL DIV POW MOD FLOOR_DIV
%right UMINUS

%start statements

%%

statements:
    | statements statement EOL
    ;

statement:
    | expression { print_matrix($1); }
    ;

expression:
      NUMBER                    { $$ = create_matrix(1, 1); (*$$)[0][0] = $1; }
    | expression ADD expression { $$ = evaluate_expression($1, $2, $3); }
    | expression SUB expression { $$ = evaluate_expression($1, $2, $3); }
    | expression MUL expression { $$ = evaluate_expression($1, $2, $3); }
    | expression DIV expression { $$ = evaluate_expression($1, $2, $3); }
    | expression POW expression { $$ = evaluate_expression($1, $2, $3); }
    | expression MOD expression { $$ = evaluate_expression($1, $2, $3); }
    | expression FLOOR_DIV expression { $$ = evaluate_expression($1, $2, $3); }
    | expression INC           { $$ = perform_unary_operation($1, $2); }
    | expression DEC           { $$ = perform_unary_operation($1, $2); }
    | TRANSPOSE expression     { $$ = transpose_matrix($2); }
    | INVERSE expression       { $$ = calculate_inverse($2); }
    | DETERMINANT expression    { $$ = create_matrix(1, 1); (*$$)[0][0] = calculate_determinant($2); }
    ;

%%

void yyerror(const char *s) {
    cerr << "Error: " << s << endl;
}

int main() {
    yyin = stdin;
    yyparse();
    return 0;
}

double** create_matrix(int rows, int cols) {
    double** matrix = new double*[rows];
    for (int i = 0; i < rows; ++i) {
        matrix[i] = new double[cols];
    }
    return matrix;
}

void free_matrix(double** matrix, int rows) {
    for (int i = 0; i < rows; ++i) {
        delete[] matrix[i];
    }
    delete[] matrix;
}

void print_matrix(double** matrix, int rows, int cols) {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
}

double** evaluate_expression(double** left, int op, double** right) {
    // Реализуйте операции для матриц здесь
}

double** perform_unary_operation(double** matrix, int op) {
    // Реализуйте унарные операции для матриц здесь
}

double calculate_determinant(double** matrix) {
    // Реализуйте нахождение определителя здесь (пока только для 2x2 матриц)
}

double** calculate_inverse(double** matrix) {
    // Реализуйте нахождение обратной матрицы здесь (пока только для 2x2 матриц)
}

double** transpose_matrix(double** matrix) {
    // Реализуйте транспонирование матрицы здесь
}

Ответы (0 шт):