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

scanner: lex.l hush-3.0b4/api/grammar/examples/dlp


[.] - [up] [top] - index README C++ make include source logic grammar scripts
  

dlp_lex


  %class dlp_lex
  %e 5000
  
  
  include <ml/dlp/lex.h>
  
  define LEXDEBUG 1
  int yyout = 2; // AE: what ?
  include <iostream.h>
  include "yacc.tab.h"
  
  dlp_lex::dlp_lex(istream* in, ostream* out) : lex_scanner(in,out) { 
          }
  
  int dlp_lex::_op() { return OP0; /*257 is already predefined*/ }
  
  static int _debug = 0;
  static int in_obj = 0;
  static int bracks = 0;
  static char buf[1024];
  
  define P(X) if (_debug) *yyerr << "-" << X << "-";
  define found(tok,s,yytext) if (_debug && s) { \
               cerr << "Found: " << yytext << " = " \ 
               << s << " " << tok << endl; }
  
  

slide: dlp_lex


definitions


  
  
  context [ \t]*[^\n]
  stop  "."
  opsym [\+\-\*\/\^\!\?\:\;\@\#\&\$\=\<\>\~\|\.\,]
  op    ({opsym}{opsym}+)
  
  kescape ("\\\"")
  qescape ("\\\'")
  
  aseq [\$_A-Za-z0-9][\\$A-Za-z0-9_]*
  key (\:{aseq}\:|\#{aseq}\#|\~{aseq}\~|\@{aseq}\@|\.{aseq}\.)
  
  kstringelem ({kescape}|[^\"\n])
  qstringelem ({qescape}|[^\'\n])
  string  (\"{kstringelem}+\")
  qstring (\'{qstringelem}+\')
  
  atom ({aseq}|{key}|{qstring})
  
  

slide: definitions


scanner rules


  
  %.*       { /* comments */ }
  
  {atom} { P(yytext); // atom - var - key - etc
            int tok = _atom(); 
            char* s = get(yytext,&tok);
            found(tok,s,yytext);
            char* p = s?s:yytext;
            return token(tok?tok:_atom(),p);
            }
  
  {string} { P("string");
            return token(STRING,yytext);
             }
  
  

slide: scanner rules


operators -- look at the table lookup: this->get(yytext,&tok)


  
  {op}        {
          P(yytext);
          int tok = _op();
          char* s = get(yytext,&tok);
          char* p = s?s:yytext;
          found(tok,s,yytext);
          if (!s) {
                  cerr << "Warning: unrecognized token *** " << yytext
                  << " *** line: " << yylineno << endl;
                  }
          return token(tok?tok:_op(),p);
          }
  
  

slide: operators -- look at the table lookup: this->get(yytext,&tok)


dot for access & C++ style brackets


  
  "};"    { /* to allow slide formatting: "};" = <;/slide>; */
          return token('}',yytext);
          }
  \./{context} {
          P(yytext);
          int tok = _op();
          return token(tok,"<-");
          }
  
  

slide: dot for access & C++ style brackets


...


  
  [ \t]   { }
  \n        {
              if (_debug && !(yylineno%10))
  		   *yyout << "%%line: " << yylineno << endl;
            }
  
  .        { 
          P(yytext);
          int tok = yytext[0];
          char* s = get(yytext,&tok);
          char* p = s?s:yytext;
          found(tok,s,yytext);
          return token(tok?tok:yytext[0],p);
          }
  
  

slide: ...

  

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