source: trunk/orbital/gun-parser.y @ 1424

Last change on this file since 1424 was 1424, checked in by sam, 11 years ago

orbital: port the gun command compiler to our bison/flex system.

File size: 3.0 KB
Line 
1%{
2//
3// Orbital
4//
5// Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
6//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
7//            (c) 2012 Sam Hocevar <sam@hocevar.net>
8//
9
10#if defined HAVE_CONFIG_H
11#   include "config.h"
12#endif
13
14#include "core.h"
15#include "loldebug.h"
16
17using namespace lol;
18
19#include "../gun.h"
20
21#include <stdio.h>
22#include <string>
23#include <vector>
24%}
25
26%require "2.3"
27%debug
28%defines
29%skeleton "lalr1.cc"
30%name-prefix="orbital"
31%define parser_class_name "GunParser"
32%locations
33%parse-param { class GunCompiler& gc }
34%error-verbose
35
36%union
37{
38    float fval;
39    struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args;
40}
41
42%start gun_description
43
44%token T_AI
45%token T_PAI
46%token T_CA
47%token T_SA
48%token T_TIM
49%token T_SO
50%token T_RD
51%token T_SPD
52%token T_MODA
53%token T_MODB
54%token T_FFB
55%token T_FFP
56%token T_FB
57%token T_FP
58%token T_SK
59%token T_LOOP
60
61%token T_END 0
62
63%token <fval> NUMBER
64
65%type <fval> number
66%type <args> args1 args2 args3
67
68%{
69#include "../gun-compiler.h"
70
71#undef yylex
72#define yylex gc.m_lexer->lex
73%}
74
75%%
76
77gun_description:
78    gun_command_list T_END
79    ;
80
81gun_command_list:
82    gun_command
83  | gun_command_list ',' gun_command
84    ;
85
86gun_command:
87    T_AI            { gc.m_gun.m_angle = gc.m_gun.AimActor(); }
88  | T_PAI args1     { gc.m_gun.PreAimActor($2.f0); }
89  | T_CA args1      { gc.m_gun.m_pre_aim = $2.f0; }
90  | T_SA args1      { gc.m_gun.m_angle = $2.f0; }
91  | T_TIM args1     { gc.m_gun.m_round_duration = $2.f0; }
92  | T_SO args1      { gc.m_gun.m_angle_offset = $2.f0; }
93  | T_RD args1      { gc.m_gun.m_radius = $2.f0; }
94  | T_SPD args1     { gc.m_gun.m_shoot_speed = $2.f0; }
95  | T_MODA args3    { /* FIXME: 1st modifier */ }
96  | T_MODB args3    { /* FIXME: 2nd modifier */ }
97  | T_FFB args1     { for (int i = 0; i < (int)$2.f0; i++) gc.m_gun.Shoot(1);
98                      gc.m_gun.m_shoot_type = 1;
99                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
100  | T_FFP args1     { for (int i = 0; i < (int)$2.f0; i++) gc.m_gun.Shoot(0);
101                      gc.m_gun.m_shoot_type = 0;
102                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
103  | T_FB args1      { gc.m_gun.Shoot(1); gc.m_gun.m_nbshoots = (int)$2.f0 - 1;
104                      gc.m_gun.m_shoot_type = 1;
105                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
106  | T_FP args1      { gc.m_gun.Shoot(0); gc.m_gun.m_nbshoots = (int)$2.f0 - 1;
107                      gc.m_gun.m_shoot_type = 0;
108                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
109  | T_SK args1      { gc.m_gun.m_round_timer = gc.m_gun.m_round_duration * $2.f0;
110                      /* FIXME: modifiers */ }
111  | T_LOOP          { /* FIXME: loops */ }
112    ;
113
114args1: number { $$.f0 = $1; } ;
115args2: args1 ',' number { $$ = $1; $$.f1 = $3; } ;
116args3: args2 ',' number { $$ = $1; $$.f2 = $3; } ;
117
118number:
119    NUMBER       { $$ = $1; }
120  | '-' number   { $$ = -$2; }
121    ;
122
123%%
124
125void orbital::GunParser::error(const GunParser::location_type& l,
126                               const std::string& m)
127{
128    gc.Error(l, m);
129}
130
Note: See TracBrowser for help on using the repository browser.