error: expected identifier before ‘(’ token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nina01
    New Member
    • Jan 2009
    • 8

    error: expected identifier before ‘(’ token

    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******
    Code:
    /* A Bison parser, made by GNU Bison 2.3.  */
    ....
    ......
    /* Tokens.  */
    #ifndef YYTOKENTYPE
    # define YYTOKENTYPE
       /* Put the tokens into the symbol table, so that GDB and other debuggers
          know about them.  */
       enum yytokentype {
         INTEGER_LITERAL = 258,
         IDENTIFIER = 259,
         MULT = 260,
         INT = 261,
         NEW = 262,
         THIS = 263,
         BOOLEAN = 264,
         IF = 265,
         WHILE = 266,
         SYSTEM_OUT_PRINTLN = 267,
         LENGTH = 268,
         FALSE = 269,
         TRUE = 270,
         ELSE = 271,
         EOF = 272,
         AND = 273,
         MINUS = 274,
         INF = 275,
         PLUS = 276
       };
    #endif
    /* Tokens.  */
    #define INTEGER_LITERAL 258
    #define IDENTIFIER 259
    #define MULT 260
    #define INT 261
    #define NEW 262
    #define THIS 263
    #define BOOLEAN 264
    #define IF 265
    #define WHILE 266
    #define SYSTEM_OUT_PRINTLN 267
    #define LENGTH 268
    #define FALSE 269
    #define TRUE 270
    #define ELSE 271
    #define EOF 272     [B]// line 56[/B]
    #define AND 273
    #define MINUS 274
    #define INF 275
    #define PLUS 276
    
    #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
    typedef int YYSTYPE;
    # define yystype YYSTYPE /* obsolescent; will be withdrawn */
    # define YYSTYPE_IS_DECLARED 1
    # define YYSTYPE_IS_TRIVIAL 1
    #endif
    
    extern YYSTYPE yylval;
    HELP please!
    Thanks in advance!
    Last edited by pbmods; Jan 23 '09, 11:03 PM. Reason: Added CODE tags.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Is anything included before, like
    stdin.h, where..
    Code:
    #define	EOF	(-1)
    Try to change EOF to something else...

    Comment

    • nina01
      New Member
      • Jan 2009
      • 8

      #3
      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...

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        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.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by nina01
          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...

          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:

          Code:
          #ifdef EOF
          #undef EOF
          #endif
          Or simply use another name in your .l or .y file, e.g. ENDF will do.

          kind regards,

          Jos

          Comment

          • nina01
            New Member
            • Jan 2009
            • 8

            #6
            I've renamed the token and now it works.
            Thanks for all those who replied to my question!

            Comment

            Working...