QFuullY
QFuullY

Reputation: 17

Error EOF inside action Flex

I am creating a file that will be compiled with flex, but I am having trouble understanding why I am getting this error. I am inexperienced with this. The error says line 43 (ie the last line) end of file inside the action. What I have so far.

%{
#ifdef PRINT
#define TOKEN(t) printf("Token: " #t "/n");
#else
#define TOKEN(t) return(t);
#endif
%}

%%
"," TOKEN(COMMA")
";" TOKEN(SEMICOLON)
"->"    TOKEN(ARROW)
"(" TOKEN(BRA)
")" TOKEN(KET)
"=" TOKEN(EQUALS)
"<>"    TOKEN(LESMORE)
 "<" TOKEN(LESS)_THAN)
 ">" TOKEN(MORE_THAN)
 "<="    TOKEN(LESS_EQUAL)
 ">="    TOKEN(MORE_EQUAL)
 "*" TOKEN(MULTIPLY)
 "/"    TOKEN(DIVIDE)
 "'"    TOKEN(CHAR_SHOW)
 ENDP    TOKEN(ENDP)
 DECLARATIONS    TOKEN(DECLARATIONS)
 CHARACTER   TOKEN(CHARACTER)
 INTEGER TOKEN(INTEGER)
 REAL    TOKEN(REAL)
 ENDIF   TOKEN(ENDIF)
 ELSE    TOKEN(ELSE)
 ENDDO   TOKEN(ENDDO)
 WHILE   TOKEN(WHILE)
 DO  TOKEN(DO)
 ENDWHILE    TOKEN(ENDWHILE)
 FOR TOKEN(FOR)
 IS  TOKEN(IS)
 BY  TOKEN(BY)
 TO  TOKEN(TO)
 ENDFOR  TOKEN(ENDFOR)
 WRITE   TOKEN(WRITE)
 NEWLINE TOKEN(NEWLINE)
 READ    TOKEN(READ)
 %%

Any help is appreciated

Upvotes: 0

Views: 384

Answers (2)

Tahar HARAZ
Tahar HARAZ

Reputation: 124

You have two Typos, you have to change that to :

            Line 10 :         "," TOKEN(COMMA")       -->     "," TOKEN(COMMA)

            Line 17:          "<" TOKEN(LESS)_THAN)   -->     "<" TOKEN(LESS_THAN)

Upvotes: 0

rici
rici

Reputation: 241791

The first action is:

"," TOKEN(COMMA")

which has a mismatched quote.

Also, there is a problem with

 "<" TOKEN(LESS)_THAN)

And it is not clear to me if all the lines from that one down are incorrectly indented by one space; if so, that is also a problem.

Finally, there is very little point in that TOKEN macro (which is probably copied from somewhere else where it is unnecessary) because you can use the --debug command-line option to Flex to produce very accurate scanner traces, and there is a similar tracing facility in bison which will also reveal the result of the scanner (including the name of the token, which the flex trace does not, unfortunately, provide).

Upvotes: 1

Related Questions