| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef PARSEREX_H |
| 23 |
#define PARSEREX_H |
| 24 |
#include "parser.h" |
| 25 |
#include "vstring.h" |
| 26 |
|
| 27 |
class ParserEx : public Parser |
| 28 |
{ |
| 29 |
public: |
| 30 |
ParserEx(); |
| 31 |
virtual ~ParserEx(); |
| 32 |
|
| 33 |
protected: |
| 34 |
enum eCharacters { |
| 35 |
|
| 36 |
SPACE = ' ', |
| 37 |
NEWLINE = '\n', |
| 38 |
CRETURN = '\r', |
| 39 |
FORMFEED = '\f', |
| 40 |
TAB = '\t', |
| 41 |
VTAB = '\v', |
| 42 |
|
| 43 |
|
| 44 |
DOUBLE_QUOTE = '"', |
| 45 |
SINGLE_QUOTE = '\'', |
| 46 |
BACKSLASH = '\\', |
| 47 |
|
| 48 |
STRING_SYMBOL = ('S' + 0x80), |
| 49 |
CHAR_SYMBOL = ('C' + 0x80) |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
void cppInit (const bool state, const bool hasAtLiteralStrings); |
| 54 |
void cppTerminate (void); |
| 55 |
|
| 56 |
bool isBraceFormat (void); |
| 57 |
unsigned int getDirectiveNestLevel (void); |
| 58 |
void cppBeginStatement (void); |
| 59 |
void cppEndStatement (void); |
| 60 |
void cppUngetc (const int c); |
| 61 |
int cppGetc (void); |
| 62 |
int skipOverCComment (void); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
bool isident(const char c) const { return (isalnum(c) || (c) == '_' || (c) == '$'); }; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
bool isident1(const char c) const { return (isalpha(c) || (c) == '_' || (c) == '~' || (c) == '$'); } |
| 76 |
|
| 77 |
private: |
| 78 |
enum Comment { COMMENT_NONE, COMMENT_C, COMMENT_CPLUS }; |
| 79 |
|
| 80 |
enum eCppLimits { |
| 81 |
MaxCppNestingLevel = 20, |
| 82 |
MaxDirectiveName = 10 |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
typedef struct sConditionalInfo { |
| 88 |
bool ignoreAllBranches; |
| 89 |
bool singleBranch; |
| 90 |
bool branchChosen; |
| 91 |
bool ignoring; |
| 92 |
} conditionalInfo; |
| 93 |
|
| 94 |
enum eState { |
| 95 |
DRCTV_NONE, |
| 96 |
DRCTV_DEFINE, |
| 97 |
DRCTV_HASH, |
| 98 |
DRCTV_IF, |
| 99 |
DRCTV_PRAGMA, |
| 100 |
DRCTV_UNDEF |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
int ungetch, ungetch2; |
| 106 |
bool resolveRequired; |
| 107 |
bool hasAtLiteralStrings; |
| 108 |
struct sDirective { |
| 109 |
enum eState state; |
| 110 |
bool accept; |
| 111 |
vString * name; |
| 112 |
unsigned int nestLevel; |
| 113 |
conditionalInfo ifdef [MaxCppNestingLevel]; |
| 114 |
} directive; |
| 115 |
|
| 116 |
|
| 117 |
bool BraceFormat; |
| 118 |
|
| 119 |
|
| 120 |
bool readDirective (int c, char *const name, unsigned int maxLength); |
| 121 |
void readIdentifier (int c, vString *const name); |
| 122 |
conditionalInfo *currentConditional (void); |
| 123 |
bool isIgnore (void); |
| 124 |
bool setIgnore (const bool ignore); |
| 125 |
bool isIgnoreBranch (void); |
| 126 |
void chooseBranch (void); |
| 127 |
bool pushConditional (const bool firstBranchChosen); |
| 128 |
bool popConditional (void); |
| 129 |
void makeDefineTag (const char *const name); |
| 130 |
void directiveDefine (const int c); |
| 131 |
void directivePragma (int c); |
| 132 |
bool directiveIf (const int c); |
| 133 |
bool directiveHash (const int c); |
| 134 |
bool handleDirective (const int c); |
| 135 |
Comment isComment (void); |
| 136 |
int skipOverCplusComment (void); |
| 137 |
int skipToEndOfString (bool ignoreBackslash); |
| 138 |
int skipToEndOfChar (void); |
| 139 |
|
| 140 |
}; |
| 141 |
|
| 142 |
#endif |