4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
8 // This header just wraps the standard flex C++ header to make it easier to include
9 // without having to worry about redefinitions of the class name every time.
11 #if !defined(_ElftosbLexer_h_)
12 #define _ElftosbLexer_h_
14 #include "ElftosbAST.h"
15 #include "FlexLexer.h"
16 #include "elftosb_parser.tab.hpp"
28 * \brief Exception class for syntax errors.
30 class syntax_error : public std::runtime_error
33 explicit syntax_error(const std::string & __arg) : std::runtime_error(__arg) {}
37 * \brief Exception class for lexical errors.
39 class lexical_error : public std::runtime_error
42 explicit lexical_error(const std::string & __arg) : std::runtime_error(__arg) {}
46 * \brief Lexical scanner class for elftosb command files.
48 * This class is a subclass of the standard C++ lexer class produced by
49 * Flex. It's primary purpose is to provide a clean way to report values
50 * for symbols, without using the yylval global. This is necessary because
51 * the parser produced by Bison is a "pure" parser.
53 * In addition, this class manages a list of source names generated by
54 * parsing. The lexer uses this list to determine if an identifier is
55 * a source name or a constant identifier.
57 class ElftosbLexer : public yyFlexLexer
60 //! \brief Constructor.
61 ElftosbLexer(istream & inputStream);
63 //! \brief Lexer interface. Returns one token.
66 //! \brief Returns the value for the most recently produced token in \a value.
67 virtual void getSymbolValue(YYSTYPE * value);
69 //! \brief Returns the current token's location in \a loc.
70 inline token_loc_t & getLocation() { return m_location; }
72 //! \name Source names
74 void addSourceName(std::string * ident);
75 bool isSourceName(std::string * ident);
79 YYSTYPE m_symbolValue; //!< Value for the current token.
80 int m_line; //!< Current line number.
81 token_loc_t m_location; //!< Location for the current token.
82 Blob * m_blob; //!< The binary object value as its being constructed.
83 int m_blobFirstLine; //!< Line number for the first character of a blob.
85 typedef std::vector<std::string> string_vector_t;
86 string_vector_t m_sources; //!< Vector of source identifiers;
88 //! \brief Throw an elftosb::lexical_error exception.
89 virtual void LexerError(const char * msg);
91 //! \brief Process a string containing escape sequences.
92 int processStringEscapes(const char * in, char * out);
95 }; // namespace elftosb
97 #endif // _ElftosbLexer_h_