help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Flex/gcc compatibility


From: Gordon (Jake) Jacobs
Subject: Flex/gcc compatibility
Date: Wed, 19 Nov 2003 11:51:25 -0800

Hi,
 I'm trying to port some 10-year-old lex/yacc code from SUN
to a RedHat Linux8 machine which comes with flex/bison. I can
run flex on either the SUN or Linux box without any errors being
reported, yet when I try to compile the resulting c code, lex.yy.c,
I get tons of errors some examples of which are shown below:

asmLex.l:8: parse error before '*' token
asmLex.l:8: warning: data definition has no type or storage class
asmLex.l: In function `yylex':
asmLex.l:39: parse error before '<' token
asmLex.l: At top level:
asmLex.l:43: parse error before '|' token
asmLex.l:43: redefinition of `yy_start'
etc...

The errors occur with either gcc 2.95 or gcc 3.2 on either platform.

I've read the incompatibilities with lex and I use the -l flag yet I
still
get lots of basic parse errors. The lex code is fairly short and
attached below. Can anyone suggest why these problems are occurring or
any solutions for porting this simple lex script?

Thank you very much,
Gordon Jacobs
%Start COMMENT1 COMMENT2 DECLARE

DIG     [0-9]*
WRD     [a-zA-Z][a-zA-Z0-9_]*

%{
static int DECL_flag=0;
extern Equ *lookup;
#undef input()
#define input() 
(((yytchar=yysptr>yysbuf?U(*--yysptr):getc(fpinp))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
%}

%%
<COMMENT1>"*/"   { 

 /*     @(#)asmLex.l    1.2
  *     Date: 94/05/05   Time: 16:22:13
  *     Version: 1.2
  */
                   CurrentChar +=2; 
                   if(DECL_flag) BEGIN DECLARE; 
                   else BEGIN 0; 
                 }
<COMMENT1>"\n"   { CurrentChar = 0; CurrentLine++; }
<COMMENT1>[^*\n]*        |
<COMMENT1>"*"    { CurrentChar += strlen(yytext); }

<COMMENT2>"\n"   { CurrentChar = 0; CurrentLine++; 
                  if(DECL_flag) BEGIN DECLARE;
                  else BEGIN 0;
                 }
<COMMENT2>[^\n"]* { CurrentChar += strlen(yytext); }

<DECLARE>(START|start) { BEGIN 0; DECL_flag = 0; CurrentChar += 5; }
<DECLARE>[ \t]*(EQU|equ)[ \t]*{WRD}[ \t]*{DIG} 
                { /* printf("Preproc: %s\n",yytext);*/ Enter_to_table(yytext); }
<DECLARE>" "    { CurrentChar++; }
<DECLARE>"\t"   { CurrentChar = (CurrentChar+8) & 0xfffffff8; }
<DECLARE>"\n"   { CurrentChar = 0; CurrentLine++; }

(DECL|decl)     { DECL_flag = 1; BEGIN DECLARE; CurrentChar += 4; }
" "             { CurrentChar++; }
\t              { CurrentChar = (CurrentChar+8) & 0xfffffff8; }
\n              { CurrentChar = 0; CurrentLine++; }
"/*"            { BEGIN COMMENT1; CurrentChar += 2; }
";"             { BEGIN COMMENT2; CurrentChar++; return(ENDTOKEN); }
">>"            { CurrentChar += 2; 
                  if(debug) printf("SHFTOKEN\n"); return(SHFTTOKEN);
                }
"+"|"-"         { 
                  CurrentChar++;
                  if(yytext[0] == '-')
                    yylval.token = 1;
                  else
                    yylval.token = 0;
                  if(debug) printf("SUBTOKEN = %d\n",yylval.token); 
                  return(SUBTOKEN);
                }
{DIG}           { extern char *alloc_text();
                  CurrentChar += strlen(yytext);
                  yylval.token = atoi(yytext);
                  if(debug) printf("INTTOKEN = %d\n",atoi(yytext)); 
                  return(INTTOKEN);
                }
{WRD}:          { extern char *alloc_text(), *c; char *p, *rindex();
                  CurrentChar += strlen(yytext);
                  p = rindex(yytext,':');
                  *p = '\0';
                  yylval.character = alloc_text(yytext); 
                  if(debug) printf("LABELTOKEN = %s\n",(yytext)); 
                  table_update(yytext,pc);
                  return(LABELTOKEN); 
                }
{WRD}           { extern Equ *table_scan(); extern char *alloc_text(); 
                  extern int encode_keyword();
                  Equ *tmp; char msg[80]; int instr;
                  CurrentChar += strlen(yytext);
                  if(debug) printf("WORD = %s\n",(yytext)); 

                  if((instr=encode_keyword(yytext)) != (-1)) {
                     yylval.token = instr;
                     return(KEYWORD);
                  }
                  else if((tmp = table_scan(yytext)) == 0) {
                     yylval.character = alloc_text(yytext);
                     return(CHARTOKEN);
                  }
                  else {
                     yylval.token = tmp->value;
                     return(INTTOKEN);
                  }
                }
[,()=]          { CurrentChar++; 
                  /* printf("Char: %s\n",yytext);  */
                  return(*yytext);
                }

%%
yyerror(s)
    char *s;
{
        Error(s);
}
int yywrap()
{
        return(1);
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]