speclex.l 3.25 KB
%{
#include <bstring.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "makedisk.h"
#include "y.tab.h"

static void skipComments(void);
static void skipPound(void);

int	lineNumber = 1;

%}

%%

\n		{
			lineNumber++;
		}
"/*"		{
			skipComments();
		}			
"#"		{
			skipPound();
		}
[ \t]*		{
			/* skip white space */
		}
"address"	{
			yylval.integer = ADDRESS;
			return(ADDRESS);
		}
"after"		{
			yylval.integer = AFTER;
			return(AFTER);
		}
"align"		{
			yylval.integer = ALIGN;
			return(ALIGN);
		}
"beginseg"	{
			yylval.integer = BEGINSEG;
			return(BEGINSEG);
		}
"beginwave"	{
			yylval.integer = BEGINWAVE;
			return(BEGINWAVE);
		}
"BOOT"		{
			yylval.integer = BOOT;
			return(BOOT);
		}
"CART"          {
			yylval.integer = CART;
			return(CART);
		}
"DISK"          {
			yylval.integer = DISK;
			return(DISK);
		}
"endseg"	{
			yylval.integer = ENDSEG;
			return(ENDSEG);
		}
"endwave"	{
			yylval.integer = ENDWAVE;
			return(ENDWAVE);
		}
"entry"		{
			yylval.integer = ENTRY;
			return(ENTRY);
		}
"flags"		{
			yylval.integer = FLAGS;
			return(FLAGS);
		}
"include"	{
			yylval.integer = INCLUDE;
			return(INCLUDE);
		}
"lba"           {
                        yylval.integer = LBA;
                        return(LBA);
                }
"max"		{
			yylval.integer = MAXFUNC;
			return(MAXFUNC);
		}
"maxsize"	{
			yylval.integer = MAXSIZE;
			return(MAXSIZE);
		}
"media"	        {
			yylval.integer = MEDIA;
			return(MEDIA);
		}
"min"		{
			yylval.integer = MINFUNC;
			return(MINFUNC);
		}
"name"		{
			yylval.integer = NAME;
			return(NAME);
		}
"number"	{
			yylval.integer = NUMBER;
			return(NUMBER);
		}
"NONE"	        {
			yylval.integer = NONE;
			return(NONE);
		}
"OBJECT"	{
			yylval.integer = OBJECT;
			return(OBJECT);
		}
"RAMSTART"      {
                        yylval.integer = RAMSTART;
                        return(RAMSTART);
                }
"RAW"		{
			yylval.integer = RAW;
			return(RAW);
		}
"stack"		{
			yylval.integer = STACK;
			return(STACK);
		}
"+"		{
			yylval.integer = PLUS;
			return(PLUS);
		}
"["		{
			yylval.integer = LPAREN;
			return(LPAREN);
		}
"]"		{
			yylval.integer = RPAREN;
			return(RPAREN);
		}
","		{
			yylval.integer = COMMA;
			return(COMMA);
		}
0x[0-9a-fA-F]+	{
			sscanf(yytext, "%x", &yylval.integer);
			return(CONSTANT);
		}
("+"|-)?[0-9]+	{ 
			yylval.integer = atoi(yytext);
			return(CONSTANT); 
		}

[a-zA-Z0-9$_()\./]+	{ 
			yylval.string = (char *) malloc(strlen(yytext)+1);
			strcpy(yylval.string, yytext);
			return(IDENTIFIER); 
		}			
\"[a-zA-Z0-9$_()\./]*\"	{ 
			yytext[strlen(yytext)-1] = '\0';
			yylval.string = (char *) malloc(strlen(yytext)-1);
			strcpy(yylval.string, &yytext[1]);
			return(IDENTIFIER); 
		}
.		{
			yyerror("Illegal character");
		}
%%
static void
skipComments(void)
{
	for (;;) {
		while (input() != '*');
		if (input() != '/') {
			unput(yytext[yyleng-1]);
		} else {
			return;
		}
	}
}

static void
skipPound(void)
{
	int     i = 0, lnumber;
	char    c, poundbuf[256], fname[_POSIX_PATH_MAX];

	while ((c = input()) != '\n')
		poundbuf[i++] = c;

	poundbuf[i] = '\0';
	if (sscanf(poundbuf, " %d \"%s\"",&lnumber, fname) == 2) {
		fname[strlen(fname)-1] = '\0';
		if (strcmp(fileName, fname) == 0)
			lineNumber = lnumber-1;
	}
	lineNumber++;
}