chiark / gitweb /
Merge and end branch-hostside-wip-2008-01-25 PROPERLY; cvs up -j branch-hostside...
[trains.git] / hostside / record-y.y
1 /* -*- fundamental -*- */
2
3 %{
4 #include "record-i.h"
5 #include "record-l.h"
6
7 static Train *cur_train;
8 %}
9
10 %union {
11   const char *name;
12   Train *train;
13   Segment *seg;
14   int num;
15 }
16
17 %token <name>   TRAIN SEG  IS AT HAS STEP HOME END  IDENT
18 %token <name>   NL
19 %token <num>    NUM
20
21 %type <name>    ident
22 %type <train>   train
23 %type <seg>     seg
24 %type <num>     backwards
25
26 %defines
27 %error-verbose
28 %name-prefix="record_yy"
29
30 %%
31
32 file:           end
33         |       line NL { record_tempzone_clear(); } file
34
35 line:           /* empty */
36         |       TRAIN train IS NUM NUM '+' NUM '+' NUM
37         {         if ($2) record_train_is($2,$4,$5,$7,$9);
38         }
39         |       TRAIN train AT backwards seg ':' NUM '+' '-' NUM
40         {         if ($2) record_train_at($2,$4,$5,$7,$10);
41         }
42         |       TRAIN train { cur_train=$2; } HOME segments
43         {
44         }
45         |       TRAIN train STEP NUM '=' NUM NUM '/' NUM
46         {         if (!trains) record_train_step_count();
47                   else if ($2) record_train_step($2,$4,$6,$7,$9);
48         }
49         |       SEG seg HAS backwards train
50         {         if ($2 && $5) record_seg_has($2,$4,$5);
51         }
52         |       SEG seg AT ident
53         {         if ($2) record_seg_at($2,$4);
54         }
55
56 backwards:      /* empty */ { return 0; }
57         |       '-' { return 1; }
58
59 segments:       { cur_train= 0; }
60         |       backwards seg { record_train_home(cur_train,$1,$2); } segments
61 ident:          TRAIN | SEG | IS | AT | HAS | STEP | HOME | END | IDENT
62
63 seg:            ident { $$= record_pname2seg($1); }
64 train:          ident { $$= record_pname2train($1); }
65
66 end:            END NL
67
68 %%