home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / s2latex.tar.Z / s2latex.tar / s2l.l < prev    next >
Text File  |  1985-02-05  |  3KB  |  155 lines

  1. %{
  2. /*    s2l.l    1.2    85/02/04    */
  3. /* scanner for "scribe" documents.
  4.  *
  5.  * copyright (c) 1984 by Van Jacobson, Lawrence Berkeley Laboratory
  6.  * This program may be freely redistributed but not for profit.  This
  7.  * comment must remain in the program or any derivative.
  8.  */
  9.  
  10. static char bstack[256];    /* the type of closing bracket we want */
  11. static int bsp = 0;        /* "bracket" stack pointer */
  12. char    matching();
  13. %}
  14. WS    [ \t]*
  15. LB    ("("|"["|"{"|"<"|\'|\"|\`)
  16. RB    (")"|"]"|"}"|">"|\'|\"|\')
  17. %START    CS BS B C
  18. %%
  19. @[bB][lL][aA][nN][kK][sS][pP][aA][cC][eE]/{LB} {
  20.             BEGIN BS;
  21.             if ( lastsym=lookup(yytext) )
  22.                 return (lastsym->s_type);
  23.             fprintf(stderr,"lex botch: keyword %s\n", yytext );
  24.             exit(1);
  25.             }
  26. @[bB][eE][gG][iI][nN]{WS}{LB} return(get_env_name());
  27. @[eE][nN][dD]{WS}{LB}    {
  28.             get_env_name();
  29.             return(END_ENV);
  30.             }
  31. @[a-zA-Z0-9]+/{WS}{LB}    {
  32.             BEGIN CS;
  33.             if ( !(lastsym=lookup(yytext)) )
  34.                 {
  35.                 if ( kflag )
  36.                     fprintf(stderr,"unknown keyword %s\n",
  37.                         yytext );
  38.                 lastsym = enter( yytext, KW_REP, &yytext[1] );
  39.                 }
  40.             return (lastsym->s_type);
  41.             }
  42. @[a-zA-Z0-9]+        return(COMMAND);
  43. @\+/{WS}{LB}        {
  44.             BEGIN CS;
  45.             return(SUP);
  46.             }
  47. @\-/{WS}{LB}        {
  48.             BEGIN CS;
  49.             return(SUB);
  50.             }
  51. <CS>{WS}        ;
  52. <CS>{LB}        {
  53.             bstack[++bsp] = matching(*yytext);
  54.             BEGIN C;
  55.             return(LBRACK);
  56.             }
  57. <BS>{WS}        ;
  58. <BS>{LB}        {
  59.             bstack[++bsp] = matching(*yytext);
  60.             BEGIN B;
  61.             return(LBRACK);
  62.             }
  63. <B,C>{RB}        {
  64.             if ( bstack[bsp] == *yytext ) {
  65.                 if ( --bsp <= 0 )
  66.                     BEGIN 0;
  67.                 return(RBRACK);
  68.                 }
  69.             return( (*yytext=='}'||*yytext=='"')? *yytext : CHAR );
  70.             }
  71. <B>[iI][nN][cC][hH][eE][sS]    { return(INCHES); }
  72. @\\            return(TAB);
  73. @>            return(RJUST);
  74. @=            return(CENTER);
  75. @\\{WS}@=        return(CENTER);
  76. @"^"            return(SETTAB);
  77. @\\{WS}@=/{WS}\n    ;
  78. @=/{WS}\n        ;
  79. @\\/{WS}\n        ;
  80. @;            ;
  81. @~            return(STILDE);
  82. @_            return(HYPHEN);
  83. @" "             return(NPSPACE);
  84. @@            return('@');
  85. @"*"            return(LBREAK);
  86. @\.[ \t]+        return(POINT);
  87. @\.{WS}/\n        return(POINT);
  88. [<>|{}#$%&~_^\\"]    return(*yytext);
  89. .            return(CHAR);
  90. ^[     ]*\n        {
  91.             inputline++;
  92.             return(BLANKLINE);
  93.             }
  94. [     ]*\n        {
  95.             inputline++;
  96.             return('\n');
  97.             }
  98. %%
  99. yywrap() {
  100.     return (1);
  101. }
  102.  
  103. /* get the "name" part of an environment spec & discard any optional
  104.  * parameters.  The name is added to the symbol table if it isn't 
  105.  * already there.  At the time we call this routine, we've matched
  106.  * either "@begin{LB}" or "@end{LB}".  We gobble input until we find
  107.  * the matching right bracket.
  108.  */
  109. get_env_name()
  110. {
  111.     char    ename[128];
  112.     char    c;
  113.     char    *nm=ename;
  114.     char    mb = matching( yytext[yyleng-1] );
  115.  
  116.     /* get the name */
  117.     while ( isalnum( c=input() ) )
  118.         *nm++ = c;
  119.     *nm = '\0';
  120.  
  121.     /* discard everything else up to the closing bracket */
  122.     while ( c != mb )
  123.         c = input();
  124.  
  125.     /* lookup and/or add the env name */
  126.     if ( ! (lastsym = lookup(ename)) )
  127.         {
  128.         if ( kflag )
  129.             fprintf(stderr,"unknown environment %s\n", ename );
  130.         lastsym = enter( ename, ENV_REP, ename );
  131.         }
  132.     return(lastsym->s_type);
  133. }
  134.  
  135. /* return the right bracket character that matches the given left bracket
  136.  * character.
  137.  */
  138. char matching(lb)
  139. char lb;
  140. {
  141.     switch(lb) {
  142.  
  143.     case '(':  return(')');
  144.     case '[':  return(']');
  145.     case '{':  return('}');
  146.     case '<':  return('>');
  147.     case '"':  return('"');
  148.     case '\'':  return('\'');
  149.     case '`':  return('\'');
  150.     default:
  151.         fprintf(stderr,"matching botch: '%c'\n", lb );
  152.         exit(1);
  153.     }
  154. }
  155.