"Fossies" - the Fresh Open Source Software Archive

Member "ragel-6.10/examples/gotocallret.cpp" (24 Mar 2017, 5205 Bytes) of package /linux/misc/ragel-6.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "gotocallret.cpp": 6.9_vs_6.10.

    1 
    2 #line 1 "gotocallret.rl"
    3 /*
    4  * Demonstrate the use of goto, call and return. This machine expects either a
    5  * lower case char or a digit as a command then a space followed by the command
    6  * arg. If the command is a char, then the arg must be an a string of chars.
    7  * If the command is a digit, then the arg must be a string of digits. This
    8  * choice is determined by action code, rather than though transition
    9  * desitinations.
   10  */
   11 
   12 #include <iostream>
   13 #include <stdlib.h>
   14 #include <stdio.h>
   15 #include <string.h>
   16 
   17 using namespace std;
   18 
   19 struct GotoCallRet 
   20 {
   21     char comm;
   22     int cs, top, stack[32];
   23 
   24     int init( );
   25     int execute( const char *data, int len, bool isEof );
   26     int finish( );
   27 };
   28 
   29 
   30 #line 57 "gotocallret.rl"
   31 
   32 
   33 
   34 #line 35 "gotocallret.cpp"
   35 static const int GotoCallRet_start = 7;
   36 static const int GotoCallRet_first_final = 7;
   37 static const int GotoCallRet_error = 0;
   38 
   39 static const int GotoCallRet_en_garble_line = 3;
   40 static const int GotoCallRet_en_alp_comm = 5;
   41 static const int GotoCallRet_en_dig_comm = 6;
   42 static const int GotoCallRet_en_main = 7;
   43 
   44 
   45 #line 60 "gotocallret.rl"
   46 
   47 int GotoCallRet::init( )
   48 {
   49     
   50 #line 51 "gotocallret.cpp"
   51     {
   52     cs = GotoCallRet_start;
   53     top = 0;
   54     }
   55 
   56 #line 64 "gotocallret.rl"
   57     return 1;
   58 }
   59 
   60 int GotoCallRet::execute( const char *data, int len, bool isEof )
   61 {
   62     const char *p = data;
   63     const char *pe = data + len;
   64     const char *eof = isEof ? pe : 0;
   65 
   66     
   67 #line 68 "gotocallret.cpp"
   68     {
   69     if ( p == pe )
   70         goto _test_eof;
   71     goto _resume;
   72 
   73 _again:
   74     switch ( cs ) {
   75         case 7: goto st7;
   76         case 0: goto st0;
   77         case 1: goto st1;
   78         case 2: goto st2;
   79         case 3: goto st3;
   80         case 4: goto st4;
   81         case 8: goto st8;
   82         case 5: goto st5;
   83         case 9: goto st9;
   84         case 6: goto st6;
   85         case 10: goto st10;
   86     default: break;
   87     }
   88 
   89     if ( ++p == pe )
   90         goto _test_eof;
   91 _resume:
   92     switch ( cs )
   93     {
   94 tr2:
   95 #line 52 "gotocallret.rl"
   96     {cout << "correct command" << endl;}
   97     goto st7;
   98 st7:
   99     if ( ++p == pe )
  100         goto _test_eof7;
  101 case 7:
  102 #line 103 "gotocallret.cpp"
  103     if ( (*p) > 57 ) {
  104         if ( 97 <= (*p) && (*p) <= 122 )
  105             goto tr11;
  106     } else if ( (*p) >= 48 )
  107         goto tr11;
  108     goto tr0;
  109 tr0:
  110 #line 56 "gotocallret.rl"
  111     {p--;{goto st3;}}
  112     goto st0;
  113 tr7:
  114 #line 38 "gotocallret.rl"
  115     {p--;{cs = stack[--top];goto _again;}}
  116     goto st0;
  117 tr9:
  118 #line 39 "gotocallret.rl"
  119     {p--;{cs = stack[--top];goto _again;}}
  120     goto st0;
  121 #line 122 "gotocallret.cpp"
  122 st0:
  123 cs = 0;
  124     goto _out;
  125 tr11:
  126 #line 51 "gotocallret.rl"
  127     {comm = (*p);}
  128     goto st1;
  129 st1:
  130     if ( ++p == pe )
  131         goto _test_eof1;
  132 case 1:
  133 #line 134 "gotocallret.cpp"
  134     if ( (*p) == 32 )
  135         goto tr1;
  136     goto tr0;
  137 tr1:
  138 #line 42 "gotocallret.rl"
  139     {
  140         if ( comm >= 'a' )
  141             {stack[top++] = 2;goto st5;}
  142         else 
  143             {stack[top++] = 2;goto st6;}
  144     }
  145     goto st2;
  146 st2:
  147     if ( ++p == pe )
  148         goto _test_eof2;
  149 case 2:
  150 #line 151 "gotocallret.cpp"
  151     if ( (*p) == 10 )
  152         goto tr2;
  153     goto tr0;
  154 st3:
  155     if ( ++p == pe )
  156         goto _test_eof3;
  157 case 3:
  158     if ( (*p) == 10 )
  159         goto tr4;
  160     goto tr3;
  161 tr3:
  162 #line 34 "gotocallret.rl"
  163     {cout << "error: garbling line" << endl;}
  164     goto st4;
  165 st4:
  166     if ( ++p == pe )
  167         goto _test_eof4;
  168 case 4:
  169 #line 170 "gotocallret.cpp"
  170     if ( (*p) == 10 )
  171         goto tr6;
  172     goto st4;
  173 tr4:
  174 #line 34 "gotocallret.rl"
  175     {cout << "error: garbling line" << endl;}
  176 #line 34 "gotocallret.rl"
  177     {{goto st7;}}
  178     goto st8;
  179 tr6:
  180 #line 34 "gotocallret.rl"
  181     {{goto st7;}}
  182     goto st8;
  183 st8:
  184     if ( ++p == pe )
  185         goto _test_eof8;
  186 case 8:
  187 #line 188 "gotocallret.cpp"
  188     goto st0;
  189 st5:
  190     if ( ++p == pe )
  191         goto _test_eof5;
  192 case 5:
  193     if ( (*p) > 90 ) {
  194         if ( 97 <= (*p) && (*p) <= 122 )
  195             goto st9;
  196     } else if ( (*p) >= 65 )
  197         goto st9;
  198     goto tr7;
  199 st9:
  200     if ( ++p == pe )
  201         goto _test_eof9;
  202 case 9:
  203     if ( (*p) > 90 ) {
  204         if ( 97 <= (*p) && (*p) <= 122 )
  205             goto st9;
  206     } else if ( (*p) >= 65 )
  207         goto st9;
  208     goto tr7;
  209 st6:
  210     if ( ++p == pe )
  211         goto _test_eof6;
  212 case 6:
  213     if ( 48 <= (*p) && (*p) <= 57 )
  214         goto st10;
  215     goto tr9;
  216 st10:
  217     if ( ++p == pe )
  218         goto _test_eof10;
  219 case 10:
  220     if ( 48 <= (*p) && (*p) <= 57 )
  221         goto st10;
  222     goto tr9;
  223     }
  224     _test_eof7: cs = 7; goto _test_eof; 
  225     _test_eof1: cs = 1; goto _test_eof; 
  226     _test_eof2: cs = 2; goto _test_eof; 
  227     _test_eof3: cs = 3; goto _test_eof; 
  228     _test_eof4: cs = 4; goto _test_eof; 
  229     _test_eof8: cs = 8; goto _test_eof; 
  230     _test_eof5: cs = 5; goto _test_eof; 
  231     _test_eof9: cs = 9; goto _test_eof; 
  232     _test_eof6: cs = 6; goto _test_eof; 
  233     _test_eof10: cs = 10; goto _test_eof; 
  234 
  235     _test_eof: {}
  236     if ( p == eof )
  237     {
  238     switch ( cs ) {
  239     case 5: 
  240 #line 38 "gotocallret.rl"
  241     {p--;{cs = stack[--top];    if ( p == pe )
  242         goto _test_eof;
  243 goto _again;}}
  244     break;
  245     case 6: 
  246 #line 39 "gotocallret.rl"
  247     {p--;{cs = stack[--top];    if ( p == pe )
  248         goto _test_eof;
  249 goto _again;}}
  250     break;
  251     case 1: 
  252     case 2: 
  253 #line 56 "gotocallret.rl"
  254     {p--;{       if ( p == pe )
  255                goto _test_eof3;
  256 goto st3;}}
  257     break;
  258 #line 259 "gotocallret.cpp"
  259     }
  260     }
  261 
  262     _out: {}
  263     }
  264 
  265 #line 74 "gotocallret.rl"
  266     if ( cs == GotoCallRet_error )
  267         return -1;
  268     if ( cs >= GotoCallRet_first_final )
  269         return 1;
  270     return 0;
  271 }
  272 
  273 #define BUFSIZE 1024
  274 
  275 int main()
  276 {
  277     char buf[BUFSIZE];
  278 
  279     GotoCallRet gcr;
  280     gcr.init();
  281     while ( fgets( buf, sizeof(buf), stdin ) != 0 )
  282         gcr.execute( buf, strlen(buf), false );
  283 
  284     gcr.execute( 0, 0, true );
  285     if ( gcr.cs < GotoCallRet_first_final )
  286         cerr << "gotocallret: error: parsing input" << endl;
  287     return 0;
  288 }