简体   繁体   中英

expected identifier before numeric constant

I use this code as DFA deterministic finite automata that accept even input of ones or zeros

#include <stdio.h> 

#define TOTAL_STATES 2
#define FINAL_STATES 1
#define ALPHABET_CHARCTERS 2
#define UNKNOWN_SYMBOL_ERR 0
#define NOT_REACHED_FINAL_STATE 1
#define REACHED_FINAL_STATE 2
enum DFA_STATES{q0,q1,q2,q3};
enum input{0,1};
int Accepted_states[FINAL_STATES]={q0};
char alphabet[ALPHABET_CHARCTERS]={'0','1'};
int Transition_Table[TOTAL_STATES][ALPHABET_CHARCTERS];
int Current_state=q0;
void DefineDFA()
{
    Transition_Table[q0][0] = q3;
    Transition_Table[q0][1] = q1;
    Transition_Table[q1][0] = q2;
    Transition_Table[q1][1] = q0;
    Transition_Table[q2][0] = q1;
    Transition_Table[q2][1] = q3;
    Transition_Table[q3][0] = q0;
    Transition_Table[q3][1] = q2;

}
int DFA(char current_symbol)
{
int i,pos;
    for(pos=0;pos<ALPHABET_CHARCTERS; pos++)
        if(current_symbol==alphabet[pos])   
            break;//stops if any character other than a or b
    if(pos==ALPHABET_CHARCTERS)
         return UNKNOWN_SYMBOL_ERR;
    for(i=0;i<FINAL_STATES;i++)
 if((Current_state=Transition_Table[Current_state][pos])
==Accepted_states[i])
            return REACHED_FINAL_STATE;
    return NOT_REACHED_FINAL_STATE;
}
int main(void)
{
    char current_symbol;
    int result;

    DefineDFA();    //Fill transition table

    printf("Enter a string with 'a' s and 'b's:\n Press Enter Key to stop\n");


    while((current_symbol=getchar())!= '\n')
        if((result= DFA(current_symbol))==UNKNOWN_SYMBOL_ERR)
            break;
    switch (result) {
    case UNKNOWN_SYMBOL_ERR:printf("Unknown Symbol %c",
  current_symbol); 
 break;
    case NOT_REACHED_FINAL_STATE:printf("Not accepted"); break;
    case REACHED_FINAL_STATE:printf("Accepted");break;
    default: printf("Unknown Error");
    }
    printf("\n\n\n");
    return 0;
}

i get this error 10:15: error: expected identifier before numeric constant 10:15: error: expected '}' before numeric constant 10:15: error: expected unqualified-id before numeric constant 10:18: error: expected declaration before '}' token

Enum items must be names not values

enum input{AAA,BBB};

or

enum input{AAA=0,BBB};

or

enum input{AAA=0,BBB=1};

Your line:

enum input{0,1};

Is using integers as enum values. This is not allowed. Something like:

enum input {n0, n1};

Is fine. The whole point of using enums is so descriptive titles can be used in place of numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM