0

I redeem this problem with the flex and bison compilation. this image: https://drive.google.com/open?id=1o_XSlpBV3FaQJn9AlBGrkBDqnWJOyCjR shows which commands I run and what I get in output. I am a beginner for this type of programming and I can not understand what the problem is. my codes are as follows:

BISON CODE

%{
/#include <stdio.h>
%}
%token NUM PIU MENO PER DIVISO PAR_AP PAR_CH
%start Expr
%error-verbose
%%
Expr: Expr PIU Term
| Expr MENO Term
| Term
;
Term: Term PER Factor
| Term DIVISO Factor
| Factor
;
Factor: NUM
| PAR_AP Expr PAR_CH
;
%%
int main (void) {
yyparse();
return 0;
}
yyerror (char *s) {
printf("Errore Sintattico\n");
}

FLEX CODE

%{
/#include <stdio.h>
/#include "prova.tab.h"
%}
delim [ \t\n]
ws {delim}+
digit [0-9]
number {digit}+
%option noyywrap
%%
{ws} ;
{number} {return (NUM);}
\+ {return(PIU);}
\- {return (MENO);}
\* {return (PER);}
[/] {return (DIVISO);}
\( {return (PAR_AP);}
\) {return (PAR_CH);}
%%
Georgi Hristozov
  • 3,899
  • 2
  • 17
  • 23
  • Hi Manuel and welcome to the community. Regarding the screenshot, I think it would be better if we try to include these commands in the question as text instead as an image. This will make the question much more "searchable" both from Google and from SO itself. One way would be to start Firefox in your VirtualBox VM and log on to Stack Overflow there; you should be able to copy text from the terminal to Firefox that way. – Per Lundberg Jan 01 '19 at 20:31
  • Possible duplicate of [Generating a compiler from lex and yacc grammar](https://stackoverflow.com/questions/23717039/generating-a-compiler-from-lex-and-yacc-grammar) – Per Lundberg Jan 01 '19 at 20:33
  • ok, now when i use "gcc lex.yy.c prova.tab.c" the output is a file named "a.out" and not "a.exe". why? – Manuel Mannino Jan 01 '19 at 21:18

0 Answers0