00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "test-scanner.h"
00019
00020 #include <lib/message/manager.h>
00021 #include <lib/message/handler_console.h>
00022
00023 static const int MyDbg=0x10000000;
00024
00025
00026 int main()
00027 {
00028 MessageManager::init();
00029 MessageHandler_Console cons_hdl(Message::MTAll,0);
00030
00031 TestScanner scan;
00032
00033 fprintf(stderr,"sizeof(SourcePosition)=%u, sizeof(SCLocation)=%u\n",
00034 sizeof(SourcePosition),sizeof(SCLocation));
00035
00036 SError error;
00037 TLString path;
00038 int rv=scan.SetInput(path,error,0);
00039 Debug(MyDbg,"SetInput=%d (%s)",rv,error.msg().str());
00040
00041 for(;;)
00042 {
00043 TestScanner::TestToken *tok=
00044 (TestScanner::TestToken*)scan.LexNextToken();
00045
00046 if(!tok)
00047 { Debug(MyDbg,"-EOF-"); break; }
00048
00049 switch(tok->token)
00050 {
00051 case TS_IDENTIFIER:
00052 Debug(MyDbg,tok->lloc.loc0,"identifier >%s<",
00053 tok->lval.string_val);
00054 if(tok->lval.string_val && !(rand()%4))
00055 { *tok->lval.string_val='\0'; }
00056 break;
00057 case TS_INTEGER:
00058 Debug(MyDbg,tok->lloc.loc0,"integer >%d<",tok->lval.int_val);
00059 break;
00060 case TS_IF:
00061 Debug(MyDbg,tok->lloc.loc0,"IF token");
00062 break;
00063 case TS_ELSE:
00064 Debug(MyDbg,tok->lloc.loc0,"ELSE token");
00065 break;
00066 default:
00067 if(tok->token>0 && tok->token<256)
00068 {
00069 Debug(MyDbg,tok->lloc.loc0,"char token %d '%c'",
00070 tok->token,(char)tok->token);
00071 }
00072 else
00073 {
00074
00075 Error(tok->lloc.loc0,"OOPS: unknown token %d ?!",
00076 tok->token);
00077 }
00078 break;
00079 }
00080 }
00081
00082 MessageManager::cleanup();
00083 return(0);
00084 }