1 %{ 2 3 /* 4 * Copyright (c) 1983 Regents of the University of California. 5 * All rights reserved. 6 * 7 * %sccs.include.redist.c% 8 */ 9 10 #ifndef lint 11 static char sccsid[] = "@(#)parse.y 5.5 (Berkeley) 06/01/90"; 12 #endif /* not lint */ 13 14 #include "htable.h" 15 %} 16 17 %union { 18 int number; 19 struct addr *addrlist; 20 struct name *namelist; 21 } 22 %start Table 23 24 %token END 25 %token <number> NUMBER KEYWORD 26 %token <namelist> NAME 27 28 %type <namelist> Names Cputype Opsys Protos Proto 29 %type <addrlist> Addresses Address 30 %% 31 Table : Entry 32 | Table Entry 33 ; 34 35 Entry : KEYWORD ':' Addresses ':' Names ':' END 36 = { 37 do_entry($1, $3, $5, NONAME, NONAME, NONAME); 38 } 39 | KEYWORD ':' Addresses ':' Names ':' Cputype ':' END 40 = { 41 do_entry($1, $3, $5, $7, NONAME, NONAME); 42 } 43 | KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' END 44 = { 45 do_entry($1, $3, $5, $7, $9, NONAME); 46 } 47 | KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' ':' END 48 = { 49 do_entry($1, $3, $5, $7, $9, NONAME); 50 } 51 | KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' Protos ':' END 52 = { 53 do_entry($1, $3, $5, $7, $9, $11); 54 } 55 | error END 56 | END /* blank line */ 57 ; 58 59 Addresses: Address 60 = { 61 $$ = $1; 62 } 63 | Address ',' Addresses 64 = { 65 $1->addr_link = $3; 66 $$ = $1; 67 } 68 ; 69 70 Address : NUMBER '.' NUMBER '.' NUMBER '.' NUMBER 71 = { 72 char *a; 73 74 $$ = (struct addr *)malloc(sizeof (struct addr)); 75 a = (char *)&($$->addr_val); 76 a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7; 77 $$->addr_link = NOADDR; 78 } 79 ; 80 81 Names : NAME 82 = { 83 $$ = $1; 84 } 85 | NAME ',' Names 86 = { 87 $1->name_link = $3; 88 $$ = $1; 89 } 90 ; 91 92 Cputype : /* empty */ 93 = { 94 $$ = NONAME; 95 } 96 | NAME 97 = { 98 $$ = $1; 99 } 100 ; 101 102 Opsys : /* empty */ 103 = { 104 $$ = NONAME; 105 } 106 | NAME 107 = { 108 $$ = $1; 109 } 110 ; 111 112 Protos : Proto 113 = { 114 $$ = $1; 115 } 116 | Proto ',' Protos 117 = { 118 $1->name_link = $3; 119 $$ = $1; 120 } 121 ; 122 123 Proto : NAME 124 = { 125 $$ = $1; 126 } 127 ; 128 %% 129 130 #include <stdio.h> 131 132 extern int yylineno; 133 134 yyerror(msg) 135 char *msg; 136 { 137 fprintf(stderr, "\"%s\", line %d: %s\n", infile, yylineno, msg); 138 } 139