Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/lex/test-scanner-main.cc

Go to the documentation of this file.
00001 /*
00002  * lib/lex/test-scanner-main.ll
00003  * 
00004  * Test and demo scanner. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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,/*use_color=*/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; // null ref for now
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                     // This should not happen. 
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 }

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5