⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slpscanner.java

📁 compiler constructor using the recursive deceiding way
💻 JAVA
字号:
/*****************************************************************//*                                                               *//* This is a hand-written lexical analyser for SLP written in    *//* Java. It implements the SLPTokeniserConstants interface which *//* was generated by the JavaCC lexical analyser. This would not  *//* normally be done, but it ensures compatibility between the    *//* two different lexical analysers.                              *//*                                                               *//*****************************************************************/import java.io.*;public class SLPScanner implements SLPTokeniserConstants {/* This implementsInputStream input_stream; /* This is where the input comes from */char c; /* This gives the next character in the input stream */int line = 1; /* The current line number in the input */int i;public SLPScanner (InputStream stream) {  input_stream = stream;  try {    i = input_stream.read();    c = (char)i;  }  catch (IOException e) {};}/* getNextToken returns the next token *//*    recognised in the input stream   */public Token getNextToken() {  String s = new String("");  Token t = new Token();  try {    /* Skip white space */    while ((c == ' ') || (c== '\t') || (c == '\n') || (c == '\r') || (c == '\f')) {      if (c == '\n')         line++;      i = input_stream.read();      c = (char)i;    }     t.beginLine = line;    t.endLine = line;    /* Check for end of input */    if (i == -1) {      t.kind = EOF;      return t;    }    if (Character.isLetter(c)) {       /* identifier or reserved word encountered */      do {        s = s + String.valueOf(c);        c = (char)input_stream.read();      } while (Character.isLetter(c));      t.image = s;      if (s.equals("print"))         t.kind = PRINT;      else         t.kind = ID;      return t;    }        else if (Character.isDigit(c)) {      /* number encountered */      do {        s = s + String.valueOf(c);        i = input_stream.read();        c = (char)i;      } while (Character.isDigit(c));      t.image = s;      t.kind = NUM;      return t;      }    else {      switch(c) {        case ',': t.kind = COMMA;                  t.image = ",";                  i = input_stream.read();                  c = (char)i;                  return t;         case ';': t.kind = SEMIC;                  t.image = ";";                  i = input_stream.read();                  c = (char)i;                  return t;         case '(': t.kind = LBR;                  t.image = "(";                  i = input_stream.read();                  c = (char)i;                  return t;         case ')': t.kind = RBR;                  t.image = ")";                  i = input_stream.read();                  c = (char)i;                  return t;         case ':': i = input_stream.read();                  c = (char)i;                  if (c == '=') {                    t.kind = ASSIGN;                    t.image = ":=";                    i = input_stream.read();                    c = (char)i;                  }                  else {                    t.kind = OTHER;                    t.image = "=";                  }                  return t;         case '+': t.kind = PLUS_SIGN;                  t.image = "+";                  i = input_stream.read();                  c = (char)i;                  return t;         case '-': t.kind = MINUS_SIGN;                  t.image = "-";                  i = input_stream.read();                  c = (char)i;                  return t;         case '*': t.kind = MULT_SIGN;                  t.image = "*";                  i = input_stream.read();                  c = (char)i;                  return t;         case '/': t.kind = DIV_SIGN;                  t.image = "/";                  i = input_stream.read();                  c = (char)i;                  return t;         default:  t.kind = OTHER;                  t.image = String.valueOf(c);                  i = input_stream.read();                  c = (char)i;                  return t;       }    }  }  catch (IOException e) {    t.kind = OTHER;    t.image = String.valueOf(c);    return t;   }}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -