}
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();