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