⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firstpass.cs

📁 c--解释器
💻 CS
📖 第 1 页 / 共 5 页
字号:
                            //跳到 ; 以后
                            while (!this.matchToken(";")) { this.getNextToken(); }

                            this.getNextToken();
                            throw new ComException(theError.getRow(), theError.getColumn(), 3);

                        }



                    }//real
                    else
                    {
                        //生成一个变量声明节点
                        TreeNode the_var_decl = new TreeNode(7);
                        //作为方法体内容的孩子
                        the_funct_in_cont.addChildren(the_var_decl);

                        //将real token作为变量声明的孩子
                        the_var_decl.addChildren(new Token("real", 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);

                        }

                    }
                }
                //语句
                //赋值语句 或 方法调用语句
                else if (this.getToken().isIdentifier()) 
                {
                    //记录标识符
                    Token the_identifier = this.getToken();
                    
                    this.getNextToken();
                   
                    //方法调用语句
                    if(this.matchToken("("))
                    {
                        //一个方法调用语句的节点 15
                        TreeNode the_funct_call = this.funct_call_part(the_identifier);
                        
                        //作为方法体内容的孩子
                        the_funct_in_cont.addChildren(the_funct_call);

                        //匹配分号
                        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 if (this.matchToken("[")) 
                    {
                        //一个数组元素赋值语句节点
                        TreeNode the_array_elem_give = new TreeNode(17);
                        //作为方法体内容的孩子
                        the_funct_in_cont.addChildren(the_array_elem_give);

                        //一个数组元素节点
                        TreeNode the_array_elem = this.array_elem_part(the_identifier);
                        
                        //数组元素为 数组元素赋值语句 的孩子
                        the_array_elem_give.addChildren(the_array_elem);

                                //匹配 赋值符号
                                if (this.getToken().getSbl() == 3)
                                {
                                    //作为 数组元素赋值语句 的孩子
                                    the_array_elem_give.addChildren(this.getToken());

                                    this.getNextToken();

                                    //进入表达式部分
                                    //一个表达式节点
                                    TreeNode the_expression =this.expression_part();
                                    //表达式 作为 数组元素赋值 的孩子
                                    the_array_elem_give.addChildren(the_expression);

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

                                }
                    }
                    //变量赋值语句  
                   
                    else if (this.getToken().getSbl() == 3)
                    {
                      
                        
                        //一个变量赋值语句节点
                        TreeNode the_var_give = new TreeNode(22);
                        //作为 方法体内容 的孩子
                        the_funct_in_cont.addChildren(the_var_give);

                        //标识符 作为 变量赋值语句的孩子
                        the_var_give.addChildren(the_identifier);

                       //赋值符号 作为 变量赋值语句 的孩子
                        the_var_give.addChildren(this.getToken());

                        this.getNextToken();

                        //进入表达式部分
                        TreeNode the_expression = this.expression_part();
                        //表达式 作为 变量赋值语句 的孩子
                        the_var_give.addChildren(the_expression);

                        if (this.matchToken(";"))
                        {
                            this.getNextToken();

                            return the_funct_in_cont;

                        }
                        else
                        {
                            //记录错误
                            Token theError = this.getToken();

                            //跳过错误单词
                            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(), 7);
                    }
                }
                //条件语句
                else if (this.matchToken("if")) 
                {
                    // 一个条件语句节节点
                    TreeNode the_condition = new TreeNode(23);

                    this.getNextToken();

                    if(this.matchToken("("))
                    {
                        getNextToken();
                        //一个条件节点
                        TreeNode the_condition_condi = this.condition_condi_part();
                        //作为 条件语句的孩子
                        the_condition.addChildren(the_condition_condi);

                        if(this.matchToken(")"))
                        {
                            this.getNextToken();

                            if (this.matchToken("{")) 
                            {
                                 //一个方法体节点
                                TreeNode the_function_in_if = this.function_in_part();
                                //作为条件语句的孩子
                                the_condition.addChildren(the_function_in_if);

                                //有else部分
                                if (this.matchToken("else")) 
                                {
                                    this.getNextToken();

                                    if (this.matchToken("{")) 
                                    {
                                        //一个方法体节点
                                        TreeNode the_function_in_else = this.function_in_part();
                                        //作为 条件语句的孩子
                                        the_condition.addChildren(the_function_in_else);

                                        //条件语句 作为 方法体内容 的孩子
                                        the_funct_in_cont.addChildren(the_condition);

                                        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(), 7);
                                    }
                                } 
                                //没有else部分
                                else 
                                {   //条件语句 作为 方法体内容的孩子
                                    the_funct_in_cont.addChildren(the_condition);
                                    
                                    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(), 7);
                            }
                        
                        }
                        else
                        {
                            // “)”  错误
                            //记录错误
                            Token theError = this.getToken();

                            //跳到 } 以后
                            this.getNextToken();
                            while (!this.matchToken("}"))
                            {
                                this.getNextToken();
                            }
                            this.getNextToken();

                            throw new ComException(theError.getRow(), theError.getColumn(), 9);
                        }
                    }
                    else
                    {// " ( "错误
                        //记录错误
                        Token theError = this.getToken();

                        //跳到分号以后
                        this.getNextToken();
                        while (!this.matchToken("}"))
                        {
                            this.getNextToken();
                        }
                        this.getNextToken();

                        throw new ComException(theError.getRow(), theError.getColumn(), 9);

                    }

                }
                //循环语句
                else if (this.matchToken("while")) 
                {
                    //一个循环语句节点
                    TreeNode the_loop = new TreeNode(25);

                    this.getNextToken();

                    if(this.matchToken("("))
                    {
                        this.getNextToken();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -