Thread: Lex Help

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    Lex Help

    I am trying to implement a simple program in LEX but it is giving error.
    I am doing it in Ubuntu.

    Code:
    %{
    #include <stdio.h>
    %}
    
    digit         [0-9]
    letter        [A-Za-z]
    
    
    %%
        /*** Rules section ***/
    
       {letter} { return 1; }
    
    %%
    /*** C Code section ***/
    
    int main(void)
    {
        /* Call the lexer, then quit. */
        yylex();
        return 0;
    }

    Code:
    text.lex: In function ‘yylex’:
    text.lex:13: error: ‘letter’ undeclared (first use in this function)
    text.lex:13: error: (Each undeclared identifier is reported only once
    text.lex:13: error: for each function it appears in.)
    text.lex:13: error: expected ‘;’ before ‘}’ token

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I'm using [ ] instead of curly braces so it doesn't whine about code tags...
    Move [letter] all the way to the left column on line 13. It thinks you're trying to match nothing/everything, and produce two pieces of code, one with [letter] and one with [ return 1; ]

  3. #3
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278
    Thanks it worked!

Popular pages Recent additions subscribe to a feed