tab2wvs_scan.l 1.72 KB
/* tab2wvs_scan.l - Tokenizer for register level simulation */

%p 6500
%a 4200
%o 4700

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

%%
{number}	{ install_number(yytext, 10); return (tNUMBER);	}
{hex}		{ install_number(yytext, 16); return (tHEX);	}
{input}		{ return (tINPUT);	}
{output}	{ return (tOUTPUT);	}
{bidir}		{ return (tBIDIR);	}
{edge}		{ return (tEDGE);	}
{strobe}	{ return (tSTROBE);	}
{clock}		{ return (tCLOCK);	}
{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}	{ return (tEOL);	}
{comment}	;
{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(char *str)
{
   (void) strncpy(yylval.name, str, TOKENSIZ-1);
   yylval.name[TOKENSIZ-1] = '\0';
}

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