The DejaVU Framework -- hush 3.0
[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?

scanner: oolex.l hush-3.1/grammar/filters


[.] - [up] [top] - index README text make grammar configure slides talks
  %a 8000
  %p 12000
  %n 2000
  %e 3500
  
  

oolex


  
  int cctest = 0;
  char *name="NAME";
  char *super="lex_scanner";
  char namebuf[BUFSIZ];
  int fc=0;
  int sep=0;
  int cl=0;
  static int is_flex = 0;
  
  

slide: oolex


rules


  
  "generated by flex".* {
           is_flex = 1; ECHO;
           printf("\n\n#include <iostream.h>\n");
          }
  
  "yyinput" { ECHO; }
  "xxxyyin" { if (is_flex) printf(" *yyin "); else ECHO; } 
  
  ^"#line".* { }
  "(yyout" printf("(stderr");
  
  "yy_current_buffer->yy_input_file = ".* {
          printf("yy_current_buffer->yy_input_file = yyin;");
          }
  
  ^"#if defined(__cplusplus) || defined(__STDC__)" {
          if (!cctest) {
                  cctest = 1; 
                  cl = 39;
                  /*printf("\n#undef FLEX_SCANNER\n");*/
                  printf("// %s", yytext);
                  } else ECHO;
          }
  
  "lex_input" { printf("input"); }
  "lex_output" { printf("output"); }
  
  \%\{|\%\} ;
  
  ^\%"class ".* { strcpy(namebuf,yytext+7); name = namebuf; }
  
  ^[ \t]"#" printf("#");
  
  "getc(yyin)" { printf("yyget()"); /* "printf("YYGET"); */ }
  "putc(c,yyout)" { printf("yyput(c)"); /* printf("YYPUT("); */ }
  
  ^"# define YYLMAX BUFSIZ".* {
          if (!cctest) cl = 5;
          else
                  cl = 5 + 26;
          printf("// %s", yytext);
          }
  
  ^"fprintf(yyout,".* printf("cerr << \"bad switch yylook\" << nstr << \"\\n\";");
  
  ^"static char yy_hold_char;" { printf("// %s",yytext); }
  ^"static int yy_n_chars;" { printf("// %s ", yytext); }
  ^"static yy_state_type yy_try_NUL_trans YY_PROTO".* { printf("// %s ", yytext); }
  ^"static int yy_get_next_buffer YY_PROTO".* { printf("// %s ", yytext); }
  ^"static yy_state_type yy_get_previous_state YY_PROTO(( void ));".* { printf("// %s ", yytext); }
  ^"static void yy_fatal_error YY_PROTO(( yyconst char msg[] ))".* { printf("// %s ", yytext); }
  ^"static void yyunput YY_PROTO(( int c, char *buf_ptr ));".* { printf("// %s ", yytext); }
  ^"static void yy_init_buffer( YY_BUFFER_STATE b, istream* file );".* { printf("// %s ", yytext); }
  ^"static YY_BUFFER_STATE yy_create_buffer( istream* file, int size );".* { printf("// %s ", yytext); }
  
  ^"int yyleng; extern char".*\n {
          if (!cctest)
                  cl=9;
          else if(is_flex)
                  cl=11;
          else
          cl=9;
          printf("// %s // ", yytext);
          }
  
  ^"int yyleng;"\n {
          if (!cctest)
                  cl=12;
          else
                  cl=12;
          printf("// %s // ", yytext);
          }
  
  ^"int yyleng;"\n"char yytext[YYLMAX];"\n {
          if (!cctest)
                  cl=9;
          else
                  cl=9;
          printf("// int yyleng; char yytext[YYLMAX];  ");
          }
  
  \n { if (cl) { cl--; printf("\n// "); } else ECHO; }
  
  ^"yylex(){" { inclex();  printf("term* %s::operator()(){",name); 
                printf("if (!initialized) { init(); initialized = 1; }");
              }
  
  ^"int nstr;".* { printf("int nstr;"); }
  ^"int yyvstop[]" printf("static int yyvstop[]");
  ^"struct yywork {" printf("static struct yywork {");
  ^"struct yysvf " printf("static struct yysvf " );
  ^"char yysbuf[YYLMAX];" printf("static %s",yytext);
  ^"char *yysptr = yysbuf;" printf("static %s",yytext);
  ^"int *yyfnd;" printf("static %s",yytext);
  ^"int yyprevious" printf("static %s",yytext);
  ^"struct yysvf yysvec[]" printf("static struct yysvf yysvec[]");
  
  ^"struct yywork *" {
                  if (1) {
                          printf("inline void %s::init() {\n",super);
                          printf("/*%s/ ",yytext);
                  } else {
                          printf("void %s::init() {\n",super);
                          printf("%s ",yytext);
                  }
            }
  
  ^"struct yysvf *yybgin"  printf("/* struct yysvf */ yybgin");
  ^"char yymatch[]"  {
                          printf("yylineno = 1;\n");
                          printf("yysptr = yysbuf;\n");
                          printf("yyprevious = YYNEWLINE;\n");
                          printf("}\n");
                          printf("static %s", yytext);
                     }
  ^"char yyextra[]" printf("static %s", yytext);
  ^"int yylineno =1;".*\n printf("// %s", yytext);
  ^"char yytext[YYLMAX]".*\n { cl = 5; printf("// %s// ", yytext); }
  
  ^"yylook()" {
          if (!cctest) printf("inline int %s::%s",super, yytext);
          }
  
  ^"int yylook(void)" {
          printf("inline int %s::yylook(void)",super);
          } /* SUPER or NAME */
  
  ^"int yyback(int *p, int m)" {
          if (cctest)
                  printf("// int %s::yyback(int *p, int m)",super );
          printf("\nstatic int yyback%s(int *p, int m)",name);
  
          }
  
  ^"static void yy_fatal_error( yyconst char msg[] )" {
          printf("inline void %s::yy_fatal_error( yyconst char msg[] )",super);
          }
  
  ^"yyback(".* {
          if (!cctest) {
                  cl=25; 
                  printf("// int %s::yyback(int *p, int m)",super );
          } else {
                  cl = 1;
                  printf("static int yyback%s(int *p, int m)",name);
                  }
          } 
  
  "/* the fo".* {;}
  
  ^"int yyinput(void)" {
          if (cctest)
                  printf("static int %syyinput(void) { return 0;}",super);
          else
                  printf("int %s::yyinput(void)",super);
          }
  
  ^"yyinput()" {
          if (!cctest)
                  printf("int %s::%s{",super, yytext);
          else  {
                  printf("static int %syyinput(void){}",super);
                  cl = 30;
                  printf("\n#endif\n");
                  }
          }
  
  ^"void yyoutput(int c)" { 
                  printf("static yyoutput%s(int c)",name);
                  }
  
  ^"yyoutput(".* { 
          if (!cctest) {
                  cl=20;
                  printf("void %s::yyoutput(int c) {",super); /*}*/
          } else {
                  printf("static yyxxutput%s(int c)",name);
          }
  }
  
  ^"YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )" {
          printf("inline YY_BUFFER_STATE %s::yy_scan_buffer( char *base, yy_size_t size )",super);
          }
  
  ^"YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )" {
          printf("inline YY_BUFFER_STATE %s::yy_scan_bytes( yyconst char *bytes, int len )",super);
          }
  
  ^"YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )" {
          printf("inline YY_BUFFER_STATE %s::yy_scan_string( yyconst char *yy_str )",super);
          }
  
  ^"void yy_flush_buffer( YY_BUFFER_STATE b )" {
          printf("inline void %s::yy_flush_buffer( YY_BUFFER_STATE b )",super);
          }
  
  ^"YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )" {
          printf("YY_BUFFER_STATE %s::yy_create_buffer( istream* file, int size )",super);
          }
  
  ^"void yyunput(int c)" {
          printf("static yyunput%s(int c)",name);
          }
  
  ^"yyunput(".* { if (!cctest) {
                  cl = 3;
                  printf("void %s::yyunput(int c) {",super);  /*}*/
                  }
          else {
                  printf("static yyxxunput%s(int c)",name);
                  }
          } 
  
  ^[ t]*"FILE".*\n {
          if (!fc++) {
                  }
          else printf(yytext);
          }
  
  "if ( ! yyin )" { ;}
  "if ( ! yyout )" { ;}
  
  ^"static int yyinput YY_PROTO(( void ));" { ;}
  ^"static int yyinput()" printf("inline int %s::yyinput()",super, yytext);
  
  ^"} return(0); }" {
          printf("} return token(0,\"\",0); }");
          }
  
  ^"if(yywrap()) return(0); break;" {
          printf("if(yywrap()) return token(0,\"\",0); break;");
          }
  
  ^"YY_DECL".*\n[ \t]*"{" { 
             inclex();
             printf(" term* %s::operator()() {",name); 
             printf("if (!initialized) { init(); initialized = 1; }");
             }
  
  ^"#define yywrap() 1" { ;}
  ^"# line".*\n { ;}
  "FILE *yy_input_file;" printf("istream* yy_input_file;");
  ^"static YY_CHAR yy_hold_char;" { cl = 3; }
  ^"extern YY_CHAR *yytext;" { cl = 7; }
  ^"FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;" { ; }
  ^"static yy_state_type yy_last_accepting_state;" { cl = 2; }
  ^"static YY_CHAR *yy_c_buf_p".* { cl = 3; }
  ^"static int yy_did_buffer_switch_on_eof;" { cl = 12; }
  
  "yyin = stdin;" { printf(";"); }
  "yyout = stdout;" { printf(";"); }
  
  "b->yy_input_file = file;" printf("b->yy_input_file = file;");
  "if ( yy_current_buffer == new_buffer )"[ \t\n]+"return;" { ;}
  
  ^"static int yy_get_next_buffer()" {
          printf("inline int %s::yy_get_next_buffer()",super);
          }
  
  ^"static yy_state_type yy_get_previous_state()" {
          printf("inline yy_state_type %s::yy_get_previous_state()",super);
          }
  
  ^"static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )" {
          printf(" inline yy_state_type %s::yy_try_NUL_trans( yy_state_type yy_current_state )",super);
          }
  ^"static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )" {
          printf(" inline yy_state_type %s::yy_try_NUL_trans( register yy_state_type yy_current_state )",super);
          }
  
  ^"static void yyunput( int c, register char *yy_bp )" {
          printf("inline void %s::yyunput( int c, char *yy_bp )",super);
          }
  
  ^"static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )" {
          printf("inline void %s::yyunput( YY_CHAR c, register YY_CHAR *yy_bp )",super);
          }
  
  ^"static int yyinput()" {
          printf("inline int %s::yyinput()",super);
          }
  
  ^"void yyrestart( FILE *input_file )" {
          printf("inline void %s::yyrestart( istream* input_file )",super);
          }
  
  ^"void yy_switch_to_buffer(" {
          printf("inline void %s::yy_switch_to_buffer(",super);
          }
  
  ^"void yy_load_buffer_state(" {
          printf("inline void %s::yy_load_buffer_state(",super);
          }
  
  ^"xxYY_BUFFER_STATE yy_create_buffer( FILE *file, int size )" {
       printf("inline YY_BUFFER_STATE yy_create_buffer( istream* file, int size )", super);
       }
  
  ^"void yy_delete_buffer(" {
          printf("inline void %s::yy_delete_buffer(",super);
          }
  
  "void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )" {
       printf("inline void %s::yy_init_buffer( YY_BUFFER_STATE b, istream* file )", super);
       }
  
  "struct yy_buffer_state"\n"    {"\n"    FILE *yy_input_file;" {
       printf("struct yy_buffer_state\n{\nistream* yy_input_file;");
       }
  
  "FILE *" printf("istream* ");
  
  "yyin = yy_current_buffer->yy_input_file;" {
          printf("//yyin = yy_current_buffer->yy_input_file;");
          }
  
  "extern FILE *yyin, *yyout;" { ;}
  
  "define YY" ECHO;
  
  

slide: rules


auxiliary


  
  inclex() {
  printf("#undef ECHO\n");
  printf("#define ECHO echo()\n");
  printf("\n#ifndef FLEX_SCANNER\nstruct yysvf { struct yywork *yystoff; struct yysvf *yyother; int *yystops;};\n#endif\n");
  printf("\n#ifndef NAME\n#define NAME lex\n#endif\n");
  
  if (0) {
  printf("\n#undef FLEX_SCANNER\n");
  }
  
  if (1) {
  printf("\n#ifdef FLEX_SCANNER\n");
  printf("\n#undef YY_INPUT\n");
  printf("\n#define YY_INPUT(B,R,S) yy_input(B,R,S);\n");
  printf("\ninline YY_BUFFER_STATE lex_scanner::yy_create_buffer( istream* file, int size );\n");
  printf("\ninline void lex_scanner::yy_init_buffer( YY_BUFFER_STATE b, istream* file );\n");
  printf("\ninline void lex_scanner::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer );\n");
  printf("\n#endif\n\n");
  }
  
  }
  
  

slide: auxiliary

  

[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?
Hush Online Technology
hush@cs.vu.nl
11/03/98