I'm trying to insert the code that flex reads into my .tex file, this console app is supposed to take a .pascal and analyze it and then generate a .tex file but I'm not able to pass the code to the .tex file and then I need to add color to each token it reads, I need help!! Commands to compile it flex file.l, g++ lex.yy.c, ./a.out, test.pascal, pdflatex PDF.tex
%{
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int token_if = 0;
%}
%%
if ++token_if;
then|begin|end|procedure|function {
printf( "A keyword: %s\n", yytext );
}
%%
int main(int argc, char *argv[])
{
//read file
FILE *fp;
char filename[50], c;
printf("Enter the filename: \n");
scanf("%s",filename);
fp = fopen(filename,"r");
if (fp == NULL)
{
printf("file null");
exit(0);
} else
{
yyin = fp;
//start of lex
yylex();
// counter
//get_token(token_if);
//create latex file
ofstream myPDF("PDF.tex");
myPDF << " \\documentclass{article} "
<< "\\title{Scanner}"
<< "\\author{Andres}"
<< "\\date{III}"
<< " \\begin{document} "
<< "\\maketitle"
<< "\\newpage"
<< "\\section{¿Q?}"
<< " number of if's "
<< token_if
<< " \\end{document} ";
myPDF.close();
}
// printf("# of if's = %d", token_if);
return 0;
}