-
Notifications
You must be signed in to change notification settings - Fork 0
/
summa.y
90 lines (76 loc) · 2.13 KB
/
summa.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex(void);
extern int yyparse(void);
void yyerror(const char * s);
%}
%require "3.8"
%token character dash hash hour minute nl percent punctuation word ws
%%
input:
| input logline nl { fprintf(stderr, "logline\n"); }
| input ignore nl { fprintf(stderr, "ignore\n"); }
| input nl { fprintf(stderr, "newline\n"); }
;
logline:
timestamp ws description ws tags { fprintf(stderr, "timestamp description tags\n"); }
| timestamp ws description { fprintf(stderr, "timestamp description\n"); }
| timestamp ws tags { fprintf(stderr, "timestamp tags\n"); }
| timespan ws percent ws description ws tags { fprintf(stderr, "timespan percent description tags\n"); }
| timespan ws percent ws description { fprintf(stderr, "timespan percent description\n"); }
| timespan ws percent ws tags { fprintf(stderr, "timespan percent tags\n"); }
| timespan ws description ws tags { fprintf(stderr, "timespan description tags\n"); }
| timespan ws description { fprintf(stderr, "timespan description\n"); }
| timespan ws tags { fprintf(stderr, "timespan tags\n"); }
;
timespan:
timestamp dash timestamp { fprintf(stderr, "timespan\n"); }
;
timestamp:
hour minute { fprintf(stderr, "timestamp\n"); }
;
description:
character
| dash
| punctuation
| word
| ws
| description character
| description dash
| description punctuation
| description word
| description ws
;
tags:
tag
| tags ws tag
;
tag:
hash word { fprintf(stderr, "tag\n"); }
;
ignore:
character
| dash
| hash
| percent
| punctuation
| ws
| word
| ignore character
| ignore dash
| ignore hash
| ignore percent
| ignore punctuation
| ignore timestamp
| ignore word
| ignore ws
;
%%
int main(int argc, char ** argv) {
while(yyparse()) {};
}
void yyerror(const char * s) {
fprintf(stderr, "error: %s\n", s);
exit(1);
}