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

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

orbital: make sure to include "config.h" in all compiled files.

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 <string>
22%}
23
24%require "2.3"
25%debug
26%defines
27%skeleton "lalr1.cc"
28%name-prefix="orbital"
29%define parser_class_name "GunParser"
30%locations
31%parse-param { class GunCompiler& gc }
32%error-verbose
33
34%union
35{
36    float fval;
37    struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args;
38}
39
40%start gun_description
41
42%token T_AI
43%token T_PAI
44%token T_CA
45%token T_SA
46%token T_TIM
47%token T_SO
48%token T_RD
49%token T_SPD
50%token T_MODA
51%token T_MODB
52%token T_FFB
53%token T_FFP
54%token T_FB
55%token T_FP
56%token T_SK
57%token T_LOOP
58
59%token T_END 0
60
61%token <fval> NUMBER
62
63%type <fval> number
64%type <args> args1 args2 args3
65
66%{
67#include "../gun-compiler.h"
68
69#undef yylex
70#define yylex gc.m_lexer->lex
71%}
72
73%%
74
75gun_description:
76    gun_command_list T_END
77    ;
78
79gun_command_list:
80    gun_command
81  | gun_command_list ',' gun_command
82    ;
83
84gun_command:
85    T_AI            { gc.m_gun.m_angle = gc.m_gun.AimActor(); }
86  | T_PAI args1     { gc.m_gun.PreAimActor($2.f0); }
87  | T_CA args1      { gc.m_gun.m_pre_aim = $2.f0; }
88  | T_SA args1      { gc.m_gun.m_angle = $2.f0; }
89  | T_TIM args1     { gc.m_gun.m_round_duration = $2.f0; }
90  | T_SO args1      { gc.m_gun.m_angle_offset = $2.f0; }
91  | T_RD args1      { gc.m_gun.m_radius = $2.f0; }
92  | T_SPD args1     { gc.m_gun.m_shoot_speed = $2.f0; }
93  | T_MODA args3    { /* FIXME: 1st modifier */ }
94  | T_MODB args3    { /* FIXME: 2nd modifier */ }
95  | T_FFB args1     { for (int i = 0; i < (int)$2.f0; i++) gc.m_gun.Shoot(1);
96                      gc.m_gun.m_shoot_type = 1;
97                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
98  | T_FFP args1     { for (int i = 0; i < (int)$2.f0; i++) gc.m_gun.Shoot(0);
99                      gc.m_gun.m_shoot_type = 0;
100                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
101  | T_FB args1      { gc.m_gun.Shoot(1); gc.m_gun.m_nbshoots = (int)$2.f0 - 1;
102                      gc.m_gun.m_shoot_type = 1;
103                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
104  | T_FP args1      { gc.m_gun.Shoot(0); gc.m_gun.m_nbshoots = (int)$2.f0 - 1;
105                      gc.m_gun.m_shoot_type = 0;
106                      gc.m_gun.m_round_timer = gc.m_gun.m_round_duration; }
107  | T_SK args1      { gc.m_gun.m_round_timer = gc.m_gun.m_round_duration * $2.f0;
108                      /* FIXME: modifiers */ }
109  | T_LOOP          { /* FIXME: loops */ }
110    ;
111
112args1: number { $$.f0 = $1; } ;
113args2: args1 ',' number { $$ = $1; $$.f1 = $3; } ;
114args3: args2 ',' number { $$ = $1; $$.f2 = $3; } ;
115
116number:
117    NUMBER       { $$ = $1; }
118  | '-' number   { $$ = -$2; }
119    ;
120
121%%
122
123void orbital::GunParser::error(const GunParser::location_type& l,
124                               const std::string& m)
125{
126    gc.Error(l, m);
127}
128
Note: See TracBrowser for help on using the repository browser.