]>
Commit | Line | Data |
---|---|---|
86e4d161 | 1 | %{ |
86e4d161 MS |
2 | |
3 | #include <err.h> | |
4 | #include <string.h> | |
5 | #include "dma.h" | |
6 | ||
7 | extern int yylineno; | |
65bec70e | 8 | static void yyerror(const char *); |
86e4d161 | 9 | int yywrap(void); |
65bec70e | 10 | int yylex(void); |
86e4d161 | 11 | |
65bec70e | 12 | static void |
86e4d161 MS |
13 | yyerror(const char *msg) |
14 | { | |
15 | warnx("aliases line %d: %s", yylineno, msg); | |
16 | } | |
17 | ||
18 | int | |
19 | yywrap(void) | |
20 | { | |
21 | return (1); | |
22 | } | |
23 | ||
24 | %} | |
25 | ||
26 | %union { | |
27 | char *ident; | |
28 | struct stritem *strit; | |
29 | struct alias *alias; | |
30 | } | |
31 | ||
32 | %token <ident> T_IDENT | |
33 | %token T_ERROR | |
34 | %token T_EOF 0 | |
35 | ||
36 | %type <strit> dests | |
37 | %type <alias> alias aliases | |
38 | ||
39 | %% | |
40 | ||
41 | start : aliases T_EOF | |
42 | { | |
43 | LIST_FIRST(&aliases) = $1; | |
44 | } | |
45 | ||
46 | aliases : /* EMPTY */ | |
47 | { | |
48 | $$ = NULL; | |
49 | } | |
50 | | alias aliases | |
51 | { | |
52 | if ($2 != NULL && $1 != NULL) | |
53 | LIST_INSERT_AFTER($2, $1, next); | |
54 | else if ($2 == NULL) | |
55 | $2 = $1; | |
56 | $$ = $2; | |
57 | } | |
58 | ; | |
59 | ||
60 | alias : T_IDENT ':' dests '\n' | |
61 | { | |
62 | struct alias *al; | |
63 | ||
64 | if ($1 == NULL) | |
65 | YYABORT; | |
66 | al = calloc(1, sizeof(*al)); | |
67 | if (al == NULL) | |
68 | YYABORT; | |
69 | al->alias = $1; | |
70 | SLIST_FIRST(&al->dests) = $3; | |
71 | $$ = al; | |
72 | } | |
73 | | error '\n' | |
74 | { | |
75 | yyerrok; | |
76 | $$ = NULL; | |
77 | } | |
78 | ; | |
79 | ||
80 | dests : T_IDENT | |
81 | { | |
82 | struct stritem *it; | |
83 | ||
84 | if ($1 == NULL) | |
85 | YYABORT; | |
86 | it = calloc(1, sizeof(*it)); | |
87 | if (it == NULL) | |
88 | YYABORT; | |
89 | it->str = $1; | |
90 | $$ = it; | |
91 | } | |
92 | | T_IDENT ',' dests | |
93 | { | |
94 | struct stritem *it; | |
95 | ||
96 | if ($1 == NULL) | |
97 | YYABORT; | |
98 | it = calloc(1, sizeof(*it)); | |
99 | if (it == NULL) | |
100 | YYABORT; | |
101 | it->str = $1; | |
102 | SLIST_NEXT(it, next) = $3; | |
103 | $$ = it; | |
104 | } | |
105 | ; | |
106 | ||
107 | %% |