| 1 | %{ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 1980 Regents of the University of California. |
| 5 | * All rights reserved. The Berkeley software License Agreement |
| 6 | * specifies the terms and conditions for redistribution. |
| 7 | * |
| 8 | * @(#)lang.l 5.3 (Berkeley) %G% |
| 9 | */ |
| 10 | |
| 11 | #include <ctype.h> |
| 12 | #include "y.tab.h" |
| 13 | #include "config.h" |
| 14 | |
| 15 | #define tprintf if (do_trace) printf |
| 16 | |
| 17 | /* |
| 18 | * Key word table |
| 19 | */ |
| 20 | |
| 21 | struct kt { |
| 22 | char *kt_name; |
| 23 | int kt_val; |
| 24 | } key_words[] = { |
| 25 | { "and", AND }, |
| 26 | { "args", ARGS }, |
| 27 | { "at", AT }, |
| 28 | { "config", CONFIG }, |
| 29 | { "controller", CONTROLLER }, |
| 30 | { "cpu", CPU }, |
| 31 | { "csr", CSR }, |
| 32 | { "device", DEVICE }, |
| 33 | { "disk", DISK }, |
| 34 | { "drive", DRIVE }, |
| 35 | { "dst", DST }, |
| 36 | { "dumps", DUMPS }, |
| 37 | { "flags", FLAGS }, |
| 38 | { "hz", HZ }, |
| 39 | { "ident", IDENT }, |
| 40 | { "machine", MACHINE }, |
| 41 | { "major", MAJOR }, |
| 42 | { "makeoptions", MAKEOPTIONS }, |
| 43 | { "master", MASTER }, |
| 44 | { "maxusers", MAXUSERS }, |
| 45 | { "mba", MBA }, |
| 46 | { "minor", MINOR }, |
| 47 | { "nexus", NEXUS }, |
| 48 | { "on", ON }, |
| 49 | { "options", OPTIONS }, |
| 50 | { "priority", PRIORITY }, |
| 51 | { "pseudo-device",PSEUDO_DEVICE }, |
| 52 | { "root", ROOT }, |
| 53 | { "size", SIZE }, |
| 54 | { "slave", SLAVE }, |
| 55 | { "swap", SWAP }, |
| 56 | { "tape", DEVICE }, |
| 57 | { "timezone", TIMEZONE }, |
| 58 | { "trace", TRACE }, |
| 59 | { "uba", UBA }, |
| 60 | { "vba", VBA }, |
| 61 | { "vector", VECTOR }, |
| 62 | { 0, 0 }, |
| 63 | }; |
| 64 | %} |
| 65 | WORD [A-Za-z_][-A-Za-z_]* |
| 66 | %% |
| 67 | {WORD} { |
| 68 | int i; |
| 69 | |
| 70 | if ((i = kw_lookup(yytext)) == -1) |
| 71 | { |
| 72 | yylval.str = yytext; |
| 73 | tprintf("id(%s) ", yytext); |
| 74 | return ID; |
| 75 | } |
| 76 | tprintf("(%s) ", yytext); |
| 77 | return i; |
| 78 | } |
| 79 | \"[^"]+\" { |
| 80 | yytext[strlen(yytext)-1] = '\0'; |
| 81 | yylval.str = yytext + 1; |
| 82 | return ID; |
| 83 | } |
| 84 | 0[0-7]* { |
| 85 | yylval.val = octal(yytext); |
| 86 | tprintf("#O:%o ", yylval.val); |
| 87 | return NUMBER; |
| 88 | } |
| 89 | 0x[0-9a-fA-F]+ { |
| 90 | yylval.val = hex(yytext); |
| 91 | tprintf("#X:%x ", yylval.val); |
| 92 | return NUMBER; |
| 93 | } |
| 94 | [1-9][0-9]* { |
| 95 | yylval.val = atoi(yytext); |
| 96 | tprintf("#D:%d ", yylval.val); |
| 97 | return NUMBER; |
| 98 | } |
| 99 | [0-9]"."[0-9]* { |
| 100 | double atof(); |
| 101 | yylval.val = (int) (60 * atof(yytext) + 0.5); |
| 102 | return FPNUMBER; |
| 103 | } |
| 104 | "-" { |
| 105 | return MINUS; |
| 106 | } |
| 107 | "?" { |
| 108 | yylval.val = -1; |
| 109 | tprintf("? "); |
| 110 | return NUMBER; |
| 111 | } |
| 112 | \n/[ \t] { |
| 113 | yyline++; |
| 114 | tprintf("\n... "); |
| 115 | } |
| 116 | \n { |
| 117 | yyline++; |
| 118 | tprintf("\n"); |
| 119 | return SEMICOLON; |
| 120 | } |
| 121 | #.* { /* Ignored (comment) */; } |
| 122 | [ \t]* { /* Ignored (white space) */; } |
| 123 | ";" { return SEMICOLON; } |
| 124 | "," { return COMMA; } |
| 125 | "=" { return EQUALS; } |
| 126 | "@" { return AT; } |
| 127 | . { return yytext[0]; } |
| 128 | |
| 129 | %% |
| 130 | /* |
| 131 | * kw_lookup |
| 132 | * Look up a string in the keyword table. Returns a -1 if the |
| 133 | * string is not a keyword otherwise it returns the keyword number |
| 134 | */ |
| 135 | |
| 136 | kw_lookup(word) |
| 137 | register char *word; |
| 138 | { |
| 139 | register struct kt *kp; |
| 140 | |
| 141 | for (kp = key_words; kp->kt_name != 0; kp++) |
| 142 | if (eq(word, kp->kt_name)) |
| 143 | return kp->kt_val; |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Number conversion routines |
| 149 | */ |
| 150 | |
| 151 | octal(str) |
| 152 | char *str; |
| 153 | { |
| 154 | int num; |
| 155 | |
| 156 | (void) sscanf(str, "%o", &num); |
| 157 | return num; |
| 158 | } |
| 159 | |
| 160 | hex(str) |
| 161 | char *str; |
| 162 | { |
| 163 | int num; |
| 164 | |
| 165 | (void) sscanf(str+2, "%x", &num); |
| 166 | return num; |
| 167 | } |