Make options like NO_F00F_HACK work (with context sensitive lexical rules).

This commit is contained in:
Luoqi Chen 1999-04-27 01:37:01 +00:00
parent 24de4f3b19
commit e07fcb3e2e
2 changed files with 45 additions and 30 deletions

View File

@ -59,8 +59,7 @@
%token <val> FPNUMBER
%type <str> Save_id
%type <str> Opt_name
%type <str> Opt_string
%type <str> Opt_value
%type <str> Dev
%type <str> device_name
%type <val> major_minor
@ -165,7 +164,7 @@ Spec:
;
Config_spec:
MACHINE Opt_string
MACHINE Save_id
= {
if (!strcmp($2, "i386")) {
machine = MACHINE_I386;
@ -179,7 +178,7 @@ Config_spec:
} else
yyerror("Unknown machine type");
} |
CPU Opt_string
CPU Save_id
= {
struct cputype *cp =
(struct cputype *)malloc(sizeof (struct cputype));
@ -385,7 +384,7 @@ Opt_list:
;
Option:
Opt_string
Save_id
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
char *s;
@ -405,7 +404,7 @@ Option:
op->op_value = ns(s + 1);
}
} |
Opt_string EQUALS Opt_string
Save_id EQUALS Opt_value
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
@ -416,7 +415,7 @@ Option:
opt = op;
} ;
Opt_name:
Opt_value:
ID
= { $$ = $1; } |
NUMBER
@ -426,16 +425,6 @@ Opt_name:
(void) snprintf(buf, sizeof(buf), "%d", $1);
$$ = ns(buf);
} ;
Opt_string:
Opt_name
= { $$ = $1; } |
Opt_name Opt_string
= {
char buf[80];
(void) snprintf(buf, sizeof(buf), "%s%s", $1, $2);
$$ = ns(buf); free($1); free($2);
} ;
Save_id:
ID
@ -449,7 +438,7 @@ Mkopt_list:
;
Mkoption:
Opt_string EQUALS Opt_string
Save_id EQUALS Opt_value
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));

View File

@ -105,11 +105,14 @@ int octal __P((char *));
int hex __P((char *));
%}
WORD [-A-Za-z_][-A-Za-z_]*
WORD [A-Za-z_][-A-Za-z_]*
ID [A-Za-z_][-A-Za-z_0-9]*
%START NONUM TOEOL
%%
{WORD} {
<NONUM>{WORD} {
int i;
BEGIN 0;
if ((i = kw_lookup(yytext)) == -1)
{
yylval.str = strdup(yytext);
@ -119,15 +122,42 @@ WORD [-A-Za-z_][-A-Za-z_]*
tprintf("(%s) ", yytext);
return i;
}
<INITIAL>{WORD}/[0-9]* {
int i;
if ((i = kw_lookup(yytext)) == -1)
REJECT;
if (i == CONTROLLER || i == DEVICE || i == DISK ||
i == PSEUDO_DEVICE || i == AT || i == ON)
BEGIN NONUM;
tprintf("(%s) ", yytext);
return i;
}
<INITIAL>{ID} {
BEGIN 0;
yylval.str = strdup(yytext);
tprintf("id(%s) ", yytext);
return ID;
}
\\\"[^"]+\\\" {
yytext[strlen(yytext)-2] = '"';
yytext[strlen(yytext)-1] = '\0';
BEGIN 0;
yytext[yyleng-2] = '"';
yytext[yyleng-1] = '\0';
yylval.str = strdup(yytext + 1);
tprintf("id(%s) ", yytext+1);
return ID;
}
\"[^"]+\" {
yytext[strlen(yytext)-1] = '\0';
BEGIN 0;
yytext[yyleng-1] = '\0';
yylval.str = strdup(yytext + 1);
tprintf("id(%s) ", yytext+1);
return ID;
}
<TOEOL>[^#\n]* {
BEGIN 0;
yylval.str = strdup(yytext);
tprintf("id(%s) ", yytext);
return ID;
}
0[0-7]* {
@ -140,18 +170,14 @@ WORD [-A-Za-z_][-A-Za-z_]*
tprintf("#X:%x ", yylval.val);
return NUMBER;
}
-[1-9][0-9]* {
yylval.val = atoi(yytext);
tprintf("#D:%d ", yylval.val);
return NUMBER;
}
[1-9][0-9]* {
-?[1-9][0-9]* {
yylval.val = atoi(yytext);
tprintf("#D:%d ", yylval.val);
return NUMBER;
}
[0-9]"."[0-9]* {
yylval.val = (int) (60 * atof(yytext) + 0.5);
tprintf("#F:%d ", yylval.val);
return FPNUMBER;
}
"?" {
@ -172,7 +198,7 @@ WORD [-A-Za-z_][-A-Za-z_]*
[ \t\f]* { /* Ignored (white space) */; }
";" { return SEMICOLON; }
"," { return COMMA; }
"=" { return EQUALS; }
"=" { BEGIN TOEOL; return EQUALS; }
"@" { return AT; }
. { return yytext[0]; }