编译原理上机报告(9)

2019-08-03 11:33

}

parameter = new Double(0); //here...we can use it as a pointer

//and the set is 0 at the beginning. //token = new Token();

//here are some private functions. private void enter(String x) { }

private void back(String x) { }

private void call_match(String x)

//here we change to String,not Token_Type,because^ //we may want to print the '(' { }

//树的痕迹??

//其中只调用了一个函数,那便是PrintSyntaxTree private void Tree_trace(ExprNode x) { }

protected void FetchToken() throws Exception { }

protected void MatchToken(Token_Type The_Token)throws Exception

token = myscanner.GetToken(); //it may throw exception

if(token.type == Token_Type.ERRTOKEN)

SyntaxError(1); PrintSyntaxTree(x,1);

System.out.println(\//?????

//System.out.println(\System.out.println(\System.out.println(\return;

{ }

private void SyntaxError(int case_of) { }

private void ErrMsg(int no,String message,StringBuffer string) //we change unsigned int to int. { }

//------------------------先序遍历并打印表达式的语法树----------- public void PrintSyntaxTree(ExprNode root,int indent) //here^^

//we print our grammer tree. {

int temp;

for(temp = 1;temp <= indent;temp++) { }

switch(root.OpCode) {

case PLUS:System.out.println(\case MINUS:System.out.println(\case MUL:System.out.println(\case DIV:System.out.println(\case POWER:System.out.println(\

case FUNC:System.out.println(root.content.CaseFunc.MathFunPtr.getName());break; case CONST_ID:System.out.println(root.content.CaseConst);break;

System.out.print(\

//print the \\t,and its number is indent

System.out.printf(\return; switch(case_of) {

case 1: ErrMsg(myscanner.LineNo,\错误记号\case 2: ErrMsg(myscanner.LineNo,\不是预期记号\} return;

if(token.type != The_Token)

SyntaxError(2); FetchToken();

//it may throw exception

}

case T:System.out.println(\

default:System.out.println(\}

if(root.OpCode == Token_Type.CONST_ID||root.OpCode == Token_Type.T) { }

else if(root.OpCode == Token_Type.FUNC) { } else { }

PrintSyntaxTree(root.content.CaseOperator.Left,indent+1); PrintSyntaxTree(root.content.CaseOperator.Right,indent+1); PrintSyntaxTree(root.content.CaseFunc.child,indent+1); try{

System.out.println(\System.out.println(\System.out.println(\Method sp = parser.class.getMethod(\

sp.invoke(null, \

printTable(1, 10, 10, root.content.CaseFunc.MathFunPtr); }

catch(Exception e) { }

System.out.println(e.toString()); return;

//-------------------绘图语言解释器入口(与主程序的外部接口)--------- public void Parser(String SrcFilePtr)throws Exception {

enter(\

if((myscanner.InitScanner(SrcFilePtr))== 1) //take notice!here,InitScanner return int! //we can't use \{ }

FetchToken();

System.out.println(\return;

}

Program();

myscanner.CloseScanner(); back(\return;

//-------------------Program的递归子程序---------------------------- protected void Program()throws Exception { }

//-------------------Statement的递归子程序---------------------------- protected void Statement()throws Exception { }

//-------------------OriginStatement的递归子程序------------------------ protected void OriginStatement()throws Exception //the statement is: //ORIGIN IS (double,double) {

ExprNode tmp = new ExprNode(); enter(\

enter(\

//System.out.println(token.type); switch(token.type) {

case ORIGIN:OriginStatement();break; case SCALE:ScaleStatement();break; case ROT:RotStatement();break; case FOR:ForStatement();break; default:SyntaxError(2); }

back(\return;

enter(\

while(token.type != Token_Type.NONTOKEN) //if it's not nontoken,we go ahead. { }

back(\return;

Statement();

MatchToken(Token_Type.SEMICO);

}

//take notice !! //here is my adding!

MatchToken(Token_Type.ORIGIN);call_match(\

MatchToken(Token_Type.IS);call_match(\

MatchToken(Token_Type.L_BRACKET);call_match(\tmp = Expression();

MatchToken(Token_Type.COMMA);call_match(\tmp = Expression();

MatchToken(Token_Type.R_BRACKET);call_match(\back(\return;

//-------------------ScaleStatement的递归子程序------------------------- protected void ScaleStatement()throws Exception //the scalestatement is: //SCALE IS (double,double) {

ExprNode tmp = new ExprNode(); enter(\

MatchToken(Token_Type.SCALE);call_match(\

MatchToken(Token_Type.IS);call_match(\

MatchToken(Token_Type.L_BRACKET);call_match(\tmp = Expression();

MatchToken(Token_Type.COMMA);call_match(\tmp = Expression();


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

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

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

马上注册会员

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