By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,412 Members | 2,896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,412 IT Pros & Developers. It's quick & easy.

error: expected identifier before ‘(’ token

P: 8
Hi!
I'm working on a mini compiler with flex and bison. The ".l" and ".y" files are generated successfully. However, when I try to compile the hole thing using the command "gcc -o comp comp.tab.c lex.yy.c ", I keep having this error :-(

In file included from comp.l:4:
comp.tab.h:56: error: expected identifier before ‘(’ token


It's supposed to be a syntax error but I honestly don't know where does it come from knowing that the file "comp.tab.h" is generated by bison...

*******comp.tab.h******
Expand|Select|Wrap|Line Numbers
  1. /* A Bison parser, made by GNU Bison 2.3.  */
  2. ....
  3. ......
  4. /* Tokens.  */
  5. #ifndef YYTOKENTYPE
  6. # define YYTOKENTYPE
  7.    /* Put the tokens into the symbol table, so that GDB and other debuggers
  8.       know about them.  */
  9.    enum yytokentype {
  10.      INTEGER_LITERAL = 258,
  11.      IDENTIFIER = 259,
  12.      MULT = 260,
  13.      INT = 261,
  14.      NEW = 262,
  15.      THIS = 263,
  16.      BOOLEAN = 264,
  17.      IF = 265,
  18.      WHILE = 266,
  19.      SYSTEM_OUT_PRINTLN = 267,
  20.      LENGTH = 268,
  21.      FALSE = 269,
  22.      TRUE = 270,
  23.      ELSE = 271,
  24.      EOF = 272,
  25.      AND = 273,
  26.      MINUS = 274,
  27.      INF = 275,
  28.      PLUS = 276
  29.    };
  30. #endif
  31. /* Tokens.  */
  32. #define INTEGER_LITERAL 258
  33. #define IDENTIFIER 259
  34. #define MULT 260
  35. #define INT 261
  36. #define NEW 262
  37. #define THIS 263
  38. #define BOOLEAN 264
  39. #define IF 265
  40. #define WHILE 266
  41. #define SYSTEM_OUT_PRINTLN 267
  42. #define LENGTH 268
  43. #define FALSE 269
  44. #define TRUE 270
  45. #define ELSE 271
  46. #define EOF 272     // line 56
  47. #define AND 273
  48. #define MINUS 274
  49. #define INF 275
  50. #define PLUS 276
  51.  
  52. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  53. typedef int YYSTYPE;
  54. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  55. # define YYSTYPE_IS_DECLARED 1
  56. # define YYSTYPE_IS_TRIVIAL 1
  57. #endif
  58.  
  59. extern YYSTYPE yylval;
  60.  
HELP please!
Thanks in advance!
Jan 23 '09 #1
Share this Question
Share on Google+
5 Replies


100+
P: 687
Is anything included before, like
stdin.h, where..
Expand|Select|Wrap|Line Numbers
  1. #define    EOF    (-1)
  2.  
Try to change EOF to something else...
Jan 23 '09 #2

P: 8
Hi again,
In fact I removed the lines "EOF=272" & "#define EOF 272" and the error disappeared... I guess there was a name collision or something like that...
Jan 23 '09 #3

Expert 100+
P: 2,400
Did you define a token named EOF in your grammar? If so, then you may have inadvertently directed bison to create the namespace collision. Try renaming your token and rebuilding.
Jan 24 '09 #4

Expert 10K+
P: 11,448
@nina01

Before you include that generated bison file better undefine that EOF macro first; removeing it from the list mutilates the tokenizer and it won't work properly anymore. Add the following lines before you include that generated file:

Expand|Select|Wrap|Line Numbers
  1. #ifdef EOF
  2. #undef EOF
  3. #endif
  4.  
Or simply use another name in your .l or .y file, e.g. ENDF will do.

kind regards,

Jos
Jan 24 '09 #5

P: 8
I've renamed the token and now it works.
Thanks for all those who replied to my question!
Jan 24 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.