Contents    Page-10    Prev    Next    Page+10    Index   

Example Lexer


/* The ``big switch'': guess token type,
   call a routine to parse it */
TOKEN gettoken()
  {   TOKEN tok;  int c, cclass;
      tok = talloc();   /* allocate new token */
      skipblanks();     /* and comments */
      if ((c = peekchar()) != EOF)
          {
            cclass = CHARCLASS[c];
            if (cclass == ALPHA)
              identifier(tok);
            else if (cclass == NUMERIC)
                    number(tok);
                    else if (c == '\'')
                            getstring(tok);
                            else special(tok);
          }
          else EOFFLG = 1;
     return(tok);
  }