home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / scpp.t.Z / scpp.t / lex.l < prev    next >
Text File  |  2009-11-06  |  2KB  |  101 lines

  1. %{
  2. /*
  3.  * scpp - selective C preprocessor
  4.  *  Lexical scanner
  5.  *
  6.  * Copyright (c) 1985 by
  7.  * Tektronix, Incorporated Beaverton, Oregon 97077
  8.  * All rights reserved.
  9.  *
  10.  * Permission is hereby granted for personal, non-commercial
  11.  * reproduction and use of this program, provided that this
  12.  * notice and all copyright notices are included in any copy.
  13.  */
  14.  
  15. # include <stdio.h>
  16.  
  17. # undef input
  18. # undef unput
  19. # define input() (*nxtin == ATTN ? nxtc() : *nxtin++)
  20. # define unput(c) unc(c)
  21.  
  22. # include "scpp.h"
  23. # include "y.tab.h"
  24.  
  25. int lasttok = NL;    /* used to detect ^# when lex can't    */
  26. # define yield(t) lasttok = t; questr(yytext, yyleng); return(t)
  27.  
  28. /*
  29.  * All input to higher levels of scpp is provided exclusively by this
  30.  *  lexical analyzer, xxlex().
  31.  * This routine is called xxlex() rather than yylex() because the "#if"
  32.  *  expression parser uses a slightly different lexical analyzer (which
  33.  *  calls xxlex()).
  34.  */
  35.  
  36. %}
  37. %%
  38.  
  39. "<"    {yield(LT);}
  40. "<="    {yield(LE);}
  41. ">"    {yield(GT);}
  42. ">="    {yield(GE);}
  43. ","    {yield(CM);}
  44. "/"    {yield(DIV);}
  45. "%"    {yield(MOD);}
  46. "+"    {yield(PLUS);}
  47. "-"    {yield(MINUS);}
  48. "<<"    {yield(LS);}
  49. ">>"    {yield(RS);}
  50. "*"    {yield(MUL);}
  51. "=="    {yield(EQ);}
  52. "!="    {yield(NE);}
  53. "&"    {yield(AND);}
  54. "|"    {yield(OR);}
  55. "^"    {yield(ER);}
  56. "&&"    {yield(ANDAND);}
  57. "||"    {yield(OROR);}
  58. "?"    {yield(QUEST);}
  59. ":"    {yield(COLON);}
  60. "!"    {yield(NOT);}
  61. "~"    {yield(COMPL);}
  62. "("    {yield(LP);}
  63. ")"    {yield(RP);}
  64. ","    {yield(CM);}
  65. [ \t]+    {yield(WHITE);    /* whitespace */}
  66. \\\n    {/* escaped newline */
  67.         if (curfile->af_raw) {
  68.             curfile->af_line++;
  69.         }
  70.         yield(QNL);
  71.     }
  72. \n    {/* unescaped newline */
  73.         if (curfile->af_raw) {
  74.             curfile->af_line++;
  75.         }
  76.         yield(NL);
  77.     }
  78. 0x[0-9a-fA-F]+[Ll]?    {yield(INT); /* hex constant */}
  79. [0-9]+[Ll]?        {yield(INT); /* decimal or octal constant */}
  80. [0-9]+[Ee]([+-][0-9])?[0-9]*        |
  81. \.[0-9]+([Ee]([+-][0-9])?[0-9]*)?    |
  82. [0-9]+\.[0-9]*([Ee]([+-][0-9])?[0-9]*)?    {yield(FLOAT); /* floating constant */}
  83. [a-zA-Z_][a-zA-Z0-9_]*    {yield(IDENT); /* identifier */}
  84. \'    {yield(QUOTE);}
  85. \"    {yield(DQUOTE);}
  86. \\    {yield(BACKS);}
  87. "/*"    {yield(OPENC); /* start (open) comment */}
  88. "*/"    {yield(CLOSEC);/* finish (close) comment */}
  89. #    {/*
  90.       * a control line if preceeded immediately by a newline,
  91.       *  even if that newline was the result of macro interpretation.
  92.       */
  93.         if (lasttok == NL) {
  94.             yield(POUNDLINE);
  95.         }
  96.         yield(OTHER);
  97.     }
  98. .    {yield(OTHER);}
  99.  
  100. %%
  101.