Universidad Autónoma Del Estado de Hidalgo: Semestre y Grupo: 6°1
Universidad Autónoma Del Estado de Hidalgo: Semestre y Grupo: 6°1
ESTADO DE HIDALGO
LICENCIATURA EN CIENCIAS
COMPUTACIONALES
“AUTOMATAS Y COMPILADORES”
%option noyywrap
%{
#include<stdio.h>
%}
%%
[\n\t] ;
-?(([0-9]+)|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {printf("number\n");}
. ECHO;
%%
int main()
yylex();
return 0;
}
Captura ejercicio 1
Código ejercicio 2
%option noyywrap
%{
#include<stdio.h>
%}
word [^ \t\n]+
eol \n
%%
. charCount++;
%%
int main(argc,argv)
int argc;
char **argv;
FILE *file;
if(!file) {
exit(1);
yyin = file;
yylex();
}
Captura ejercicio 2
Captura ejercicio 2
Código ejercicio 3
%{
#include<stdio.h>
%}
word [^ \t\n]+
eol \n
%%
. charCount++;
%%
char **fileList;
unsigned currentFile = 0;
unsigned nFiles;
int argc;
char **argv;
FILE *file;
fileList = argv+1;
nFiles = argc-1;
if(argc == 2){
/*
*/
currentFile = 1;
if(!file){
exit(1);
yyin = file;
if (argc > 2)
yylex();
/*
*/
totalCC += charCount;
totalWC += wordCount;
totalLC += lineCount;
} else
return 0;
yywrap()
/*
*/
totalCC += charCount;
totalWC += wordCount;
totalLC += lineCount;
if(file != NULL){
yyin = file;
break;
}
fprintf(stderr, "Could not open %s\n", fileList[currentFile-1]);
}
Captura ejercicio 3
Código ejercicio 4
%option noyywrap
%{
#include<stdio.h>
unsigned verbose;
char *progName;
%}
%%
-h |
"-?" |
-help { printf("usage is: %s [-help | -h | -? ] [-verbose | -v] "
"[(-file| -f) filename]\n", progName);
}
-v |
-verbose {printf("verbose mode is on\n"); verbose =1;}
%%
main(argc, argv)
int argc;
char **argv;
{
progName =*argv;
yylex();
return 0;
}
Captura ejercicio 4
Codigo ejercicio 8
%option noyywrap
%{
#include<stdio.h>
#undef input
#undef unput
int input(void);
unsigned verbose;
char *progName;
%}
%%
-h |
"-?" |
-help {printf("usage is: %s [-help | -h | -? ][-verbose | -v]" " [(-file| -f) filename]\n", progName);}
-v |
%%
progName = *argv;
targv = argv+1;
arglim = argv+argc;
yylex();
int
input(void)
char c;
return(0); /* EOF */
return(c);
targv++;
offset = 0;
return(' ');
void
unput(int ch)
if(ch == 0)
if(offset){
offset--;
return;
offset = strlen(*targv);
}
Codigo ejercicio 6
%option noyywrap
%{
#include<stdio.h>
#undef input
#undef unput
unsigned verbose;
unsigned fname;
char *progName;
%}
%s FNAME
%%
[ ]+ /* ignore blanks */
-h |
"-?" |
-help {printf("usage is: %s [-help | -h | -? ] [-verbose | -v]" " (-file | -f) filename\n", progName);}
-f |
[^ ]+ ECHO;
%%
{
progName = *argv;
targv = argv+1;
arglim = argv+argc;
yylex();
if(fname < 2)
}
Captura Ejercicio 6
Código ejercicio 7
%option noyywrap
%{
#include<stdio.h>
%}
%s MAGIC
%%
%%
int main()
yylex();
return 0;
}
Captura ejercicio 7
Codigo Ejercicio 8
%option noyywrap
%{
#include<stdio.h>
%}
%x COMMENT
%%
<COMMENT>"*/"
<COMMENT>\n { comments++; }
<COMMENT>.\n { comments++; }
^[ \t]*\n {whiteSpace++; }
.+"/*".*"*/".*\n { code++; }
.*"/*".*"*/".+\n { code++; }
.\n { code++; }
%%
int main()
yylex();
%option noyywrap
%{
#include<stdio.h>
%}
%x COMMENT
%%
<COMMENT>"*/"
<COMMENT>\n { comments++; }
<COMMENT>.\n { comments++; }
^[ \t]*\n {whiteSpace++; }
.+"/*".*"*/".*\n { code++; }
.*"/*".*"*/".+\n { code++; }
.\n { code++; }
%%
int main()
yylex();
}
Captura ejercicio 9