#ifndef _AS68HC11_PARSE_HPP_ #define _AS68HC11_PARSE_HPP_ #ifndef _COMMON_STRING_HPP_ #include #endif #ifndef _COMMON_SMARTPOINTER_HPP_ #include #endif #ifndef _COMMON_OPENFILE_HPP_ #include #endif #ifndef _AS68HC11_SCAN_HPP_ #include #endif #ifndef _AS68HC11_EMIT_HPP_ #include #endif #ifndef _AS68HC11_PSYMBOL_HPP_ #include #endif #ifndef _AS68HC11_PARSESYMBOLCOUNT_HPP_ #include #endif #ifndef _AS68HC11_CACHEBLOCK_HPP_ #include #endif #ifndef _AS68HC11_LABELGENERATOR_HPP_ #include #endif #ifndef _AS68HC11_FIXUP_HPP_ #include #endif #ifndef _AS68HC11_EQUATE_HPP_ #include #endif class Parse : public Emit { public: enum Status{Error,Ok}; enum ParseSymbols{codestart2,codeend2,purecode2}; Parse(PureViewOfFile &srcView,PureViewOfFile &dstView); virtual ~Parse(); BOOL parse(void); DWORD codeBytes(void)const; Status status(void)const; String lastMessage(void)const; DWORD lastLineNumber(void)const; private: enum {FirstLine=1}; enum MaxBits{MaxBit16=0xFFFF,MaxBit8=0xFF}; enum {MaxForwardJump=128,MaxBackwardJump=-128}; enum ErrorCode{IllegalAddressingModeForMnemonic,ExpectedIndexRegister,OperandSizeMustMatch, ValueOutOfRangeForInstruction,SymbolAlreadyDefined,SymbolNotDefined,BranchOutOfRange, SymbolAlreadyDifferentKind,DivideByZero}; void insertSymbols(Block &groupSymbols); void insertSymbols(const ParseSymbol &groupSymbol); void removeSymbols(Block &groupSymbols); void removeSymbols(const ParseSymbol &groupSymbol); BOOL symbolIn(Block &parseSymbols)const; BOOL symbolIn(const ParseSymbol &parseSymbol)const; BOOL peekSymbolIn(const ParseSymbol &parseSymbol); Scan::ScanSymbols currentSymbolType(void)const; void parseLabelExtended(SmartPointer ¤tSymbol,WORD indexForm); void parseLabelDirect(SmartPointer ¤tSymbol,WORD indexForm); void parseLabelImmediate(SmartPointer ¤tSymbol,WORD indexForm); void parseDirectExtended(SmartPointer ¤tSymbol,WORD indexForm,Scan::ScanSymbols peekSymbol); void parseRelativeMask(SmartPointer ¤tSymbol,Scan::ScanSymbols peekSymbol); void parseMask(SmartPointer ¤tSymbol,Scan::ScanSymbols peekSymbol); void parseIndexed(SmartPointer ¤tSymbol,WORD indexForm); void parseRelative(SmartPointer ¤tSymbol,WORD indexForm); void parseImmediate(SmartPointer ¤tSymbol,WORD indexForm); void parseInherent(SmartPointer ¤tSymbol,WORD indexForm); void parseIndex(SmartPointer ¤tSymbol,SmartPointer &addressMode,DWORD &expressionResult); BOOL emitEquate(SmartPointer ¤tSymbol,Equate &equate); BOOL emitLabel(SmartPointer ¤tSymbol,Label &label); void insertLabelFixup(SmartPointer ¤tSymbol,Label &label); void parseBranch(void); void simpleExpression(DWORD &expressionResult); void expression(DWORD &expressionResult); DWORD term(void); void factor(DWORD &expressionResult); void errorExpect(Symbol::SymbolType symbolType); void expect(Scan::ScanSymbols symbol); void syntaxError(int expectedSymbol); void createSimpleExpressionSymbols(void); void createStatementSymbols(void); void createTermSymbols(void); void createMathSymbols(void); void createAddSymbols(void); void createSignSymbols(void); void createFactorSymbols(void); void createExpressionSymbols(void); void errorExpect(int scanSymbol); void error(ErrorCode errorCode,const String &strExtraMessage=String()); void keywordStatement(void); void labelStatement(void); void equateStatement(void); void originStatement(void); void userStatement(void); void rmbStatement(void); void statement(void); void parseLiteral(void); void syntaxCheck(void); void syntaxError(void); DWORD origin(void)const; BOOL resolve(void); WORD nextSymbol(void); BOOL isInEquates(const String &strLabel); BOOL isInLabels(const String &strLabel); BOOL isInError(void)const; BOOL inRange(DWORD value,MaxBits maxBits=MaxBit16)const; BOOL jumpInRange(int distance)const; CacheBlock mParseSymbols; BOOL mIsInError; DWORD mNumeralValue; DWORD mLastLineNumber; DWORD mLineNumber; String mLastMessage; SmartPointer mCurrentSymbol; Scan::ScanSymbols mCurrentSymbolType; Block mStatementSymbols; Block mSimpleExpressionSymbols; Block mExpressionSymbols; Block mTermSymbols; Block mMathSymbols; Block mAddSymbols; Block mSignSymbols; Block mFactorSymbols; LabelGenerator mLabelGenerator; BinaryTree mEquates; Block mFixups; String mLiteralValue; FileHandle mLogFile; DWORD mCodeBytes; }; inline void Parse::insertSymbols(Block &groupSymbols) { mParseSymbols.insert(groupSymbols); } inline void Parse::insertSymbols(const ParseSymbol &groupSymbol) { mParseSymbols.insert(groupSymbol); } inline void Parse::removeSymbols(Block &groupSymbols) { mParseSymbols.remove(groupSymbols); } inline void Parse::removeSymbols(const ParseSymbol &groupSymbol) { mParseSymbols.remove(groupSymbol); } inline Parse::Status Parse::status(void)const { if(mIsInError)return Error; return Ok; } inline String Parse::lastMessage(void)const { return mLastMessage; } inline DWORD Parse::lastLineNumber(void)const { return mLastLineNumber; } inline BOOL Parse::isInError(void)const { return mIsInError; } inline Scan::ScanSymbols Parse::currentSymbolType(void)const { return mCurrentSymbolType; } inline void Parse::expect(Scan::ScanSymbols symbol) { if(symbol==currentSymbolType())nextSymbol(); else syntaxError(symbol); syntaxCheck(); } inline void Parse::syntaxCheck(void) { if(!mParseSymbols.symbolIn(currentSymbolType()))syntaxError(); } inline BOOL Parse::inRange(DWORD value,MaxBits maxBits)const { if(MaxBit16==maxBits&&value>MaxBit16)return FALSE; else if(MaxBit8==maxBits&&value>MaxBit8)return FALSE; return TRUE; } inline BOOL Parse::jumpInRange(int distance)const { if(distance>MaxForwardJump||distance