Question: I need help, now im trying to made the main.cpp code in visual studio 2 0 2 2 . i already made a . l

I need help, now im trying to made the main.cpp code in visual studio 2022. i already made a .l file and y. file using bison and flex. The .l file code is the following
%{
#include "cminusminus_parser.tab.h"// Generated by Bison
%}
%%
"+"{ return PLUS; }
"-"{ return MINUS; }
"*"{ return MULTIPLY; }
"/"{ return DIVIDE; }
INT { return INT; }
[a-zA-Z][a-zA-Z0-9]*{ return ID; }
[0-9]+{ return NUMBER; }
"/*"([^*]|[\r
]|(\*+([^*/]|[\r
])))*"*+"{/* Ignore comments */}
"[\t\r
]+"{/* Ignore whitespace */}
.{/* For any unrecognized character */}
%% and .y file is the following %{
#include
#include
#include "cminusminus_parser.tab.h"
extern int yylex();
extern int yyparse();
extern FILE* yyin;
void yyerror(const char* s);
%}
%token PLUS MINUS MULTIPLY DIVIDE INT ID NUMBER
%left PLUS MINUS
%left MULTIPLY DIVIDE
%%
program:
declaration_list
;
declaration_list:
declaration_list declaration
| declaration
;
declaration:
var_declaration
| fun_declaration
;
var_declaration:
INT ID ';'
;
fun_declaration:
INT ID '(' params ')' compound_stmt
;
params:
param_list
|
;
param_list:
param_list ',' param
| param
;
param:
INT ID
;
compound_stmt:
'{' local_declarations statement_list '}'
;
local_declarations:
local_declarations var_declaration
|
;
statement_list:
statement_list statement
|
;
statement:
expression_stmt
| compound_stmt
;
expression_stmt:
expression ';'
|';'
;
expression:
var '=' expression
| simple_expression
;
var:
ID
;
simple_expression:
additive_expression
;
additive_expression:
additive_expression PLUS term
| additive_expression MINUS term
| term
;
term:
term MULTIPLY factor
| term DIVIDE factor
| factor
;
factor:
'(' expression ')'
| var
| NUMBER
;
%%
void yyerror(const char* s){
fprintf(stderr, "Error: %s
", s);
}
I need help, now im trying to made the main.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!