Change Details
b2/SUBST |
1 | 1 | REF=R[0-9]* { |
2 | 2 | T=R |
3 | 3 | VAL=(#R) { R=$1 } |
4 | | TOL = 5% |
5 | | FN=*% { TOL=$$ } |
| 4 | TOL <= 5% |
| 5 | FN=*% { TOL<=$$ } |
6 | 6 | break REF |
7 | 7 | // end break again |
8 | 8 | } |
b2/boom.c |
16 | 16 | |
17 | 17 | #include "util.h" |
18 | 18 | #include "lang.h" |
| 19 | #include "param.h" |
19 | 20 | #include "subex.h" |
20 | 21 | |
21 | 22 | |
... | ... | |
33 | 34 | exit(1); |
34 | 35 | } |
35 | 36 | *eq = 0; |
36 | | *last_var = make_var(tmp, eq+1); |
| 37 | *last_var = make_var(tmp, rel_eq, eq+1); |
37 | 38 | last_var = &(*last_var)->next; |
38 | 39 | } |
39 | 40 | |
... | ... | |
44 | 45 | const struct var *var; |
45 | 46 | |
46 | 47 | out = substitute(substitutions, vars); |
47 | | for (var = out; var; var = var->next) |
48 | | printf("%s=%s\n", var->name, var->value); |
| 48 | for (var = out; var; var = var->next) { |
| 49 | printf("%s", var->name); |
| 50 | dump_relop(stdout, var->op); |
| 51 | printf("%s\n", var->value); |
| 52 | } |
49 | 53 | free_vars(out); |
50 | 54 | } |
51 | 55 | |
b2/lang.l |
119 | 119 | } |
120 | 120 | %} |
121 | 121 | |
122 | | <INITIAL,ID>{ID}({ID}|"%")* { yylval.s = unique(yytext); |
| 122 | <INITIAL,ID>{ID}({ID}|"%")* { yylval.s = unique(yytext); |
123 | 123 | return WORD; } |
124 | 124 | |
125 | 125 | <PAT>{PAT}* { BEGIN(ID); |
126 | 126 | yylval.s = stralloc(yytext); |
127 | 127 | return PATTERN; } |
128 | 128 | |
129 | | "=" { if (pattern) |
| 129 | [<>=] { if (pattern) |
130 | 130 | BEGIN(PAT); |
131 | | return '='; } |
| 131 | return *yytext; } |
132 | 132 | |
133 | | "<=" return TOK_LE; |
134 | | ">=" return TOK_GE; |
| 133 | "<=" { if (pattern) |
| 134 | BEGIN(PAT); |
| 135 | return TOK_LE; } |
| 136 | ">=" { if (pattern) |
| 137 | BEGIN(PAT); |
| 138 | return TOK_GE; } |
135 | 139 | |
136 | 140 | "//"[^\n]* ; |
137 | 141 | "/*"([^*]|("*"+([^*/])))*"*"+"/" { const char *s = yytext; |
b2/lang.y |
587 | 587 | { |
588 | 588 | $$ = NULL; |
589 | 589 | } |
590 | | | WORD '=' PATTERN opt_block block |
| 590 | | WORD relop PATTERN opt_block block |
591 | 591 | { |
592 | 592 | if ($4) { |
| 593 | if ($2 != rel_eq) |
| 594 | yyerror("only = allow for matching"); |
593 | 595 | $$ = subst_match($1, $3); |
594 | 596 | $$->u.match.block = $4; |
595 | 597 | } else { |
596 | | $$ = subst_assign($1, $3); |
| 598 | $$ = subst_assign($1, $2, $3); |
597 | 599 | } |
598 | 600 | free((void *) $3); |
599 | 601 | $$->next = $5; |
b2/subex.c |
21 | 21 | #include "util.h" |
22 | 22 | #include "vstring.h" |
23 | 23 | #include "lang.h" |
| 24 | #include "relop.h" |
24 | 25 | #include "subst.h" |
25 | 26 | #include "subex.h" |
26 | 27 | |
... | ... | |
138 | 139 | } |
139 | 140 | |
140 | 141 | |
141 | | struct var *make_var(const char *name, const char *val) |
| 142 | struct var *make_var(const char *name, enum relop op, const char *val) |
142 | 143 | { |
143 | 144 | struct var *var; |
144 | 145 | |
145 | 146 | var = alloc_type(struct var); |
146 | 147 | var->name = unique(name); |
| 148 | var->op = op; |
147 | 149 | var->value = unique(val); |
148 | 150 | var->next = NULL; |
149 | 151 | return var; |
150 | 152 | } |
151 | 153 | |
152 | 154 | |
153 | | static void do_assign(const char *name, struct var **out, const char *val) |
| 155 | static void do_assign(const char *name, struct var **out, enum relop op, |
| 156 | const char *val) |
154 | 157 | { |
155 | 158 | while (*out) { |
156 | 159 | if ((*out)->name == name) |
... | ... | |
161 | 164 | free((void *) (*out)->value); |
162 | 165 | (*out)->value = val; |
163 | 166 | } else { |
164 | | *out = make_var(name, val); |
| 167 | *out = make_var(name, op, val); |
165 | 168 | } |
166 | 169 | } |
167 | 170 | |
... | ... | |
217 | 220 | case st_assign: |
218 | 221 | tmp = compose(sub->u.assign.pat, in, *out, s, match, |
219 | 222 | units); |
220 | | do_assign(sub->u.assign.dst, out, tmp); |
| 223 | do_assign(sub->u.assign.dst, out, sub->u.assign.op, |
| 224 | tmp); |
221 | 225 | break; |
222 | 226 | case st_end: |
223 | 227 | return &jump_end; |
b2/subex.h |
13 | 13 | #ifndef SUBEX_H |
14 | 14 | #define SUBEX_H |
15 | 15 | |
| 16 | #include "relop.h" |
16 | 17 | #include "subst.h" |
17 | 18 | |
18 | 19 | |
19 | 20 | struct var { |
20 | 21 | const char *name; |
| 22 | enum relop op; |
21 | 23 | const char *value; |
22 | 24 | struct var *next; |
23 | 25 | }; |
24 | 26 | |
25 | 27 | |
26 | 28 | struct var *substitute(const struct subst *sub, const struct var *in); |
27 | | struct var *make_var(const char *name, const char *val); |
| 29 | struct var *make_var(const char *name, enum relop op, const char *val); |
28 | 30 | const char *var_lookup(const struct var *vars, const char *name); |
29 | 31 | void free_vars(struct var *vars); |
30 | 32 | |
b2/subst.c |
21 | 21 | #include "util.h" |
22 | 22 | #include "vstring.h" |
23 | 23 | #include "lang.h" |
| 24 | #include "relop.h" |
24 | 25 | #include "subst.h" |
25 | 26 | |
26 | 27 | |
... | ... | |
226 | 227 | } |
227 | 228 | |
228 | 229 | |
229 | | struct subst *subst_assign(const char *dst, const char *pat) |
| 230 | struct subst *subst_assign(const char *dst, enum relop op, const char *pat) |
230 | 231 | { |
231 | 232 | struct subst *sub; |
232 | 233 | |
233 | 234 | sub = alloc_subst(st_assign); |
234 | 235 | sub->u.assign.dst = dst; |
| 236 | sub->u.assign.op = op; |
235 | 237 | sub->u.assign.pat = parse_pattern(pat); |
236 | 238 | return sub; |
237 | 239 | } |
... | ... | |
358 | 360 | fprintf(file, "%*s}\n", INDENT*level, ""); |
359 | 361 | break; |
360 | 362 | case st_assign: |
361 | | fprintf(file, "%s=", sub->u.assign.dst); |
| 363 | fprintf(file, "%s", sub->u.assign.dst); |
| 364 | dump_relop(file, sub->u.assign.op); |
362 | 365 | dump_chunks(file, sub->u.assign.pat); |
363 | 366 | fprintf(file, "\n"); |
364 | 367 | break; |
b2/subst.h |
17 | 17 | #include <sys/types.h> |
18 | 18 | #include <regex.h> |
19 | 19 | |
| 20 | #include "relop.h" |
| 21 | |
20 | 22 | |
21 | 23 | enum chunk_type { |
22 | 24 | ct_string, |
... | ... | |
53 | 55 | } match; |
54 | 56 | struct { |
55 | 57 | const char *dst; |
| 58 | enum relop op; |
56 | 59 | struct chunk *pat; |
57 | 60 | } assign; |
58 | 61 | const struct subst *jump; |
... | ... | |
66 | 69 | |
67 | 70 | |
68 | 71 | struct subst *subst_match(const char *src, const char *re); |
69 | | struct subst *subst_assign(const char *dst, const char *pat); |
| 72 | struct subst *subst_assign(const char *dst, enum relop op, const char *pat); |
70 | 73 | struct subst *subst_end(void); |
71 | 74 | struct subst *subst_break(const char *block); |
72 | 75 | struct subst *subst_again(const char *block); |
Download the corresponding diff file