1 /* 2 3 IMASM Macro Precompiler 4 5 Copyright (C) 2003 Joe Fisher, Shiny Technologies, LLC 6 http://www.shinytechnologies.com 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 22 */ 23 24 #ifndef PARSER_H_INCLUDED 25 #define PARSER_H_INCLUDED 26 27 #include <string> 28 #include <list> 29 #include <map> 30 31 #include "strfifo.h" 32 33 int stricmp_(const char *str1, const char *str2); 34 35 enum 36 { 37 mPAREN, 38 mNOPAREN, 39 mUNKNOWN 40 }; 41 42 typedef struct _tag_symbol 43 { 44 std::string sName; 45 int iVal; 46 int iSize; 47 } symbol; 48 49 typedef struct _tag_macro 50 { 51 std::string sName; 52 int iType; 53 std::vector<std::string> argVector; 54 std::vector<std::string> codeVector; 55 } macro; 56 57 struct Parser_ltstr 58 { operatorParser_ltstr59 bool operator()(const char* s1, const char* s2) const 60 { 61 return strcmp(s1, s2) < 0; 62 } 63 }; 64 65 class Parser 66 { 67 public: Parser(StringFIFO * iFIFO,StringFIFO * oFIFO)68 Parser(StringFIFO *iFIFO, StringFIFO *oFIFO) : 69 inputFIFO (iFIFO), 70 outputFIFO(oFIFO), num_expansions(0) { } 71 72 ~Parser(); 73 74 int ParseSourceFile(); 75 int ParseUntilOutput(); GetErrorStr()76 char *GetErrorStr() {return m_szError;} 77 78 struct ParseError 79 { 80 std::string msg; ParseErrorParseError81 ParseError(std::string &m) : msg(m) { } 82 }; 83 84 85 private: 86 87 StringFIFO *inputFIFO, *outputFIFO; 88 int num_expansions; 89 90 void PutString(std::string &s, bool addNl = true, 91 IgnoreFlags Ignore = {false,false}); 92 void PutStringAsCmt(std::string &s, bool addNl = true, 93 IgnoreFlags Ignore = {false,false}); 94 95 int ParseLine(std::string &s); 96 int ReadMacro(macro *pMacro, std::string &szLine); 97 int ExpandMacro(macro *pMacro, std::string &sLine, 98 std::string &sTargetString); 99 int ThrowError(const char *format, ...); 100 int ThrowWarning(const char *format, ...); 101 int FindMacros(std::string &sLine, std::string &sOut); 102 int StripReturn(std::string &s); 103 int StripReturn(char *s); 104 105 macro *GetMacroPtr(const char *macName); 106 int GetMacroString(macro *pMacro, std::string &sLine, 107 std::string &sOut); 108 int GetMacroArgs(macro *pMacro, std::string &sMacro); 109 int GetMacroArgs(std::string &sMacName, std::string &sMacro, 110 std::vector<std::string> &argVector, int iType); 111 112 std::map<const char *, macro *, Parser_ltstr> m_macroMap; 113 char m_szError[MAX_PATH]; 114 }; 115 116 #endif 117 118