1abbeb05aStoy %{ 2b887afb5Sbostic /*- 3*557ac071Sbostic * Copyright (c) 1980, 1993 4*557ac071Sbostic * The Regents of the University of California. All rights reserved. 5824762f1Sdist * 6b887afb5Sbostic * %sccs.include.redist.c% 7c6f0e010Skarels * 8*557ac071Sbostic * @(#)lang.l 8.1 (Berkeley) 06/06/93 9824762f1Sdist */ 10abbeb05aStoy 11abbeb05aStoy #include <ctype.h> 12abbeb05aStoy #include "y.tab.h" 13abbeb05aStoy #include "config.h" 14abbeb05aStoy 15abbeb05aStoy #define tprintf if (do_trace) printf 16856f1231Stoy 17abbeb05aStoy /* 18abbeb05aStoy * Key word table 19abbeb05aStoy */ 20abbeb05aStoy 21abbeb05aStoy struct kt { 22abbeb05aStoy char *kt_name; 23abbeb05aStoy int kt_val; 24abbeb05aStoy } key_words[] = { 252596fdabSsam { "and", AND }, 262596fdabSsam { "args", ARGS }, 272596fdabSsam { "at", AT }, 285538cde1Swilliam #if MACHINE_I386 295538cde1Swilliam { "bio", BIO }, 305538cde1Swilliam #endif MACHINE_I386 312596fdabSsam { "config", CONFIG }, 322596fdabSsam { "controller", CONTROLLER }, 332596fdabSsam { "cpu", CPU }, 342596fdabSsam { "csr", CSR }, 352596fdabSsam { "device", DEVICE }, 362596fdabSsam { "disk", DISK }, 372596fdabSsam { "drive", DRIVE }, 385538cde1Swilliam #if MACHINE_I386 395538cde1Swilliam { "drq", DRQ }, 405538cde1Swilliam #endif MACHINE_I386 412596fdabSsam { "dst", DST }, 422596fdabSsam { "dumps", DUMPS }, 432596fdabSsam { "flags", FLAGS }, 442596fdabSsam { "hz", HZ }, 452596fdabSsam { "ident", IDENT }, 469043557dShibler { "interleave", INTERLEAVE }, 475538cde1Swilliam #if MACHINE_I386 485538cde1Swilliam { "iomem", IOMEM }, 495538cde1Swilliam { "iosiz", IOSIZ }, 505538cde1Swilliam { "irq", IRQ }, 515538cde1Swilliam #endif MACHINE_I386 522596fdabSsam { "machine", MACHINE }, 532596fdabSsam { "major", MAJOR }, 543081944dSkarels { "makeoptions", MAKEOPTIONS }, 552596fdabSsam { "master", MASTER }, 562596fdabSsam { "maxusers", MAXUSERS }, 572596fdabSsam { "minor", MINOR }, 585538cde1Swilliam #if MACHINE_I386 595538cde1Swilliam { "net", NET }, 605538cde1Swilliam #endif MACHINE_I386 612596fdabSsam { "nexus", NEXUS }, 622596fdabSsam { "on", ON }, 632596fdabSsam { "options", OPTIONS }, 645538cde1Swilliam #if MACHINE_I386 655538cde1Swilliam { "port", PORT }, 665538cde1Swilliam #endif MACHINE_I386 672596fdabSsam { "priority", PRIORITY }, 682596fdabSsam { "pseudo-device",PSEUDO_DEVICE }, 692596fdabSsam { "root", ROOT }, 70d9b3fc46Smckusick #if MACHINE_HP300 || MACHINE_LUNA68K 715388980dSmckusick { "scode", NEXUS }, 725388980dSmckusick #endif 739043557dShibler { "sequential", SEQUENTIAL }, 742596fdabSsam { "size", SIZE }, 752596fdabSsam { "slave", SLAVE }, 762596fdabSsam { "swap", SWAP }, 772596fdabSsam { "tape", DEVICE }, 785538cde1Swilliam #if MACHINE_I386 795538cde1Swilliam { "tty", TTY }, 805538cde1Swilliam #endif MACHINE_I386 812596fdabSsam { "timezone", TIMEZONE }, 822596fdabSsam { "trace", TRACE }, 832596fdabSsam { "vector", VECTOR }, 842596fdabSsam { 0, 0 }, 85abbeb05aStoy }; 86abbeb05aStoy %} 87856f1231Stoy WORD [A-Za-z_][-A-Za-z_]* 88abbeb05aStoy %% 89abbeb05aStoy {WORD} { 90abbeb05aStoy int i; 91abbeb05aStoy 92abbeb05aStoy if ((i = kw_lookup(yytext)) == -1) 93abbeb05aStoy { 94d0585f4aSroot yylval.str = yytext; 95abbeb05aStoy tprintf("id(%s) ", yytext); 96abbeb05aStoy return ID; 97abbeb05aStoy } 98abbeb05aStoy tprintf("(%s) ", yytext); 99abbeb05aStoy return i; 100abbeb05aStoy } 101162e41f0Stoy \"[^"]+\" { 102162e41f0Stoy yytext[strlen(yytext)-1] = '\0'; 1032596fdabSsam yylval.str = yytext + 1; 104162e41f0Stoy return ID; 105162e41f0Stoy } 106abbeb05aStoy 0[0-7]* { 107d0585f4aSroot yylval.val = octal(yytext); 108d0585f4aSroot tprintf("#O:%o ", yylval.val); 109abbeb05aStoy return NUMBER; 110abbeb05aStoy } 111f038f5dcSsam 0x[0-9a-fA-F]+ { 112d0585f4aSroot yylval.val = hex(yytext); 113d0585f4aSroot tprintf("#X:%x ", yylval.val); 114abbeb05aStoy return NUMBER; 115abbeb05aStoy } 116abbeb05aStoy [1-9][0-9]* { 117d0585f4aSroot yylval.val = atoi(yytext); 118d0585f4aSroot tprintf("#D:%d ", yylval.val); 119abbeb05aStoy return NUMBER; 120abbeb05aStoy } 121ba1a8baaStoy [0-9]"."[0-9]* { 122d0585f4aSroot double atof(); 123d0585f4aSroot yylval.val = (int) (60 * atof(yytext) + 0.5); 124ba1a8baaStoy return FPNUMBER; 125ba1a8baaStoy } 126f96dda53Sroot "-" { 127f96dda53Sroot return MINUS; 128f96dda53Sroot } 129abbeb05aStoy "?" { 130d0585f4aSroot yylval.val = -1; 131abbeb05aStoy tprintf("? "); 132abbeb05aStoy return NUMBER; 133abbeb05aStoy } 134abbeb05aStoy \n/[ \t] { 135abbeb05aStoy yyline++; 136abbeb05aStoy tprintf("\n... "); 137abbeb05aStoy } 138abbeb05aStoy \n { 139abbeb05aStoy yyline++; 140abbeb05aStoy tprintf("\n"); 141abbeb05aStoy return SEMICOLON; 142abbeb05aStoy } 1432fcb4d4fSkre #.* { /* Ignored (comment) */; } 144abbeb05aStoy [ \t]* { /* Ignored (white space) */; } 145abbeb05aStoy ";" { return SEMICOLON; } 1467a8801a6Stoy "," { return COMMA; } 1472fcb4d4fSkre "=" { return EQUALS; } 148d9bdcdf4Sroot "@" { return AT; } 1492fcb4d4fSkre . { return yytext[0]; } 1502fcb4d4fSkre 151abbeb05aStoy %% 152abbeb05aStoy /* 153abbeb05aStoy * kw_lookup 154abbeb05aStoy * Look up a string in the keyword table. Returns a -1 if the 155abbeb05aStoy * string is not a keyword otherwise it returns the keyword number 156abbeb05aStoy */ 157abbeb05aStoy 158abbeb05aStoy kw_lookup(word) 159abbeb05aStoy register char *word; 160abbeb05aStoy { 161abbeb05aStoy register struct kt *kp; 162abbeb05aStoy 163abbeb05aStoy for (kp = key_words; kp->kt_name != 0; kp++) 164abbeb05aStoy if (eq(word, kp->kt_name)) 165abbeb05aStoy return kp->kt_val; 166abbeb05aStoy return -1; 167abbeb05aStoy } 168abbeb05aStoy 169abbeb05aStoy /* 170abbeb05aStoy * Number conversion routines 171abbeb05aStoy */ 172abbeb05aStoy 173abbeb05aStoy octal(str) 174abbeb05aStoy char *str; 175abbeb05aStoy { 176abbeb05aStoy int num; 177abbeb05aStoy 178d0585f4aSroot (void) sscanf(str, "%o", &num); 179abbeb05aStoy return num; 180abbeb05aStoy } 181abbeb05aStoy 182abbeb05aStoy hex(str) 183abbeb05aStoy char *str; 184abbeb05aStoy { 185abbeb05aStoy int num; 186abbeb05aStoy 187d0585f4aSroot (void) sscanf(str+2, "%x", &num); 188abbeb05aStoy return num; 189abbeb05aStoy } 190