⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.hh

📁 2007年机器人足球世界杯3D仿真组亚军
💻 HH
字号:
/* *  Little Green BATS (2006) * *  Authors: 	Martin Klomp (martin@ai.rug.nl) *		Mart van de Sanden (vdsanden@ai.rug.nl) *		Sander van Dijk (sgdijk@ai.rug.nl) *		A. Bram Neijt (bneijt@gmail.com) *		Matthijs Platje (mplatje@gmail.com) * *  Date: 	September 14, 2006 * *  Website:	http://www.littlegreenbats.nl * *  Comment:	Please feel free to contact us if you have any  *		problems or questions about the code. * * *  License: 	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. * */#ifndef __INC_RCP_PARSER_HH_#define __INC_RCP_PARSER_HH_#include <string>#include <stack>#include "predicate.hh"namespace bats {  /**\brief Communication parser         *    *  The parser...   *   *  \todo Issues:   *  - The parser uses a recursive algorithm, that means that if   *    a suficiently large message is parsed it might trigger   *    a stack overload. How much do we trust the soccer server?   *   *  The parser is used to parse the communication messages (the lisp like language)   *  to a Predicate (tree like structure @see Predicate).   *   */  class Parser {    Parser(Parser const &); // NI    Parser &operator=(Parser const &); // NI    /// The token type.    struct Token {      enum Type {        none = 0,    ///< Not a token.        error = 1,   ///< Error token.        lparent = 2, ///< '('        rparent = 3, ///< ')'        ws = 4,      ///< White space        id = 5,      ///< Everything that is not a ' ','(' or ')' (or: identifier).        end_of_line = 6 ///< The end of the line.      };      Type type;      std::string value;          };    /// Lexer Table element.    struct LexTable {      unsigned state0;      char r0;      char r1;      unsigned state1;    };    /// Token table element.    struct TokenTable {      unsigned state;      Token::Type token;    };    // The lexerTable contains all the fsa state changes.    static LexTable lexerTable[];    // The tokenTable contains all the end states with token type.    static TokenTable tokenTable[];    // returns state <- state when chr    unsigned lexerNextState(unsigned state, char chr);    // if the current state is an end state it    // return the token associated with it (@see tokenTable)    // otherwise it returns a token with type Token::none.    Token::Type isEndState(unsigned state);    // The lex stack keeps the pushBacks.    std::stack<Token> lex_stack;    // This is the string that is currently being lexed.    std::string lex_source;    // The iterator over the lex_source string.    std::string::iterator lex_iter;    // The current lexer state.    unsigned lex_state;    // Initializes the lexer src is the string to be lexed.    void initLex(std::string src);    // Gives the next token (it ignores whitespaces (' '|'\t').    Token lex();    // Pushes one token back unto the lex stack. The    // lex() method will return that token the next time    // it is called.    void lexPushBack(Token const &_t)    { lex_stack.push(_t); }    // De predicate parser method.    rPredicate parsePred();  public:    Parser();    /**     *  Parses _msg into a Predicate.     *  @returns the parsed message.     *  @throws parser_error (@see global.hh)     */    rPredicate parse(std::string const &_msg);    /**     *  Generates a lisp like expression of     *  the message, which can be send to the     *  simulation server.     */    std::string generate(rPredicate const &_pred);  };};#endif // __INC_RBATS_PARSER_HH_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -