More parse rules

This commit is contained in:
Stefan Bühler 2008-07-12 02:49:03 +02:00
parent 98678a9979
commit 482e6d23f9
2 changed files with 66 additions and 51 deletions

View File

@ -19,86 +19,86 @@ static double extract_double(context *ctx, char *fpc) {
return strtod(ctx->tmp->str, NULL);
}
#line 45 "control_parser.rl"
#line 62 "control_parser.rl"
#line 27 "control_parser.c"
static const char _control_parser_actions[] = {
0, 1, 1, 1, 2, 1, 3, 1,
4, 1, 5, 1, 6, 1, 7, 2,
1, 2, 2, 1, 3, 2, 1, 4,
2, 1, 5, 2, 1, 6, 2, 1,
7, 2, 8, 0, 3, 1, 8, 0
0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 1,
7, 1, 8, 2, 1, 2, 2, 1,
3, 2, 1, 4, 2, 1, 5, 2,
1, 6, 2, 1, 7, 2, 1, 8
};
static const char _control_parser_key_offsets[] = {
0, 0, 1, 2, 6, 10, 14, 18,
22, 26, 30, 34, 38, 42, 46, 50,
54, 58, 62
22, 26, 30, 34, 35, 39, 43, 47,
51, 55, 59, 63
};
static const char _control_parser_trans_keys[] = {
73, 32, 32, 46, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 46, 59,
48, 57, 46, 59, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 32, 46,
48, 57, 32, 46, 48, 57, 0
48, 57, 59, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 0
};
static const char _control_parser_single_lengths[] = {
0, 1, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 0
2, 2, 2, 1, 2, 2, 2, 2,
2, 2, 2, 0
};
static const char _control_parser_range_lengths[] = {
0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0
1, 1, 1, 0, 1, 1, 1, 1,
1, 1, 1, 0
};
static const char _control_parser_index_offsets[] = {
0, 0, 2, 4, 8, 12, 16, 20,
24, 28, 32, 36, 40, 44, 48, 52,
56, 60, 64
24, 28, 32, 36, 38, 42, 46, 50,
54, 58, 62, 66
};
static const char _control_parser_trans_targs[] = {
2, 0, 3, 0, 4, 17, 17, 0,
5, 16, 16, 0, 6, 5, 5, 0,
7, 15, 15, 0, 8, 14, 14, 0,
9, 13, 13, 0, 10, 12, 12, 0,
11, 18, 11, 0, 11, 18, 11, 0,
10, 12, 12, 0, 9, 13, 13, 0,
8, 14, 14, 0, 7, 15, 15, 0,
5, 16, 16, 0, 4, 17, 17, 0,
0, 0
2, 0, 3, 0, 4, 18, 18, 0,
5, 17, 17, 0, 6, 5, 5, 0,
7, 16, 16, 0, 8, 15, 15, 0,
9, 14, 14, 0, 10, 13, 13, 0,
11, 12, 12, 0, 19, 0, 11, 12,
12, 0, 10, 13, 13, 0, 9, 14,
14, 0, 8, 15, 15, 0, 7, 16,
16, 0, 5, 17, 17, 0, 4, 18,
18, 0, 0, 0
};
static const char _control_parser_trans_actions[] = {
0, 0, 0, 0, 15, 1, 1, 0,
18, 1, 1, 0, 0, 0, 0, 0,
21, 1, 1, 0, 24, 1, 1, 0,
27, 1, 1, 0, 30, 1, 1, 0,
1, 36, 1, 0, 0, 33, 0, 0,
13, 0, 0, 0, 11, 0, 0, 0,
9, 0, 0, 0, 7, 0, 0, 0,
5, 0, 0, 0, 3, 0, 0, 0,
0, 0
0, 0, 0, 0, 19, 3, 3, 0,
22, 3, 3, 0, 0, 0, 0, 0,
25, 3, 3, 0, 28, 3, 3, 0,
31, 3, 3, 0, 34, 3, 3, 0,
37, 3, 3, 0, 1, 0, 17, 0,
0, 0, 15, 0, 0, 0, 13, 0,
0, 0, 11, 0, 0, 0, 9, 0,
0, 0, 7, 0, 0, 0, 5, 0,
0, 0, 0, 0
};
static const int control_parser_start = 1;
static const int control_parser_first_final = 18;
static const int control_parser_first_final = 19;
static const int control_parser_error = 0;
static const int control_parser_en_main = 1;
#line 48 "control_parser.rl"
#line 65 "control_parser.rl"
static int control_parser_has_error(context *ctx) {
return ctx->cs == control_parser_error;
@ -115,7 +115,7 @@ void control_parser_new(trial *t) {
{
( ctx->cs) = control_parser_start;
}
#line 60 "control_parser.rl"
#line 77 "control_parser.rl"
ctx->buffer = g_string_sized_new(0);
ctx->tmp = g_string_sized_new(0);
}
@ -127,7 +127,7 @@ void control_parser_reset(trial *t) {
{
( ctx->cs) = control_parser_start;
}
#line 67 "control_parser.rl"
#line 84 "control_parser.rl"
g_string_truncate(ctx->tmp, 0);
}
@ -230,31 +230,31 @@ _match:
{ ctx->mark = p - ctx->buffer->str; }
break;
case 2:
#line 34 "control_parser.rl"
#line 35 "control_parser.rl"
{ t->map.dx = extract_double(ctx, p); }
break;
case 3:
#line 35 "control_parser.rl"
#line 36 "control_parser.rl"
{ t->map.dy = extract_double(ctx, p); }
break;
case 4:
#line 36 "control_parser.rl"
#line 37 "control_parser.rl"
{ t->map.min_sensor = extract_double(ctx, p); }
break;
case 5:
#line 37 "control_parser.rl"
#line 38 "control_parser.rl"
{ t->map.max_sensor = extract_double(ctx, p); }
break;
case 6:
#line 38 "control_parser.rl"
#line 39 "control_parser.rl"
{ t->map.max_speed = extract_double(ctx, p); }
break;
case 7:
#line 39 "control_parser.rl"
#line 40 "control_parser.rl"
{ t->map.max_turn = extract_double(ctx, p); }
break;
case 8:
#line 40 "control_parser.rl"
#line 41 "control_parser.rl"
{ t->map.max_hard_turn = extract_double(ctx, p); }
break;
#line 261 "control_parser.c"
@ -269,7 +269,7 @@ _again:
_test_eof: {}
_out: {}
}
#line 87 "control_parser.rl"
#line 104 "control_parser.rl"
g_string_erase(ctx->buffer, 0, ctx->read);
ctx->mark -= ctx->read;

View File

@ -25,9 +25,10 @@ static double extract_double(context *ctx, char *fpc) {
action done { fbreak; }
action mark { ctx->mark = fpc - ctx->buffer->str; }
action parsedouble { ctx->d = extract_double(ctx, fpc); }
action telemetrystart { }
action vehicle { }
sp = " ";
SP = " ";
double = (digit | '.')*;
@ -39,9 +40,23 @@ static double extract_double(context *ctx, char *fpc) {
max_turn = double >mark % { t->map.max_turn = extract_double(ctx, fpc); };
max_hard_turn = double >mark % { t->map.max_hard_turn = extract_double(ctx, fpc); };
init = "I" sp dx sp dy sp double sp min_sensor sp max_sensor sp max_speed sp max_turn sp max_hard_turn ";";
init = "I" SP dx SP dy SP double SP min_sensor SP max_sensor SP max_speed SP max_turn SP max_hard_turn SP ";";
x = double;
y = double;
r = double;
dir = double;
speed = double;
ctl = [ab\-] [Ll\-rR];
timestamp = double;
boulder = "b" SP x SP y SP r SP;
crater = "b" SP x SP y SP r SP;
homebase = "b" SP x SP y SP r SP;
martian = "m" SP x SP y SP dir SP speed SP;
object = boulder | crater | homebase | martian;
objects = object*;
telemetry = ( ("T" SP timestamp SP ctl SP x SP y SP dir SP speed SP) %vehicle objects) >telemetrystart ";";
main := init @ done;
}%%