tab2sim_scan.l 2.09 KB
/* tab2sim_scan.l - Tokenizer */

%p 6500
%a 4200
%o 4700

digit		[0-9]
vecdigit	[0-9xXzZ]
hexdigit	[0-9a-fA-FxXzZ]
alpha		[a-z_A-Z]
dot		[.]
blank		[ ]
underscore	[_]
colon		[:]
lbrk		[\[]
rbrk		[\]]
lpar            [\(]
rpar            [\)]
hex		0x{hexdigit}+
number		{vecdigit}+
float 		{digit}*{dot}{digit}+
input		[@][Ii]
output		[@][Oo]
bidir 		[@][Bb]
edge  		[@][Ee]
strobe		[@][Ss]
clock		[@][Cc]
dclock		[@][Dd][Cc]
valid		[@][Vv]
ident		({alpha}|{dot}|{underscore})*{alpha}({alpha}|{digit}|{dot}|{underscore})*
comment		#[^\n]*\n
endofline	[\n]
skip		[ \t]
backslash	[\\]

%%
{hex}		{ install_number(yytext, 16); return (tHEX);	}
{number}	{ install_number(yytext, 10); if(VectorPhase) return (tBIN);
					      else return (tNUMBER);	}
{float}		{ install_float(yytext); return (tFLOAT); }
{input}		{ return (tINPUT);	}
{output}	{ return (tOUTPUT);	}
{bidir}		{ return (tBIDIR);	}
{edge}		{ return (tEDGE);	}
{strobe}	{ return (tSTROBE);	}
{clock}		{ return (tCLOCK);	}
{dclock}	{ return (tDCLOCK);	}
{valid}		{ return (tVALID);	}
{colon}		{ return (tCOLON);	}
{lbrk}		{ return (tLBRACK);	}
{rbrk}		{ return (tRBRACK);	}
{lpar}          { return (tLPAREN);     }
{rpar}          { return (tRPAREN);     }

{ident}		{ install(yytext); return (tIDENT);	}

{backslash}	{ int c;  while ( (c = input()) != '\n' &&
		   		c != EOF )
				;  /* eat up input til next line */
		}
{endofline}	{ line_num++; return (tEOL);	}
{comment}	{ line_num++; echo_comment(yytext);	}
{skip}		;
.		{ return (tJUNK);	}
%%

int yywrap()
{
   return(1);
}


void install_number(char *str, int base)
{
  if(!VectorPhase)
  {
     yylval.ival =  strtol (str, NULL, base); 
  }
  else
  {
    (void) strncpy(yylval.name, str, TOKENSIZ-1);
    yylval.name[TOKENSIZ-1] = '\0';
  }
}

void install_float(char *str)
{
   yylval.fval = atof(str);
}


void install(char *str)
{
   (void) strncpy(yylval.name, str, TOKENSIZ-1);
   yylval.name[TOKENSIZ-1] = '\0';
}

void echo_comment(char *comment)
{
  if(EchoComments)
    fprintf(Vecfp,"echo %s", comment);
}

void
  yyerror(str)
char *str;
{
  fprintf(stderr,"******* Error line: %d *********\n", line_num+1);
}