1 %{ 2 /* lang.l 1.12 82/10/25 */ 3 4 #include <ctype.h> 5 #include "y.tab.h" 6 #include "config.h" 7 8 #define tprintf if (do_trace) printf 9 10 /* 11 * Key word table 12 */ 13 14 struct kt { 15 char *kt_name; 16 int kt_val; 17 } key_words[] = { 18 "machine", MACHINE, 19 "cpu", CPU, "ident", IDENT, "config", CONFIG, "options", OPTIONS, 20 "device", DEVICE, "controller", CONTROLLER, "uba", UBA, "mba", MBA, 21 "csr", CSR, "nexus", NEXUS, "drive", DRIVE, "vector", VECTOR, 22 "pseudo-device", PSEUDO_DEVICE, "flags", FLAGS, "trace", TRACE, 23 "disk", DISK, "tape", DEVICE, "slave", SLAVE, "at", AT, 24 "hz", HZ, "timezone", TIMEZONE, "dst", DST, "maxusers", MAXUSERS, 25 "master", MASTER, "priority", PRIORITY, 26 0,0, 27 }; 28 %} 29 WORD [A-Za-z_][-A-Za-z_]* 30 %% 31 {WORD} { 32 int i; 33 34 if ((i = kw_lookup(yytext)) == -1) 35 { 36 yylval.str = yytext; 37 tprintf("id(%s) ", yytext); 38 return ID; 39 } 40 tprintf("(%s) ", yytext); 41 return i; 42 } 43 \"[^"]+\" { 44 yytext[strlen(yytext)-1] = '\0'; 45 yylval.val = yytext + 1; 46 return ID; 47 } 48 0[0-7]* { 49 yylval.val = octal(yytext); 50 tprintf("#O:%o ", yylval.val); 51 return NUMBER; 52 } 53 0x[0-9a-f]+ { 54 yylval.val = hex(yytext); 55 tprintf("#X:%x ", yylval.val); 56 return NUMBER; 57 } 58 [1-9][0-9]* { 59 yylval.val = atoi(yytext); 60 tprintf("#D:%d ", yylval.val); 61 return NUMBER; 62 } 63 [0-9]"."[0-9]* { 64 double atof(); 65 yylval.val = (int) (60 * atof(yytext) + 0.5); 66 return FPNUMBER; 67 } 68 "-" { 69 return MINUS; 70 } 71 "?" { 72 yylval.val = -1; 73 tprintf("? "); 74 return NUMBER; 75 } 76 \n/[ \t] { 77 yyline++; 78 tprintf("\n... "); 79 } 80 \n { 81 yyline++; 82 tprintf("\n"); 83 return SEMICOLON; 84 } 85 #.* { /* Ignored (comment) */; } 86 [ \t]* { /* Ignored (white space) */; } 87 ";" { return SEMICOLON; } 88 "," { return COMMA; } 89 "=" { return EQUALS; } 90 "@" { return AT; } 91 . { return yytext[0]; } 92 93 %% 94 /* 95 * kw_lookup 96 * Look up a string in the keyword table. Returns a -1 if the 97 * string is not a keyword otherwise it returns the keyword number 98 */ 99 100 kw_lookup(word) 101 register char *word; 102 { 103 register struct kt *kp; 104 105 for (kp = key_words; kp->kt_name != 0; kp++) 106 if (eq(word, kp->kt_name)) 107 return kp->kt_val; 108 return -1; 109 } 110 111 /* 112 * Number conversion routines 113 */ 114 115 octal(str) 116 char *str; 117 { 118 int num; 119 120 (void) sscanf(str, "%o", &num); 121 return num; 122 } 123 124 hex(str) 125 char *str; 126 { 127 int num; 128 129 (void) sscanf(str+2, "%x", &num); 130 return num; 131 } 132