-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.ym
180 lines (156 loc) · 2.33 KB
/
parse.ym
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
%{
#include <stdio.h>
#include <time.h>
#include "parse_handler.h"
int yylex(void);
void yyerror(char*);
extern int wk_lex_line;
static struct tm wkTime;
typedef struct setdata {
int reps;
double weight;
int extend_reps;
double extend_weight;
} setdata;
%}
%token DASH COLON TO AM PM NO PLUS BY EOW
%token <string> LINE PTEXT AMPM
%token <ival> INTEGER
%token <dval> DOUBLE
%type <sdval> setspec;
%type <dval> weight;
%type <ival> reps;
%union
{
int ival;
double dval;
char* string;
setdata sdval;
}
%%
batch:
{ wkOnStartParse(); }
workouts
{ wkOnEndParse(); }
;
workouts:
workout
| workouts EOW workout
;
workout:
day
times
mood
cardio
comments
exercises { wkOnEndWorkout(); }
;
day:
INTEGER DASH INTEGER DASH INTEGER
{
memset(&wkTime, 0, sizeof(struct tm));
wkTime.tm_year = $1 - 1900;
wkTime.tm_mon = $3 - 1;
wkTime.tm_mday = $5;
}
;
times:
time
{ wkOnStartTime(&wkTime); }
TO time
{ wkOnEndTime(&wkTime); }
;
time:
INTEGER COLON INTEGER AM
{
wkTime.tm_hour = $1;
wkTime.tm_min = $3;
}
| INTEGER COLON INTEGER PM
{
wkTime.tm_hour = $1 + 12;
wkTime.tm_min = $3;
}
;
mood:
LINE
{ wkOnMood($1); }
;
cardio:
LINE
{ wkOnCardio($1); }
| NO
{ wkOnCardio(NULL); }
;
comments:
LINE
{ wkOnComments($1); }
;
exercises:
exercise
| exercise exercises
;
exercise:
LINE
{ wkOnExerciseName($1); }
sets
;
sets:
set
| set sets
;
set:
setspec
{
setdata sd = $1;
wkOnSet(sd.reps, sd.weight, sd.extend_reps, sd.extend_weight, NULL);
}
| setspec PTEXT
{
setdata sd = $1;
wkOnSet(sd.reps, sd.weight, sd.extend_reps, sd.extend_weight, $2);
}
;
setspec:
reps BY weight
{
setdata sd;
sd.reps = $1;
sd.weight = $3;
sd.extend_reps = 0;
sd.extend_weight = 0;
$$ = sd;
}
| reps PLUS reps BY weight
{
setdata sd;
sd.reps = $1;
sd.weight = $5;
sd.extend_reps = $3;
sd.extend_weight = $5;
$$ = sd;
}
| reps BY weight PLUS reps BY weight
{
setdata sd;
sd.reps = $1;
sd.weight = $3;
sd.extend_reps = $5;
sd.extend_weight = $7;
$$ = sd;
}
;
weight:
INTEGER
{ $$ = (double)$1; }
| DOUBLE
;
reps:
INTEGER
;
%%
void yyerror(char* s)
{
fprintf(stderr, "line %d: %s\n", wk_lex_line, s);
return;
}