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

vos/corelibs/typechain/tclexer.ll

Go to the documentation of this file.
00001 /** tclexer Typechain Flex Lexical Scanner
00002     @see TypechainLexer
00003 
00004 
00005     @author Reed Hedges <reed@zerohour.net>
00006 
00007     Copyright (C) 2002 Reed Hedges
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public
00020     License along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022 
00023 */
00024 
00025 %option c++
00026 %option noyywrap
00027 %option yyclass="TypechainLexer"
00028     //%option outfile="tclexer.cc"
00029 %option prefix="tc"
00030 
00031     // Don't use this for testing (See below) !! :
00032 %option never-interactive
00033 
00034 
00035 %{
00036 
00037 //#define TESTING 1 // If defined, a test program is generated (with main()).
00038 
00039 #include "tclexer.hh"
00040 #include <iostream>
00041 
00042 //#define YY_USER_ACTION    printf("matched: %s.\n", yytext);
00043     
00044 
00045 %}
00046 
00047 %x PARAMKEY PARAMVAL
00048 
00049 WS  [ \t\r\n]
00050 TOK [^;|\: \t\r\n(),=]+
00051 
00052 
00053 %%
00054 
00055 {WS}*[;|\:]{WS}*                  complete_token(token, params);  clear_vars();
00056 {TOK}                             token = string(yytext);
00057 {WS}*"("{WS}*                     BEGIN(PARAMKEY);
00058 <PARAMKEY>{TOK}                   params[yytext] = ""; lastkey = strdup(yytext);
00059 <PARAMVAL>{TOK}                   params[lastkey] = string(yytext);
00060 <PARAMKEY>{WS}*"="{WS}*           BEGIN(PARAMVAL);
00061 <PARAMKEY,PARAMVAL>{WS}*","{WS}*  BEGIN(PARAMKEY);
00062 <PARAMKEY,PARAMVAL>{WS}*")"{WS}*  BEGIN(INITIAL);
00063 <<EOF>>                           final_type(token, params); clear_vars(); return 0;
00064 
00065 %%
00066 
00067 
00068 #ifdef TESTING
00069 /* Testing: */
00070 
00071 class TestingTypechainLexer : public TypechainLexer {
00072 
00073 public:
00074     TestingTypechainLexer(string s) : TypechainLexer(s) {
00075     }
00076 
00077     void print_params(map<string,string> params) {
00078         for(map<string,string>::const_iterator i = params.begin(); i != params.end(); i++) {
00079             printf("\tkey: '%s'  val: '%s'\n", i->first.c_str(), i->second.c_str());
00080         }
00081     }
00082 
00083     void complete_token(string token, map<string, string> params) {
00084         printf("complete_token: '%s'. params:\n", token.c_str());
00085         print_params(params);
00086     }
00087 
00088     void final_type(string token, map<string, string> params) {
00089         printf("final_type: '%s'. params:\n", token.c_str());
00090         print_params(params);
00091     }
00092 
00093 
00094 };
00095 
00096 
00097 int main() {
00098     TestingTypechainLexer lexer("hello; \n world(foo= bar\t, baz  ) |      la/la");
00099     lexer.yylex();
00100     return 0;
00101 }
00102 
00103 #endif //ifdef TESTING
00104 

Generated on Tue Aug 12 03:55:38 2003 for Interreality Project - VOS by doxygen 1.3.2