token.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. init_token
  2. get_token
  3. get_token_literal
  4. get_token_p

   1 #include "confdef.h"
   2 
   3 #include "token.h"
   4 
   5 /* 1 バイトのトークン */
   6 static token one_byte_token[256];
   7 
   8 /* その他のスタティックなトークン */
   9 static token const token_eof        =  {LEXVAL_eof,       {0}};
  10 static token const token_coloneq    =  {LEXVAL_coloneq,   {0}};
  11 static token const token_eqeq       =  {LEXVAL_eqeq,      {0}};
  12 static token const token_bangeq     =  {LEXVAL_bangeq,    {0}};
  13 static token const token_lt_or_eq   =  {LEXVAL_lt_or_eq,  {0}};
  14 static token const token_gt_or_eq   =  {LEXVAL_gt_or_eq,  {0}};
  15 static token const token_lsl        =  {LEXVAL_lsl,       {0}};
  16 static token const token_lsr        =  {LEXVAL_lsr,       {0}};
  17 static token const token_asr        =  {LEXVAL_asr,       {0}};
  18 
  19 static token const token_IF         =  {LEXVAL_IF,        {0}};
  20 static token const token_WHILE      =  {LEXVAL_WHILE,     {0}};
  21 static token const token_PROC       =  {LEXVAL_PROC,      {0}};
  22 static token const token_WORD       =  {LEXVAL_WORD,      {0}};
  23 static token const token_GETCHAR    =  {LEXVAL_GETCHAR,   {0}};
  24 static token const token_PUTCHAR    =  {LEXVAL_PUTCHAR,   {0}};
  25 static token const token_SET        =  {LEXVAL_SET,       {0}};
  26 static token const token_DEFPROC    =  {LEXVAL_DEFPROC,   {0}};
  27 static token const token_CALL       =  {LEXVAL_CALL,      {0}};
  28 
  29 /* 初期化 */
  30 void
  31 init_token(void)
     /* [<][>][^][v][top][bottom][index][help] */
  32 {
  33   int i;
  34 
  35   for (i = 0; i < 256; i++)
  36     {
  37       one_byte_token[i].lex = i;
  38       one_byte_token[i].sem = 0;
  39     }
  40 }
  41 
  42 token const
  43 get_token(lexval lv)
     /* [<][>][^][v][top][bottom][index][help] */
  44 {
  45   if (lv < 256)
  46     {
  47       return one_byte_token[lv];
  48     }
  49   else
  50     {
  51       switch (lv)
  52         {
  53         case LEXVAL_eof:
  54           return token_eof;
  55         case LEXVAL_coloneq:
  56           return token_coloneq;
  57         case LEXVAL_eqeq:
  58           return token_eqeq;
  59         case LEXVAL_bangeq:
  60           return token_bangeq;
  61         case LEXVAL_lt_or_eq:
  62           return token_lt_or_eq;
  63         case LEXVAL_gt_or_eq:
  64           return token_gt_or_eq;
  65         case LEXVAL_lsl:
  66           return token_lsl;
  67         case LEXVAL_lsr:
  68           return token_lsr;
  69         case LEXVAL_asr:
  70           return token_asr;
  71 
  72         case LEXVAL_IF:
  73           return token_IF;
  74         case LEXVAL_WHILE:
  75           return token_WHILE;
  76         case LEXVAL_PROC:
  77           return token_PROC;
  78         case LEXVAL_WORD:
  79           return token_WORD;
  80         case LEXVAL_GETCHAR:
  81           return token_GETCHAR;
  82         case LEXVAL_PUTCHAR:
  83           return token_PUTCHAR;
  84         case LEXVAL_SET:
  85           return token_SET;
  86         case LEXVAL_DEFPROC:
  87           return token_DEFPROC;
  88         case LEXVAL_CALL:
  89           return token_CALL;
  90 
  91         default:
  92           EMSTOP("unknown token", 0);
  93           exit(1);
  94         }
  95     }
  96 }
  97 
  98 token const
  99 get_token_literal(zinc_word w)
     /* [<][>][^][v][top][bottom][index][help] */
 100 {
 101   token newtoken;
 102 
 103   newtoken.lex = LEXVAL_literal;
 104   newtoken.sem.w = w;
 105 
 106   return newtoken;
 107 }
 108 
 109 token const
 110 get_token_p(lexval lv, void *p)
     /* [<][>][^][v][top][bottom][index][help] */
 111 {
 112   token newtoken;
 113 
 114   newtoken.lex = lv;
 115   newtoken.sem.p = p;
 116 
 117   return newtoken;
 118 }

/* [<][>][^][v][top][bottom][index][help] */