• 大小: 18KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-07-18
  • 语言: Java
  • 标签: 编译原理  

资源简介

编译原理课下作业,简易计算器的java实现,GCU 编译原理课下作业,简易计算器的java实现,GCU

资源截图

代码片段和文件信息

package experiment1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by haol on 2016/11/3.
 */
public class AnalyseStr {

        public static int i = 0;
        //isNumStr 记录是否遍历在数字串中,是的话则数字包括Zero和。并记录数字串的开头 否则 无
        //一旦便利到数字 则一直便利内部i++不跳出while循环,直到遇到非数字和第一个‘.‘
        public static boolean isNumStr = false;

        public List analyStr(String str) throws Exception {
                i = 0;
                isNumStr = false;
                str = str.trim();
                List tokens = new ArrayList();

                int begin = 0;

                while (i < str.length()) {
                        String thisStr = str.substring(i i + 1);
                        if (this.analyseIsNum(thisStr) ) {
                                if (!isNumStr) {
                                        begin = i;
                                }
                                isNumStr = true;

                                this.passNumStr(str);
                                //遍历到下一个非数字的位置
                                i++;
                                if (i + 1 < str.length() && str.substring(i i + 1).equals(“.“)) {
                                        tokens = this.analyseIAfterDot(tokens str begin);
                                } else {
                                        Token token = new Token(“5“ str.substring(begin i) str.substring(begin i) “int“);
                                        tokens.add(token);
                                        isNumStr = false;
                                }
                        } else if (thisStr.equals(“0“)) {
                                if (i+1                                        if(this.analyseIsNum(str.substring(i+1i+2)) || str.substring(i+1i+2).equals(“0“)){
                                                Token token = new Token(“e“ str.substring(i i+1) “ERROR“ “0出现的位置不正确“);
                                                tokens.add(token);
                                                i++;
                                                isNumStr = false;
                                        }else {
                                                tokens = this.analyseIsZero(tokens str);
                                        }
                                }else{
                                        Token token = new Token(“0“ str.substring(i i+1) str.substring(i i+1) “int“);
                                        tokens.add(token);
                                        i++;
                                        isNumStr = false;
                                }
                        } else {
                        /* 分析非数字并判断括号周围是否有误*/
                                tokens = this.analyseIsNotNum(tokens str);
                        }
                }
                return tokens;
        }

        public bool

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-09 20:27  experiment1\
     文件        9403  2016-11-17 20:30  experiment1\AnalyseStr.java
     文件        1291  2016-11-17 20:28  experiment1\Complie_1.java
     文件        1579  2018-02-27 17:20  experiment1\FormatOut.java
     文件         549  2016-11-04 23:19  experiment1\read.txt
     文件         773  2016-11-17 22:20  experiment1\ReadText.java
     文件        2257  2016-11-17 20:05  experiment1\Token.java
     目录           0  2017-01-09 20:27  experiment2\
     目录           0  2017-01-09 20:27  experiment2\analyse\
     文件        8417  2016-11-26 01:37  experiment2\analyse\GuideTranslate.java
     文件         627  2016-11-26 01:37  experiment2\analyse\OperateFAC.java
     文件        2179  2016-11-26 01:36  experiment2\analyse\SemanticStake.java
     文件        3182  2016-11-26 01:43  experiment2\Complie_2.java
     目录           0  2017-01-09 20:27  experiment2\define\
     文件        4141  2016-11-22 22:19  experiment2\define\CreateSLRTable.java
     文件         802  2016-11-23 13:11  experiment2\define\FourAddressCode.java
     文件        2384  2016-11-26 01:38  experiment2\define\Mathexpression.java
     目录           0  2017-01-09 20:27  experiment2\operate\
     文件        4457  2016-11-26 01:39  experiment2\operate\Calculate.java
     文件        1902  2016-11-26 01:39  experiment2\operate\GetColumn.java
     文件        1159  2016-11-26 01:40  experiment2\operate\OperateList.java
     文件         826  2016-11-26 01:42  experiment2\operate\QuerySLR.java
     目录           0  2017-01-09 20:27  experiment2\ready\
     文件        1198  2016-11-26 01:43  experiment2\ready\GetToken.java
     文件         684  2018-02-27 17:20  experiment2\ready\Logger.java
     文件         817  2016-11-19 23:59  experiment2\ready\OperateToken.java

评论

共有 条评论