%{ // 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 BOOLEAN %token UNKNOWN %token CHAR %token INT %token DOUBLE %token ID STRING %type int_list int_list_i %type
double_list double_list_i %type string_list string_list_i %type 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 ($$.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 ($$.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 ($$.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); } | arg_list CHAR { any a ($2); $1->push_back (any ()); $1->back ().swap (a); } | arg_list INT { any a ($2); $1->push_back (any ()); $1->back ().swap (a); } | arg_list DOUBLE { any a ($2); $1->push_back (any ()); $1->back ().swap (a); } | arg_list STRING { any a (*$2); $1->push_back (any ()); $1->back ().swap (a); delete $2; } | arg_list int_list { $1->push_back (any ()); $1->back ().swap (*$2.a); delete $2.a; } | arg_list double_list { $1->push_back (any ()); $1->back ().swap (*$2.a); delete $2.a; } | arg_list string_list { $1->push_back (any ()); $1->back ().swap (*$2.a); delete $2.a; } ; %% /// 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: */