1:  package compiler;
   2:   
   3:  /**
   4:   * 采用全局变量sym来存储符号码,并用全局变量id和num来传递语义值
   5:   *
   6:   * @author jiangnan
   7:   *
   8:   */
   9:  public class Symbol {
  10:   
  11:      //各类符号码
  12:      public static final int nul = 0;                  //NULL
  13:      public static final int ident = 1;               //标识符
  14:      public static final int plus = 2;                //加号+
  15:      public static final int minus = 3;              //减号-
  16:      public static final int mul = 4;                 //乘号*
  17:      public static final int div = 5;                  //除号/
  18:      public static final int oddsym = 6;           //odd
  19:      public static final int number = 7;           //数字
  20:      public static final int eql = 8;                  //等于号=(equal)
  21:      public static final int neq = 9;                 //不等于<>(not equal)
  22:      public static final int lss = 10;                 //小于<(less)
  23:      public static final int geq = 11;                 //大于等于>=(greater or equal)
  24:      public static final int gtr = 12;                //大于>(greater)
  25:      public static final int leq = 13;                //小于等于<=(less or equal)
  26:      public static final int lparen = 14;            //左括号(
  27:      public static final int rparen = 15;           //右括号 ) 
  28:      public static final int comma = 16;           //逗号,
  29:      public static final int semicolon = 17;       //分号;
  30:      public static final int peroid = 18;            //句号.
  31:      public static final int becomes = 19;         //赋值符号 :=
  32:      public static final int beginsym = 20;        //开始符号begin
  33:      public static final int endsym = 21;           //结束符号end
  34:      public static final int ifsym = 22;             //if
  35:      public static final int thensym = 23;         //then
  36:      public static final int whilesym = 24;        //while
  37:      public static final int writesym = 25;        //write
  38:      public static final int readsym = 26;         //read
  39:      public static final int dosym = 27;            //do
  40:      public static final int callsym = 28;          //call
  41:      public static final int constsym = 29;       //const
  42:      public static final int varsym = 30;           //var
  43:      public static final int procsym = 31;         //procedure
  44:      public static final int elsesym = 32;
  45:      public static final int repeatsym=33;
  46:      public static final int untilsym=34;
  47:      
  48:      //符号码的个数
  49:      public static final int symnum = 35;
  50:   
  51:      //设置保留字名字,按照字母顺序,便于折半查找
  52:      public static final String[] word = new String[]{
  53:          "begin","call" , "const"    , "do" ,
  54:          "else"  ,"end" ,"if"   , "odd", 
  55:          "procedure", "read","repeat","then",
  56:          "until" , "var", "while"    , "write" };
  57:      //保留字对应的符号值
  58:      public static final int[] wsym = new int[]{
  59:          beginsym, callsym, constsym, dosym,
  60:          elsesym, endsym, ifsym,oddsym, 
  61:          procsym,readsym,repeatsym, thensym,
  62:          untilsym ,varsym,whilesym, writesym};
  63:   
  64:      //符号码
  65:      public int symtype;
  66:      //标志符号名字;
  67:      public String id;
  68:      //数值的大小
  69:      public int num;
  70:   
  71:      /**
  72:       * 构造具有特定符号码的符号
  73:       *
  74:       * @param stype
  75:       */
  76:      public Symbol(int stype) {
  77:          symtype = stype;
  78:          id = "";
  79:          num = 0;
  80:      }
  81:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

PL/0编译器(java version) – Symbol.java的更多相关文章

  1. PL/0编译器(java version) - MainFrame.java

    1: /* 2: * To change this license header, choose License Headers in Project Properties. 3: * To chan ...

  2. PL/0编译器实践---后记

    花了几天时间,把清华版的<编译原理>一书中的PL/0编译器实践了一遍.颇有收获,记录如下: 理解代码的技巧,如何理解一份代码,比如这个程序,其逻辑相对于一般程序就比较复杂了,如何翻译,虚拟 ...

  3. PL/0编译器(java version)–Praser.java

    1: package compiler; 2:   3: import java.io.IOException; 4: import java.util.BitSet; 5:   6: /** 7: ...

  4. PL/0编译器(java version) – Scanner.java

    1: package compiler; 2:   3: import java.io.BufferedReader; 4: import java.io.FileNotFoundException; ...

  5. PL/0编译器(java version) – SymbolTable.java

    1: package compiler; 2: //竟然没有对符号表检查大小,会溢出的. 3:   4: import java.io.IOException; 5:   6: public clas ...

  6. PL/0编译器(java version)–PL0.java

    1: package compiler; 2:   3: import java.io.BufferedWriter; 4: import java.io.FileWriter; 5:   6: /* ...

  7. PL/0编译器(java version) - Interpreter.java

    1: package compiler; 2:   3: import java.io.BufferedReader; 4: import java.io.BufferedWriter; 5: imp ...

  8. PL/0编译器(java version) - Err.java

    1: package compiler; 2:   3: import java.io.BufferedWriter; 4:   5: public class Err { 6:   7: publi ...

  9. PL/0编译器(java version)–Pcode.java

    1: package compiler; 2:   3: /** 4: * //虚拟机指令 5: * 6: * @author jiangnan 7: * 8: */ 9: public class ...

随机推荐

  1. MySQL for mac使用记录

    一.登录 打开终端,输入/usr/local/mysql/bin/mysql -u root -p 初次进入mysql,密码为空.当出现mysql>提示符时,表示你已经进入mysql中.键入ex ...

  2. OS存储器管理(二)

    离散分配 分页(Paging),分段,段页式 一.分页   一个进程的物理地址可以是非连续的:   将物理内存分成固定大小的块,称为块(frame): 将逻辑内存分为同样大小的块,称为页(page): ...

  3. C语言之Sleep函数

    Sleep函数: 功 能: 执行挂起一段时间 用 法: unsigned sleep(unsigned seconds); 注意: 在VC中使用带上头文件#include <windows.h& ...

  4. Vmware player 12

    免费版的虚拟机Vmware,体积小.运行快速... 官方下载界面 下载地址: http://yunpan.cn/cm5smywVvqS8V  访问密码 35ac 官方下载:点击下载

  5. 转 -- linux IO子系统和文件系统读写流程

    我们含有分析的,是基于2.6.32及其后的内核. 我们在linux上总是要保存数据,数据要么保存在文件系统里(如ext3),要么就保存在裸设备里.我们在使用这些数据的时候都是通过文件这个抽象来访问的, ...

  6. 【BZOJ 4515】【SDOI 2016 Round1 Day1 T3】游戏

    考场上写了lct,可惜当时对标记永久化的理解并不是十分深刻,导致调一个错误的程序调了4h+,最后这道题爆0了QwQ 现在写了树链剖分,用标记永久化的线段树维护轻重链,对于$s\rightarrow l ...

  7. java中map<string,int>

    java中 Iterator it=wordsmap.entrySet().iterator(); while(it.hasNext()) { Map.Entry<String,Integer& ...

  8. IOS并发编程GCD

    iOS有三种多线程编程的技术 (一)NSThread  (二)Cocoa NSOperation (三)GCD(全称:Grand Central Dispatch) 这三种编程方式从上到下,抽象度层次 ...

  9. 状态压缩 HDU 3182

    t组数据 n个汉堡 e的能量 接下来的2行 val    n个 得到的权 cost  n个 花去的能量 接下来n行 每行一个q  q个数字 代表这类汉堡做好要的前提  每个汉堡只能用一次 #inclu ...

  10. hdu2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...