00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FALCON_LEXER_H
00017 #define FALCON_LEXER_H
00018
00019 #include <falcon/setup.h>
00020 #include <falcon/stream.h>
00021 #include <falcon/string.h>
00022 #include <falcon/types.h>
00023 #include <falcon/basealloc.h>
00024
00025 namespace Falcon
00026 {
00027
00028 class SyntreeElement;
00029 class Compiler;
00030 class Stream;
00031
00032 class FALCON_DYN_CLASS SrcLexer: public BaseAlloc
00033 {
00034 public:
00036 typedef enum {
00038 ct_top,
00040 ct_round,
00042 ct_square,
00044 ct_string,
00046 ct_graph,
00048 ct_inner
00049 } t_contextType;
00050
00051 private:
00052
00053
00054 class Context: public BaseAlloc
00055 {
00056 public:
00057 t_contextType m_ct;
00058 int m_oline;
00059 Context* m_prev;
00060
00061 Context( t_contextType ct, int openLine, Context* prev=0):
00062 m_ct( ct ),
00063 m_oline( openLine ),
00064 m_prev( prev )
00065 {
00066 }
00067 };
00068
00069 void *m_value;
00070 int m_line;
00071 int m_previousLine;
00072 int m_character;
00073 int m_prevStat;
00074 bool m_firstEq;
00075 bool m_done;
00076 bool m_addEol;
00077 bool m_lineFilled;
00078 bool m_bIsDirectiveLine;
00079 bool m_incremental;
00080 bool m_lineContContext;
00081 bool m_graphAgain;
00082 uint32 m_chrEndString;
00083 bool m_mlString;
00084
00085 Stream *m_in;
00086 List m_streams;
00087 List m_streamLines;
00088
00089 Compiler *m_compiler;
00090 String m_string;
00091
00092 typedef enum
00093 {
00094 e_line,
00095 e_string,
00096 e_stringOctal,
00097 e_stringBin,
00098 e_stringHex,
00099 e_stringRunning,
00100 e_loadDirective,
00101 e_eolComment,
00102 e_blockComment,
00103 e_zeroNumber,
00104 e_intNumber,
00105 e_binNumber,
00106 e_octNumber,
00107 e_hexNumber,
00108 e_floatNumber,
00109 e_floatNumber_e,
00110 e_floatNumber_e1,
00111 e_operator,
00112 e_symbol,
00113 e_litString
00114 } t_state;
00115
00116 t_state m_state;
00117
00118 typedef enum
00119 {
00120 t_mNormal,
00121 t_mOutscape,
00122 t_mEval
00123 } t_mode;
00124
00125 t_mode m_mode;
00126 bool m_bParsingFtd;
00127 bool m_bWasntEmpty;
00128 String m_whiteLead;
00129
00130 Context* m_topCtx;
00131
00132
00134 int checkUnlimitedTokens( uint32 nextChar );
00135
00136 int checkLimitedTokens();
00137 void checkContexts();
00138
00139 bool isWhiteSpace( uint32 chr ) {
00140 return chr == ' ' || chr == '\t' || chr == '\r' || chr == '\b' || chr == 0x12
00141 || chr == 0x3000 || chr == 0x00A0;
00142 }
00143
00145 bool isSpecialChar( uint32 chr )
00146 {
00147
00148 return chr == 0x3000 || chr == 0x00A0 ||
00149
00150 chr == 0x201C || chr == 0x201D ||
00151 chr == 0x300C || chr == 0x300D ||
00152 chr == 0xFF09 || chr == 0xFF08;
00153 }
00154
00155 bool isSymbolChar( uint32 chr )
00156 {
00157 return (chr >= '0' && chr <= '9') ||
00158 (chr >= 'a' && chr <= 'z') ||
00159 (chr >= 'A' && chr <= 'Z') ||
00160 chr == '_' ||
00161 ( chr > 0x80 && ! isSpecialChar(chr) );
00162 }
00163
00164 bool isTokenLimit( uint32 chr )
00165 {
00166 return ! isSymbolChar( chr );
00167 }
00168
00169
00170 int state_line( uint32 chr );
00171
00172 int lex_normal();
00173 int lex_outscape();
00174 int lex_eval();
00175
00176 public:
00177 SrcLexer( Compiler *comp );
00178 ~SrcLexer();
00179
00181 int line() const {
00182 return m_line;
00183 }
00184
00186 int character() const {
00187 return m_character;
00188 }
00189
00190 int previousLine() const {
00191 return m_previousLine;
00192 }
00193
00194 void resetContexts();
00195
00196 void line( int val ) { m_line = val; }
00197
00204 int doLex( void *param )
00205 {
00206 m_value = param;
00207 return lex();
00208 }
00209
00210 void *value() const { return m_value; }
00211 int lex();
00212
00213 void input( Stream *i );
00214 Stream *input() const { return m_in; }
00215
00217 void reset();
00218
00219 bool parsingFtd() const { return m_bParsingFtd; }
00220 void parsingFtd( bool b );
00221
00222 bool hasOpenContexts() { return m_topCtx != 0 || m_lineContContext; }
00223 bool incremental() const { return m_incremental; }
00224 void incremental( bool b ) { m_incremental = b; }
00225
00226 void appendStream( Stream *s );
00227 void parseMacro();
00228 void parseMacroCall();
00229
00231 void pushContext( t_contextType ct, int startLine );
00232
00236 bool popContext();
00237
00241 t_contextType currentContext();
00242
00246 int contextStart();
00247
00251 bool inParCtx();
00252
00257 bool readAhead( uint32 &chr );
00258 };
00259
00260 }
00261
00262 #endif
00263
00264