Skip to content

Commit

Permalink
Palabras reservadas
Browse files Browse the repository at this point in the history
  • Loading branch information
ajamaica committed Feb 12, 2012
1 parent 6bd0f8d commit b3b2884
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 2 additions & 3 deletions FSm/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <string.h>

int isReservedWord(char *);


char PALABRAS_RESERVADAS[][15] = {
Expand Down Expand Up @@ -41,9 +40,9 @@ char PALABRAS_RESERVADAS[][15] = {
"while"
};

int isReservedWord(char *term){
int isReservedWord(char term[128]){
int i;
for (i=0; i < sizeof(PALABRAS_RESERVADAS); i++) {
for (i=0; i < sizeof(PALABRAS_RESERVADAS)/sizeof(PALABRAS_RESERVADAS[i]); i++) {
if (strcmp(PALABRAS_RESERVADAS[i], term) == 0) {
return 1;
}
Expand Down
22 changes: 16 additions & 6 deletions FSm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ char *term; /* out: the token text if the token is a term */


case 1 :
printf("%c", 'x');

if ( (DIGIT_CH != char_class[next_ch])

Expand All @@ -155,7 +154,6 @@ char *term; /* out: the token text if the token is a term */


case 9:
printf("%c", '+');
if ( ADDITION_CH != char_class[next_ch])

{
Expand All @@ -170,7 +168,6 @@ char *term; /* out: the token text if the token is a term */
break;

case 10:
printf("%c", '-');
if ( HYPHENMINUS_CH != char_class[next_ch]) {


Expand All @@ -186,7 +183,9 @@ char *term; /* out: the token text if the token is a term */
break;

case 11:
printf("%c", '*');

term[i] = '\0';
state = -11;
break;

case 12:
Expand Down Expand Up @@ -257,9 +256,20 @@ int main(int argc, char **argv, char **envp){
switch( token = GetToken(stream,term) )

{
/*
case TERM_TOKEN : (void)printf ( "term: %s\n", term ); break;

case TERM_TOKEN :

if (isReservedWord(term)) {
printf("\n %s : PALABRA RESERVADA", term);
}
else{
printf("\n %s : ID", term);
}


break;

/*
case LFT_PAREN_TOKEN : (void)printf ( "left parenthesis\n" ); break;
case RGT_PAREN_TOKEN : (void)printf ( "right parenthesis\n" ); break;
Expand Down

0 comments on commit b3b2884

Please sign in to comment.