Created
April 6, 2019 23:29
-
-
Save jeyziel/b955e19ba1596ae4c34bc0bb2a6a7c35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <stdlib.h> | |
# include <stdio.h> | |
# include <ctype.h> | |
# include <string.h> | |
FILE *arquivo, *escrita; | |
int partida = 0; | |
int estado = 0; | |
char lexema[20] = ""; | |
int i = 0; | |
char string[25]; | |
int falhar() { | |
switch (partida) | |
{ | |
case 0: | |
partida = 9; | |
break; | |
case 9: | |
partida = 12; | |
break; | |
case 12: | |
partida = 0; | |
default: | |
break; | |
} | |
return partida; | |
} | |
char next_char() { | |
return getc(arquivo); | |
} | |
int main(){ | |
arquivo = fopen("progama.txt", "r"); | |
escrita = fopen("escrita.txt", "w"); | |
char ch; | |
while (ch != EOF) { | |
switch(estado) | |
{ | |
case 0: ch = next_char(); | |
if (ch == ' ' || ch == '\t' || ch == '\n'){ | |
estado = 0; | |
} | |
else if (ch == '>') estado = 1; | |
else if (ch == '<') estado = 5; | |
else if (ch == '=') estado = 6; | |
else{ | |
estado = falhar(); | |
} | |
break; | |
case 1: ch = next_char(); | |
if (ch == '=') estado = 2; | |
if (ch == '<') estado = 3; | |
else estado=4; | |
break; | |
case 2: | |
estado = 0; | |
break; | |
case 3: | |
estado = 0; | |
break; | |
case 4: | |
estado = 0; | |
break; | |
case 5: | |
estado = 0; | |
case 6: | |
estado = 0; | |
break; | |
case 9: | |
if (isalpha(ch)){ | |
if (ch == '1') printf("1"); | |
string[i++] = ch; | |
estado = 10; | |
}else{ | |
i = 0; | |
strcpy(string, ""); | |
estado = falhar(); | |
/* string[i] = '\0'; | |
fprintf(escrita, "%s\n", string); | |
printf("%s", string); | |
i = 0; | |
strcpy(string, "");*/ | |
} | |
break; | |
case 10: ch = next_char(); | |
if (isalpha(ch) || isdigit(ch)) { | |
estado = 10; | |
string[i++] = ch; | |
}else{ | |
estado = 11; | |
} | |
break; | |
case 11: | |
string[i] = '\0'; | |
fprintf(escrita, "%s\n", string); | |
i = 0; | |
strcpy(string, ""); | |
estado = falhar(); | |
break; | |
case 12: | |
if isdigit(ch) { | |
string[i++] = ch; | |
estado = 13; | |
}else{ | |
estado = falhar(); | |
} | |
break; | |
case 13: ch = next_char(); | |
if ( isdigit(ch)){ | |
string[i++] = ch; | |
estado = 13; | |
}else{ | |
estado = 14; | |
} | |
break; | |
case 14: | |
string[i] = '\0'; | |
fprintf(escrita, "%s\n", string); | |
i = 0; | |
strcpy(string, ""); | |
estado = falhar(); | |
break; | |
} | |
} | |
fclose(arquivo); | |
fclose(escrita); | |
//lexema = " "; | |
//putchar(ch); | |
//if (ch == '*') { | |
//printf("encontrei"); | |
//} | |
//ch = next_char(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment