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. 【算法之美】你可能想不到的归并排序的神奇应用 — leetcode 327. Count of Range Sum

    又是一道有意思的题目,Count of Range Sum.(PS:leetcode 我已经做了 190 道,欢迎围观全部题解 https://github.com/hanzichi/leetcode ...

  2. infer.net 入门2 用一个侦探故事来讲解,通俗易懂

    The results look OK, but how do you know that you aren’t missing something. Would a more sophisticat ...

  3. gravity、layout_gravity及orientation

    gravity.layout_gravity及orientation 最近在弄一个简单的界面:横向,添加一张准备好的背景图,在界面右边居中放置一个按钮.实现过程中发现对布局的主要属性没有想象中地那么熟 ...

  4. 一起来学node.js吧 node school简介

    node.js这几年火爆的简直丧心病狂,去lagou.com查查node.js的职位,那叫一个多. 要说火爆到什么程度,竟然有一个网站专门去教大家学习node.js, Node School. 进去逛 ...

  5. Unix philosophy

    拿来跟python之禅对比一下 每个程序只做一件事,但做到极致 用程序之间的相互协作来解决复杂问题 每个程序都采用文本作为输入和输出,这会使程序更易于使用 参阅:维基百科 The Zen of Pyt ...

  6. 浅谈SEO翻倍提升网站流量

    本文是在简单了解并且熟悉SEO技术的基础上加上自己的总结归纳,对于SEO还是一个长期的工程不是一天就能一下优化排名第一.下面就是我对SEO的一些见解: 一.关键字选择 内容相关 搜索次数多,竞争小 主 ...

  7. 如何通过SecureCRTPortable.exe 软件远程连接某个计算机(或者虚拟机)中的某个数据库

    1)双击SecureCRTPortable.exe - 快捷方式,打开软件; 2)"文件"--->"快速连接"-->弹出对话框: 2.1)输入主机名 ...

  8. iOS开发小技巧-修改SliderBar指针的样式(牢记这个方法,只能通过代码来修改)

    代码: // 修改进度条的指针图片 [self.progressSlider setThumbImage:[UIImage imageNamed:@"player_slider_playba ...

  9. xml解析工具-jdom

    前言:近期接触SSH框架的时候,经常得配置一下xml文件:今天闲来没事就挖挖xml解析的原理供大伙儿分享.本文主要通过一个简单的例子解析一个xml文件.明白其中缘由之后,大家想定义自己的xml也绝非难 ...

  10. Xcode 修改工程名以及注意事项

    1.先把整个工程文件夹名改为新的工程名. 2.打开工程,单击,输入新的工程名,会出现,点击确定. 3.回到工程界面,在中选择 Manage Schemes,然后再弹出的对话框,把工程名改为新的名字. ...