EnglishРусский  

   ..

   lex.c

   lex.h

   lextbl.c

   lextbl.h

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\src\lex\lextbl.c
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2006, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * ID: lextbl 18.10.06 0.0.A.
 11 *
 12 * Author: Alexey Krivonogov ( gentee )
 13 *
 14 ******************************************************************************/
 15 
 16 #include "lex.h"
 17 #include "lextbl.h"
 18 //! temporary
 19 #include "../os/user/defines.h"
 20 
 21 //----------------------------------------------------------------------------
 22 
 23 uint  STDCALL lex_tbl( plex pl, puint input )
 24 {
 25    uint     count, states = *input++;
 26    uint     i, j, l, r, ch1, ch2, val;
 27    puint    start;
 28    pubyte   ptr;
 29 
 30    buf_clear( &pl->tbl );
 31    buf_reserve( &pl->tbl, states * 1024 );
 32 
 33    while ( states-- )
 34    {
 35       count = *input++;
 36       
 37       start = ( puint )( buf_ptr( &pl->tbl ) + buf_len( &pl->tbl ));
 38       // Записываем значения для 0 и по умолчанию
 39       for ( i = 0; i < 256; i++ )
 40          buf_appenduint( &pl->tbl, *input );
 41       if ( !( *input & LEXF_RET ))
 42          start[0] = LEX_STOP;
 43       for ( i = 0; i < count; i ++ )
 44       {
 45          val = *++input;
 46          l = HIBY( val );
 47          r = LOBY( val );
 48          ch1 = ( val >> 16 ) & 0xFF;
 49          ch2 = ( val >> 24 ) & 0xFF;
 50          val = *++input;
 51          if ( val & LEXF_MULTI )
 52          {
 53             uint curm, posm;
 54             plexmulti  pmulti;
 55 
 56             if ( start[r] & LEXF_MULTI )  // Уже добавлен один multi объект
 57             {
 58                curm = start[r] >> 24;
 59                posm = (( start[r] >> 16 ) & 0xff ) + 1;
 60             }
 61             else
 62             {
 63                // Надо запомнить команду в случае всех неудач и писать ее 
 64                // первой 
 65                curm = pl->imulti++;
 66                pmulti = arr_ptr( &pl->mitems, curm * 8 );
 67                pmulti->value = start[r];
 68                posm = 1;
 69                start[ r ] = ( curm << 24 ) | LEXF_MULTI;
 70             }
 71             start[ r ] &= 0xFF00FFFF;
 72             start[ r ] |= ( posm << 16 );
 73             pmulti = arr_ptr( &pl->mitems, curm * 8 + posm );
 74             pmulti->chars = *( input - 1 );
 75             if ( pmulti->chars >> 24 ) pmulti->len = 4;
 76             else
 77                if ( pmulti->chars >> 16 ) pmulti->len = 3;
 78                else
 79                   if ( pmulti->chars >> 8 ) pmulti->len = 2;
 80                   else pmulti->len = 1;
 81             pmulti->value = val & ~LEXF_MULTI;
 82 //            printf("Posm 2 = %i start = %i %s\n", posm, (start[r] >> 16 ) & 0xFF,
 83 //                      &(*( input - 1 )) );
 84             continue;
 85          }
 86          if ( l && !r)
 87          {
 88             switch ( l )
 89             {
 90                case 0x30:
 91                   for ( j = '0'; j <= '9'; j++ )
 92                      start[ j ] = val;
 93                case 0x41:
 94 //                  printf("NumName\n");
 95                   start[ '_' ] = val;
 96                   for ( j = 'A'; j <= 'Z'; j++ )
 97                   {
 98                      start[ j ] = val;
 99                      start[ _lower[j] ] = val;
100                   }
101 //                  for ( j = 'a'; j <= 'z'; j++ )
102 //                     start[ j ] = val;
103                   for ( j = 0x80; j <= 0xff; j++ )
104                      start[ j ] = val;
105                   break;
106                case 0x58:
107                   for ( j = '0'; j <= '9'; j++ )
108                      start[ j ] = val;
109                   for ( j = 'A'; j <= 'F'; j++ )
110                   {
111                      start[ j ] = val;
112                      start[ _lower[j] ] = val;
113                   }
114 //                  for ( j = 'a'; j <= 'f'; j++ )
115 //                     start[ j ] = val;
116                   break;
117             }
118          }
119          else
120             while ( l <= r )
121                start[ l++ ] = val;
122          if ( ch1 )
123             start[ ch1 ] = val;
124          if ( ch2 )
125             start[ ch2 ] = val;
126       }
127       input++;
128    }
129    ptr = ( pubyte )input;
130    if ( j = *ptr++ )
131    {
132       if ( *ptr++ & 0x0001 )
133          pl->keywords.ignore = 1;
134       for ( i = 0; i < j; i++ )
135       {
136          l = *( puint )ptr;
137          ptr += sizeof( uint );
138          while ( *ptr )
139          {
140             hash_setuint( &pl->keywords, ptr, l++ );
141 //            printf(">%s\n", ptr );
142             ptr += mem_len( ptr ) + 1;
143          }
144          ptr++;
145       }
146    }
147    return 1;
148 }
149 
150 //----------------------------------------------------------------------------
151 
Редактировать