1 %{ 2 /* 3 * Mach Operating System 4 * Copyright (c) 1990 Carnegie-Mellon University 5 * Copyright (c) 1989 Carnegie-Mellon University 6 * Copyright (c) 1988 Carnegie-Mellon University 7 * Copyright (c) 1987 Carnegie-Mellon University 8 * All rights reserved. The CMU software License Agreement specifies 9 * the terms and conditions for use and redistribution. 10 */ 11 12 /* 13 * Copyright (c) 1980 Regents of the University of California. 14 * All rights reserved. 15 * 16 * Redistribution and use in source and binary forms are permitted 17 * provided that the above copyright notice and this paragraph are 18 * duplicated in all such forms and that any documentation, 19 * advertising materials, and other materials related to such 20 * distribution and use acknowledge that the software was developed 21 * by the University of California, Berkeley. The name of the 22 * University may not be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 26 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 * 28 * @(#)config.l 5.5 (Berkeley) 6/18/88 29 */ 30 31 #include <ctype.h> 32 #include "parser.h" 33 #include "config.h" 34 35 int kw_lookup(char *word); 36 int octal(char *str); 37 int hex(char *str); 38 int yylex(void); 39 40 #define tprintf if (do_trace) printf 41 42 /* 43 * Key word table 44 */ 45 46 struct kt { 47 const char *kt_name; 48 int kt_val; 49 } key_words[] = { 50 { "builddir", BUILDDIR }, 51 { "init", INIT }, 52 { "machine", MACHINE }, 53 { "makeoptions", MAKEOPTIONS }, 54 { "makevariables", MAKEOPTIONS }, 55 { "objectdir", OBJECTDIR }, 56 { "options", OPTIONS }, 57 { "pseudo-device",PSEUDO_DEVICE }, 58 { "sourcedir", SOURCEDIR }, 59 { "trace", TRACE }, 60 { 0, 0 }, 61 }; 62 %} 63 64 %option nounput 65 66 WORD ([A-Za-z_][-A-Za-z_]*|[A-Z][-A-Za-z_0-9]*) 67 WORD1 ([A-Za-z_][-A-Za-z_0-9]*) 68 %% 69 {WORD} | 70 {WORD1} { 71 int i; 72 73 if ((i = kw_lookup(yytext)) == -1) 74 { 75 yylval.str = yytext; 76 tprintf("id(%s) ", yytext); 77 return ID; 78 } 79 tprintf("(%s) ", yytext); 80 return i; 81 } 82 \"[^"]+\" { 83 yytext[strlen(yytext)-1] = '\0'; 84 yylval.str = yytext + 1; 85 return ID; 86 } 87 0[0-7]* { 88 yylval.val = octal(yytext); 89 tprintf("#O:%o ", yylval.val); 90 return NUMBER; 91 } 92 0x[0-9a-fA-F]+ { 93 yylval.val = hex(yytext); 94 tprintf("#X:%x ", yylval.val); 95 return NUMBER; 96 } 97 [1-9][0-9]* { 98 yylval.val = atoi(yytext); 99 tprintf("#D:%d ", yylval.val); 100 return NUMBER; 101 } 102 "?" { 103 yylval.val = -1; 104 tprintf("? "); 105 return NUMBER; 106 } 107 \n/[ \t] { 108 yyline++; 109 tprintf("\n... "); 110 } 111 \n { 112 yyline++; 113 tprintf("\n"); 114 return SEMICOLON; 115 } 116 #.* { /* Ignored (comment) */; } 117 [ \t]* { /* Ignored (white space) */; } 118 ";" { return SEMICOLON; } 119 "," { return COMMA; } 120 "=" { return EQUALS; } 121 . { return yytext[0]; } 122 123 124 %% 125 /* 126 * kw_lookup 127 * Look up a string in the keyword table. Returns a -1 if the 128 * string is not a keyword otherwise it returns the keyword number 129 */ 130 131 int 132 kw_lookup(char *word) 133 { 134 register struct kt *kp; 135 136 for (kp = key_words; kp->kt_name != 0; kp++) 137 if (eq(word, kp->kt_name)) 138 return kp->kt_val; 139 return -1; 140 } 141 142 /* 143 * Number conversion routines 144 */ 145 146 int 147 octal(char *str) 148 { 149 int num; 150 151 (void) sscanf(str, "%o", &num); 152 return num; 153 } 154 155 int 156 hex(char *str) 157 { 158 int num; 159 160 (void) sscanf(str+2, "%x", &num); 161 return num; 162 } 163 164 int 165 yywrap() 166 { 167 return 1; 168 } 169