source: trunk/orbital/gun.yy @ 1416

Last change on this file since 1416 was 1416, checked in by sam, 8 years ago

orbital: parser for the gun commands... fails to link because of flex.

File size: 3.0 KB
Line 
1/*
2 * Orbital
3 *
4 * Copyright: (c) 2012 Various People
5 */
6
7%skeleton "lalr1.cc"
8%require "2.5"
9%defines
10%define parser_class_name "GunParser"
11
12%locations
13%parse-param { Gun &gun }
14%lex-param   { Gun &gun }
15%parse-param { void *yyscanner }
16%lex-param   { void *yyscanner }
17
18%code {
19#define YY_DECL \
20    yy::GunParser::token_type \
21    yylex(yy::GunParser::semantic_type* yylval, \
22          yy::GunParser::location_type* yylloc, \
23          Gun& gun, \
24          void *yyscanner)
25YY_DECL;
26}
27
28%union
29{
30    float fval;
31    struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args;
32}
33
34%token T_AI
35%token T_PAI
36%token T_CA
37%token T_SA
38%token T_TIM
39%token T_SO
40%token T_RD
41%token T_SPD
42%token T_MODA
43%token T_MODB
44%token T_FFB
45%token T_FFP
46%token T_FB
47%token T_FP
48%token T_SK
49%token T_LOOP
50
51%token T_END 0
52
53%token <fval> NUMBER
54
55%type <fval> number
56
57%type <args> args1 args2 args3 args4 args5 args6 args7 args8
58
59%%
60
61%start gun_description ;
62
63gun_description:
64    gun_command_list T_END
65    ;
66
67gun_command_list:
68    gun_command
69  | gun_command_list ',' gun_command
70    ;
71
72gun_command:
73    T_AI            { gun.m_angle = gun.AimActor(); }
74  | T_PAI args1     { gun.PreAimActor($2.f0); }
75  | T_CA args1      { gun.m_pre_aim = $2.f0; }
76  | T_SA args1      { gun.m_angle = $2.f0; }
77  | T_TIM args1     { gun.m_round_duration = $2.f0; }
78  | T_SO args1      { gun.m_angle_offset = $2.f0; }
79  | T_RD args1      { gun.m_radius = $2.f0; }
80  | T_SPD args1     { gun.m_shoot_speed = $2.f0; }
81  | T_MODA args3    { /* FIXME: 1st modifier */ }
82  | T_MODB args3    { /* FIXME: 2nd modifier */ }
83  | T_FFB args1     { for (int i = 0; i < (int)$2.f0; i++) gun.Shoot(1);
84                      gun.m_shoot_type = 1;
85                      gun.m_round_timer = gun.m_round_duration; }
86  | T_FFP args1     { for (int i = 0; i < (int)$2.f0; i++) gun.Shoot(0);
87                      gun.m_shoot_type = 0;
88                      gun.m_round_timer = gun.m_round_duration; }
89  | T_FB args1      { gun.Shoot(1); gun.m_nbshoots = (int)$2.f0 - 1;
90                      gun.m_shoot_type = 1;
91                      gun.m_round_timer = gun.m_round_duration; }
92  | T_FP args1      { gun.Shoot(0); gun.m_nbshoots = (int)$2.f0 - 1;
93                      gun.m_shoot_type = 0;
94                      gun.m_round_timer = gun.m_round_duration; }
95  | T_SK args1      { gun.m_round_timer = gun.m_round_duration * $2.f0;
96                      /* FIXME: modifiers */ }
97  | T_LOOP          { /* FIXME: loops */ }
98    ;
99
100args1: number { $$.f0 = $1; } ;
101args2: args1 ',' number { $$ = $1; $$.f1 = $3; } ;
102args3: args2 ',' number { $$ = $1; $$.f2 = $3; } ;
103args4: args3 ',' number { $$ = $1; $$.f3 = $3; } ;
104args5: args4 ',' number { $$ = $1; $$.f4 = $3; } ;
105args6: args5 ',' number { $$ = $1; $$.f5 = $3; } ;
106args7: args6 ',' number { $$ = $1; $$.f6 = $3; } ;
107args8: args7 ',' number { $$ = $1; $$.f7 = $3; } ;
108
109number:
110    NUMBER       { $$ = $1; }
111  | '-' number   { $$ = -$2; }
112    ;
113
114%%
115
116void yy::GunParser::error(const yy::GunParser::location_type& l, const std::string &m)
117{
118    /* FIXME: do something */
119    std::cerr << "ERROR: " << m << std::endl;
120}
121
Note: See TracBrowser for help on using the repository browser.