Like Tree1Likes
  • 1 Post By anduril462

Lex Help

This is a discussion on Lex Help within the C Programming forums, part of the General Programming Boards category; I am trying to implement a simple program in LEX but it is giving error. I am doing it in ...

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

    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,326
    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; ]
    anirban likes this.

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

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