summaryrefslogtreecommitdiff
path: root/i/chuck/src/parser/yyparser.yy
diff options
context:
space:
mode:
authorbecquet2007-05-10 18:49:20 +0000
committerbecquet2007-05-10 18:49:20 +0000
commit8f486613be58ced269db1d437e560c16558604e8 (patch)
tree41e94b2122a118cb06abf6fc2a0038cd1dfbec4a /i/chuck/src/parser/yyparser.yy
parent4daa2c76c2a028e4b2c8ab379e7d1e0f535a0a31 (diff)
Création de chuck, le programme du robot 2007.
Diffstat (limited to 'i/chuck/src/parser/yyparser.yy')
-rw-r--r--i/chuck/src/parser/yyparser.yy278
1 files changed, 278 insertions, 0 deletions
diff --git a/i/chuck/src/parser/yyparser.yy b/i/chuck/src/parser/yyparser.yy
new file mode 100644
index 0000000..86db4a5
--- /dev/null
+++ b/i/chuck/src/parser/yyparser.yy
@@ -0,0 +1,278 @@
+%{
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "parser/parser.hh"
+
+// Fichiers d'en-tête générés.
+#include "yyparser.hh"
+#include "yylexer.hh"
+
+#undef yyextra
+#define yyextra (yyget_extra (scanner))
+
+void yyerror (void *scanner, const char *e);
+
+%}
+
+%error-verbose
+%pure-parser
+%lex-param {void *scanner}
+%parse-param {void *scanner}
+%defines
+%union {
+ bool b;
+ char c;
+ int i;
+ double d;
+ std::string *s;
+ struct {
+ any *a;
+ Parser::IntList *il;
+ } il;
+ struct {
+ any *a;
+ Parser::DoubleList *dl;
+ } dl;
+ struct {
+ any *a;
+ Parser::StringList *sl;
+ } sl;
+ Parser::AnyList *al;
+}
+
+%token SEP
+
+%token<b> BOOLEAN
+%token<c> UNKNOWN
+%token<c> CHAR
+%token<i> INT
+%token<d> DOUBLE
+%token<s> ID STRING
+
+%type<il> int_list int_list_i
+%type<dl> double_list double_list_i
+%type<sl> string_list string_list_i
+%type<al> arg_list
+
+%destructor { delete $$; } ID STRING
+%destructor { delete $$.a; } int_list int_list_i
+%destructor { delete $$.a; } double_list double_list_i
+%destructor { delete $$.a; } string_list string_list_i
+%destructor { delete $$; } arg_list
+
+%%
+
+input:
+ /* Nothing. */
+ | item
+ | input SEP item
+ | input SEP
+;
+
+item:
+ ID '=' BOOLEAN {
+ any a ($3);
+ if (!yyextra->assign (*$1, a))
+ YYERROR;
+ delete $1;
+ }
+ | ID '=' CHAR {
+ any a ($3);
+ if (!yyextra->assign (*$1, a))
+ YYERROR;
+ delete $1;
+ }
+ | ID '=' INT {
+ any a ($3);
+ if (!yyextra->assign (*$1, a))
+ YYERROR;
+ delete $1;
+ }
+ | ID '=' DOUBLE {
+ any a ($3);
+ if (!yyextra->assign (*$1, a))
+ YYERROR;
+ delete $1;
+ }
+ | ID '=' STRING {
+ any a (*$3);
+ if (!yyextra->assign (*$1, a))
+ YYERROR;
+ delete $1;
+ delete $3;
+ }
+ | ID '=' int_list {
+ if (!yyextra->assign (*$1, *$3.a))
+ YYERROR;
+ delete $1;
+ delete $3.a;
+ }
+ | ID '=' double_list {
+ if (!yyextra->assign (*$1, *$3.a))
+ YYERROR;
+ delete $1;
+ delete $3.a;
+ }
+ | ID '=' string_list {
+ if (!yyextra->assign (*$1, *$3.a))
+ YYERROR;
+ delete $1;
+ delete $3.a;
+ }
+ | ID arg_list {
+ if (!yyextra->call (*$1, *$2))
+ YYERROR;
+ delete $1;
+ delete $2;
+ }
+;
+
+int_list:
+ '(' int_list_i ')' {
+ $$ = $2;
+ }
+;
+
+int_list_i:
+ INT {
+ $$.a = new any (Parser::IntList ());
+ $$.il = any_cast<Parser::IntList> ($$.a);
+ $$.il->push_back ($1);
+ }
+ | int_list_i INT {
+ $1.il->push_back ($2);
+ $$ = $1;
+ }
+;
+
+double_list:
+ '(' double_list_i ')' {
+ $$ = $2;
+ }
+;
+
+double_list_i:
+ DOUBLE {
+ $$.a = new any (Parser::DoubleList ());
+ $$.dl = any_cast<Parser::DoubleList> ($$.a);
+ $$.dl->push_back ($1);
+ }
+ | double_list_i DOUBLE {
+ $1.dl->push_back ($2);
+ $$ = $1;
+ }
+;
+
+string_list:
+ '(' string_list_i ')' {
+ $$ = $2;
+ }
+;
+
+string_list_i:
+ STRING {
+ $$.a = new any (Parser::StringList ());
+ $$.sl = any_cast<Parser::StringList> ($$.a);
+ $$.sl->push_back (*$1);
+ delete $1;
+ }
+ | string_list_i STRING {
+ $1.sl->push_back (*$2);
+ $$ = $1;
+ delete $2;
+ }
+;
+
+arg_list:
+ /* empty */ {
+ $$ = new Parser::AnyList;
+ }
+ | arg_list BOOLEAN {
+ any a ($2);
+ $1->push_back (any ());
+ $1->back ().swap (a);
+ $$ = $1;
+ }
+ | arg_list CHAR {
+ any a ($2);
+ $1->push_back (any ());
+ $1->back ().swap (a);
+ $$ = $1;
+ }
+ | arg_list INT {
+ any a ($2);
+ $1->push_back (any ());
+ $1->back ().swap (a);
+ $$ = $1;
+ }
+ | arg_list DOUBLE {
+ any a ($2);
+ $1->push_back (any ());
+ $1->back ().swap (a);
+ $$ = $1;
+ }
+ | arg_list STRING {
+ any a (*$2);
+ $1->push_back (any ());
+ $1->back ().swap (a);
+ delete $2;
+ $$ = $1;
+ }
+ | arg_list int_list {
+ $1->push_back (any ());
+ $1->back ().swap (*$2.a);
+ delete $2.a;
+ $$ = $1;
+ }
+ | arg_list double_list {
+ $1->push_back (any ());
+ $1->back ().swap (*$2.a);
+ delete $2.a;
+ $$ = $1;
+ }
+ | arg_list string_list {
+ $1->push_back (any ());
+ $1->back ().swap (*$2.a);
+ delete $2.a;
+ $$ = $1;
+ }
+;
+%%
+
+/// Traite une erreur de Bison.
+void
+yyerror (void *scanner, const char *e)
+{
+ yyextra->error (e);
+}
+
+/* Shut up warning for this wrongly declared static function. */
+static int
+yy_init_globals (yyscan_t yyscanner)
+{
+ return yy_init_globals (yyscanner);
+}
+
+/* vim:ft=yacc:
+*/