编译原理上机报告(6)

2019-08-03 11:33

}

}

value = 0.0; FunPtr = null; // FuncPtr = null;

Token(Token_Type a, String b, double c, Method d) { } /*

* public static void main(String[] args) { Token mytoken; mytoken = new * Token(Token_Type.NONTOKEN,\ * System.out.println(mytoken.type); System.out.println(mytoken.lexeme); * System.out.println(mytoken.value); // //the result is //NONTOKEN //sfk * //34.0 * * } */

type = a;

lexeme = new StringBuffer(b); value = c; FunPtr = d;

3. mytokentab中的代码

package analyser;

public class mytokentab {

Token TokenTab[] = new Token[18]; // 切记类中要进行初始化必须在函数中 mytokentab() throws Exception

// unhandled exception type NoSuchMethodException // 很重要的 {

TokenTab[0] = new Token(Token_Type.CONST_ID, \TokenTab[1] = new Token(Token_Type.CONST_ID, \TokenTab[2] = new Token(Token_Type.T, \

TokenTab[3] = new Token(Token_Type.FUNC, \

.getMethod(\.getMethod(\

TokenTab[4] = new Token(Token_Type.FUNC, \

}

}

TokenTab[5] = new Token(Token_Type.FUNC, \

.getMethod(\.getMethod(\.getMethod(\.getMethod(\

TokenTab[6] = new Token(Token_Type.FUNC, \TokenTab[7] = new Token(Token_Type.FUNC, \TokenTab[8] = new Token(Token_Type.FUNC, \// parameter types

TokenTab[9] = new Token(Token_Type.ORIGIN, \TokenTab[10] = new Token(Token_Type.SCALE, \TokenTab[11] = new Token(Token_Type.ROT, \TokenTab[12] = new Token(Token_Type.IS, \TokenTab[13] = new Token(Token_Type.FOR, \TokenTab[14] = new Token(Token_Type.FROM, \TokenTab[15] = new Token(Token_Type.TO, \TokenTab[16] = new Token(Token_Type.STEP, \TokenTab[17] = new Token(Token_Type.DRAW, \

4. scanner2中的代码

package analyser;

//import java.awt.List; import java.io.*; import java.lang.*;

//import java.lang.Character; //import java.awt.*;

public class scanner2 {

static final int TOKEN_LEN = 100; // = 100;

// static int LineNo; public int LineNo; // we make it visible.

// 如此这般,不用unsigned int StringBuffer TokenBuffer;

FileReader fr; PushbackReader pr; // long filePoint;F // long fileLength;

static mytokentab tokentab; // 需要初始化,必须的 // ???不初始化没? public scanner2()

// in order to make it visible,we set it public. { }

public int InitScanner(String filename) // in order to make it visible,we set it public. { }

// TOKEN_LEN = 100;

TokenBuffer = new StringBuffer(\// 我用空串进行初始化 // 不能用空串进行初始化 try {

fr = new FileReader(filename); pr = new PushbackReader(fr); LineNo = 1; try { }

tokentab = new mytokentab(); System.out.println(e.toString()); } catch (Exception e) {

} catch (IOException E) { }

// 用空串进行初始化 return 0;

System.out.println(E.toString()); return 1;

// java无析构函数

public int CloseScanner() throws IOException // in order to make it visible,we set is public. { }

int GetChar() throws IOException // 该函数我们返回一个整数

// 千万不要忘记大小写转换的问题,否则不会匹配 { }

int toupper(int ch) { }

void BackChar(char Char) throws IOException { }

/* if(Char != EOF) */ if (((int) Char) != -1) /*

* else{ System.out.println(\le!\ */

pr.unread(Char); // ????pr.unread((int)Char); if (ch >= 'a' && ch <= 'z') { } return ch;

ch = ch - 32; int Char; Char = pr.read(); /*

* if(Char == -1) System.out.println(\ */

Char = toupper(Char); return Char; if ((pr.read()) != -1) { } return 0;

// System.out.println(\pr.close();

void AddCharTokenString(char Char) { }

void EmptyTokenString() // 清空记号缓冲区 {

int length = TokenBuffer.length(); if (length > 0)

// TokenBuffer.delete(0, length-1); TokenBuffer = null;

// System.out.print(\// System.out.println((int)Char); // 貌似TokenBuffer = null有点严重了~~ // 故需要重新new一个 if (TokenBuffer == null)

TokenBuffer = new StringBuffer(\int TokenLength = TokenBuffer.length(); if (TokenLength + 1 >= 100)

return;

// 在此对字符串长度进行了限制。 // ??? else

TokenBuffer.append(Char); // 我们进行如此追加 /*

* if(TokenBuffer != null){ System.out.print(TokenBuffer.toString()); * System.out.println(\ */

// ???

// TokenBuffer. .replace(0, TOKEN_LEN-1, \// 必须进行彻底地清理 /*

* if(TokenBuffer.length()>0)

* TokenBuffer.delete(0,TokenBuffer.length()-1); */

// 清空字符缓冲区: /* * *

* StringBuffer sb=new StringBuffer(\ *

* sb.delete(0,sb.length-1);或者:sb.replace(0,sb.length-1,\


编译原理上机报告(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:化工仪表实验指导书3[1].0

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: