C and a bit of yacc/flex

This is a discussion on C and a bit of yacc/flex within the C Programming forums, part of the General Programming Boards category; Okay, so I had this code in my .l file (scanner file): Code: TokenType getToken(void) { static int firstTime = ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    C and a bit of yacc/flex

    Okay, so I had this code in my .l file (scanner file):

    Code:
       
    TokenType getToken(void)   
    {   
        static int firstTime = TRUE;   
        TokenType currentToken;   
        if (firstTime) {   
            firstTime = FALSE;   
            lineno++;   
            yyin = stdin;   
            yyout = stderr;   
        }   
        currentToken = yylex(); 
        strncpy(tokenString, yytext, MAXTOKENLEN);   
        return currentToken;   
    }
    TokenType is basically:
    typedef int TokenType;

    declared in one of my .h file

    and I have this code in my .y file:

    Code:
    static TokenType yylex(void) { 
      return getToken(); 
    }
    The problem is that by doing this, the scanner always looks ahead once of the necessary, in other words when it has reached the end of the file.. it keeps on reading once then it finishes.. This is not what I want, I want it to terminate right after it reads the end of file.
    Last edited by -EquinoX-; 10-19-2008 at 09:24 AM.

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    can anyone please help me?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21