Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: expected identifier or ‘(’ before ‘TOKEN’
    text
    copied!<p>Basically this is a program which I take a text file with some code and take each char and make it a token or make the other chars that are included in it become a token like a variable. That part works I know because I have used this code for another project and I'm just reusing. The problem is that when I am trying to get the token the scanner.c create and return it to another file it is saying I have an error "error: expected identifier or ‘(’ before ‘TOKEN’". I cant figure out where the error is. Here is my scanner.c file and I also posted the .h file where the token is defined. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include "parser.h" *TOKEN parseString(char *token); *TOKEN parseChar(char token); *TOKEN scan(FILE *input_file) { int stateTable[3][122]; int i = 0; int j = 0; for( i=0; i &lt; 3; i++)//init to 0 { for ( j=0; j &lt; 122; j++) { stateTable[i][j] = 0; } } for( i=48; i &lt; 57; i++)//all numbers [0-9] { stateTable[1][i] = 3; stateTable[3][i] = 3; } for( i=97; i &lt; 122; i++)//all alpha [a-z] { stateTable[1][i] = 2; stateTable[2][i] = 2; } stateTable[1][10] = 1;// \n stateTable[1][32] = 1;// space stateTable[1][40] = 1;// ( stateTable[1][41] = 1;// ) stateTable[1][42] = 1;// * stateTable[1][43] = 1;// + stateTable[1][45] = 1;// - stateTable[1][47] = 1;// / stateTable[1][59] = 1;// ; stateTable[1][61] = 1;// = int state = 0; int index = 0; char temp[20]; char token; token = fgetc(input_file); state = stateTable[1][(int) token]; if (state == 2 || state == 3)//num or alpha { temp[index] = token; index++; scan(input_file); } else if (state = 1) { if (index &gt;= 1)//digit or identifier { temp[index] = '\0'; return parseString(&amp;temp[0]); temp[0] = '\0'; } else return parseChar(token); if(token == ';' ||token == ')') return parseChar(token); index = 0; } } *TOKEN parseString(char *token) { TOKEN *temp = malloc(sizeof(TOKEN)); if(strcmp("repeat",token) == 0) &amp;temp.type = 4; else if(strcmp("print",token) == 0) &amp;temp.type = 5; else if(isdigit(token[0])) { &amp;temp.type = 12; &amp;temp.attribute = token[0]; } else if(strcmp(token, "") != 0) { &amp;temp.type = 10; &amp;temp.attribute = token; } return temp; } *TOKEN parseChar(char token) { TOKEN *temp = malloc(sizeof(TOKEN)); if(token == '+' || token == '-') { &amp;temp.type = 14; &amp;temp.attribute = token; } else if(token == '/' || token == '*' || token == '%') { &amp;temp.type = 13; &amp;temp.attribute = token; } else if(token == '=') &amp;temp.type = 3; else if(token == ';') &amp;temp.type = 17; else if(token == '(') &amp;temp.type = 15; else if(token ==')') &amp;temp.type = 16; return temp; } </code></pre> <p>Here's the parser.h file that has the TOKEN in it described.</p> <pre><code>#ifndef _parser_h #define _parser_h typedef enum token_type { Id, keyword, num, addOp, multOp, assignment, semicolon, lparen, rparen }TOKEN_TYPE; typedef struct token{ TOKEN_TYPE type; char* attribute; }TOKEN; typedef enum node_type { PROGRAM, statement, assignStmt, repeatStmt, printStmt, exp, term, factor }NODE_TYPE; #endif </code></pre> <p>It just keeps saying where ever I declare the function name that I am missing a '(' before the TOKEN.</p> <p>Any help would be great. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload