📄 firstpass.cs
字号:
this.getNextToken();
//跳过整个方法部分
while (!this.matchToken(";"))
{
this.getNextToken();
}
//抛出
throw new ComException(theError.getRow(), theError.getColumn(), 7);
}
}
catch (ComException ce)
{ //假如错误队列
this.errorList.Add(ce.getMessage());
return null;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
//项部分 下
TreeNode item_part()
{
try
{
//生成一个项节点
TreeNode the_item = new TreeNode(19);
//一个因子节点
TreeNode the_atom = this.atom_part();
//作为 项 的孩子
the_item.addChildren(the_atom);
while (this.getToken().getSbl() == 5)
{
//二级运算符 作为 项 的孩子
the_item.addChildren(this.getToken());
this.getNextToken();
//一个因子节点
TreeNode the_atom2 = this.atom_part();
//作为 项 的孩子
the_item.addChildren(the_atom2);
}
//到了下一个
return the_item;
}
catch (ComException ce)
{ //假如错误队列
this.errorList.Add(ce.getMessage());
return null;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
//表达式部分 下
TreeNode expression_part()
{
try
{
//生成一个表达式节点
TreeNode the_expression = new TreeNode(18);
//取负值
if (this.matchToken("-"))
{
//作为表达式的孩子
the_expression.addChildren(this.getToken());
this.getNextToken();
//一个项节点
TreeNode the_item = this.item_part();
//作为表达式的孩子
the_expression.addChildren(the_item);
while (this.getToken().getSbl() == 4)
{
//一级运算符 作为 表达式 的孩子
the_expression.addChildren(this.getToken());
this.getNextToken();
//一个项节点
TreeNode the_item2 = this.item_part();
//作为表达式的孩子
the_expression.addChildren(the_item2);
}
//到了下一个
return the_expression;
}
//标识符 或 方法调用式 或 数 或 表达式
else if (this.getToken().isIdentifier() || this.getToken().getNumType ()> 0 || this.matchToken("("))
{
//一个项节点
TreeNode the_item = this.item_part();
//作为表达式的孩子
the_expression.addChildren(the_item);
while (this.getToken().getSbl() == 4)
{
//一级运算符 作为 表达式 的孩子
the_expression.addChildren(this.getToken());
this.getNextToken();
//一个项节点
TreeNode the_item2 = this.item_part();
//作为表达式的孩子
the_expression.addChildren(the_item2);
}
//到了下一个
return the_expression;
}
//报错
else
{ //记录错误
Token theError = this.getToken();
this.getNextToken();
// 跳过一个语句
while (!this.matchToken(";"))
{
this.getNextToken();
}
//抛出
throw new ComException(theError.getRow(), theError.getColumn(), 7);
}
}
catch (ComException ce)
{ //假如错误队列
this.errorList.Add(ce.getMessage());
return null;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
//方法体内容部分 分下 或 }下
TreeNode funct_in_cont_part()
{
try
{ //方法体内容节点
TreeNode the_funct_in_cont= new TreeNode(14);
//变量声明
//int int[]
if (this.matchToken("int"))
{
this.getNextToken();
//int[]
if (this.matchToken("["))
{
this.getNextToken();
if (this.matchToken("]"))
{
this.getNextToken();
//生成一个数组声明节点
TreeNode the_array_decl = new TreeNode(5);
//作为方法体内容的孩子
the_funct_in_cont.addChildren(the_array_decl);
//将int token作为数组声明的孩子
the_array_decl.addChildren(new Token("int", true, 0, 0));
//生成一个数组定义节点
//进入数组定义部分
TreeNode the_array_def = this.array_def_part("int");
//数组定义作为数组声明的孩子
the_array_decl.addChildren(the_array_def);
this.getNextToken();
//匹配分号
if (this.matchToken(";"))
{
this.getNextToken();
return the_funct_in_cont;
}
else
{
//记录错误
Token theError = this.getToken();
this.getNextToken();
//跳到 ; 以后
while (!this.matchToken(";")) { this.getNextToken(); }
this.getNextToken();
throw new ComException(theError.getRow(), theError.getColumn(), 2);
}
}
else
{ //记录错误
Token theError = this.getToken();
this.getNextToken();
//跳到 ; 以后
while (!this.matchToken(";")) { this.getNextToken(); }
this.getNextToken();
throw new ComException(theError.getRow(), theError.getColumn(), 3);
}
}//int
else
{
//生成一个变量声明节点
TreeNode the_var_decl = new TreeNode(7);
//作为方法体内容的孩子
the_funct_in_cont.addChildren(the_var_decl);
//将int token作为变量声明的孩子
the_var_decl.addChildren(new Token("int", true, 0, 0));
//生成一个变量定义节点
TreeNode the_var_def = this.var_def_part();
//变量定义作为变量声明的孩子
the_var_decl.addChildren(the_var_def);
//已经到下一个单词了
while (this.matchToken(","))
{
this.getNextToken();
//生成一个变量定义节点
TreeNode the_var_def2 = this.var_def_part();
//变量定义作为变量声明的孩子
the_var_decl.addChildren(the_var_def2);
}
//匹配分号
if (this.matchToken(";"))
{
this.getNextToken();
return the_funct_in_cont;
}
else
{
//记录错误
Token theError = this.getToken();
this.getNextToken();
//跳到 ; 以后
while (!this.matchToken(";")) { this.getNextToken(); }
this.getNextToken();
throw new ComException(theError.getRow(), theError.getColumn(), 2);
}
}
}
//real real[]
else if (this.matchToken("real"))
{
this.getNextToken();
//real[]
if (this.matchToken("["))
{
this.getNextToken();
if (this.matchToken("]"))
{
this.getNextToken();
//生成一个数组声明节点
TreeNode the_array_decl = new TreeNode(5);
//作为方法体内容的孩子
the_funct_in_cont.addChildren(the_array_decl);
//将real token作为数组声明的孩子
the_array_decl.addChildren(new Token("real", true, 0, 0));
//生成一个数组定义节点
//进入数组定义部分
TreeNode the_array_def = this.array_def_part("real");
//数组定义作为数组声明的孩子
the_array_decl.addChildren(the_array_def);
this.getNextToken();
//匹配分号
if (this.matchToken(";"))
{
this.getNextToken();
return the_funct_in_cont;
}
else
{
//记录错误
Token theError = this.getToken();
this.getNextToken();
//跳到 ; 以后
while (!this.matchToken(";")) { this.getNextToken(); }
this.getNextToken();
throw new ComException(theError.getRow(), theError.getColumn(), 2);
}
}
else
{ //记录错误
Token theError = this.getToken();
this.getNextToken();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -