Thread: problem with lex?

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    problem with lex?

    Hi, I wrote a lex file, but when I try to compile it, I get this error:

    l3.lex:64: parse error before `{'

    I don't see any errors.

    Here is my code:
    Code:
    %{
    %}
    
    /* regular definitions */
    
    blank		[ \t\n]
    ws		{blank}+
    comment 	[\{]([^\{\n])*[\}]
    letter 		[a-zA-Z]
    digit 		[0-9]
    id    		{letter}({letter}|{digit})*
    digits 		{digit}+
    optional_frac	(\.{digits})?
    optional_Iexp	(E[+]?{digits})?
    optional_Rexp	(E[+|-]?{digits})?
    inum		{digits}({optional_Iexp})
    rnum		{digits}({optional_frac})({optional_Rexp})
    
    %%
    
    {ws}		{// Do Nothing}
    {comment} 	{// Do Nothing}
    program		{return(PROGRAM);}
    var		{return(VAR);}
    array		{return(ARRAY);}
    of		{return(OF);}
    real		{return(REAL);}
    integer 	{return(INTEGER);}
    function 	{return(FUNC);}
    procedure 	{return(PROC);}
    begin		{return(BEG);}
    end		{return(END);}
    if		{return(IF);}
    else		{return(ELSE);}
    then		{return(THEN);}
    while		{return(WHILE);}
    do		{return(DO);}
    or		{return(ADDOP);}
    not		{return(NOT);}
    and		{return(MULOP);}
    div		{return(MULOP);}
    mod		{return(MULOP);}
    {id}		{install_id(); return(ID);}
    {inum}  	{install_iNum(); return(INUM);}
    {rnum}  	{install_rNum(); return(RNUM);}
    ":="		{return(ASSIGNOP);}
    "="		{return(RELOP);}
    "<>"		{return(RELOP);}
    "<"		{return(RELOP);}
    "<="		{return(RELOP);}
    ">="		{return(RELOP);}
    ">"		{return(RELOP);}
    "*"		{return(MULOP);}
    "/"		{return(MULOP);}
    .		{return yytext[0];}
    
    %%
    
    install_id()  {
    
      pTmp=findEntry(yytext);
      if ( pTmp == NULL )
    	pTmp=addEntry(yytext);
    
      if ( pTmp == NULL ) {
    	fprintf(stderr, "Error: Could not insert %s into symbol table.\n", 
    yytext);
    	exit(1);	
      }
      
      yylval.id_info.pEntry=pTmp;
    
    }
    
    install_iNum()  {
      
      yylval.iVal = atoi(yytext);
    }  
      
    install_rNum()  {
      
      yylval.rVal = atof(yytext);
    }
    Can anyone see anything wrong with this code?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: problem with lex?

    Originally posted by LiLgirL
    Hi, I wrote a lex file, but when I try to compile it, I get this error:

    ..snip...

    Can anyone see anything wrong with this code?
    You mean aside from the fact that this is the C board and not a Lex board?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >.		{return yytext[0];}
    Wild guess, maybe you need quotes around the dot:
    "." {return yytext[0];}

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Thanks for the ideas.

    The problem was here:

    Code:
    {ws}		{// Do Nothing}
    {comment} 	{// Do Nothing}
    The // was commenting out the closing braces as well, therefore causing the parse error. :-)

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Wow, I would have never spotted that! Talk about hidden. Glad you found it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM