EE308Lab1-2
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
| The Aim of This Assignment | Slove the problem of Lab1-2 |
| MU STU ID and FZU STU ID | 20123311 832002216 |
github address
https://github.com/HaooLi/EE308-LAB1-2
1.Give the PSP form for this work.
| Framework activities: | what I did | ESTIMATE TIME(MINUTE) |
|---|---|---|
| Plan | Understand the meaning of the problem, think of a rough solution process | 40 |
| design | Program the idea and write a rough outline | 150 |
| Code Review | Check for compliance with programming specifications and check for syntax errors | 25 |
| Test | Import different data for detection | 20 |
| Postmortem & Process Improvement Plan | Do an overall review to make sure the program works | 10 |
2.Description of problem-solving ideas. This is the process of how to think and how to find information after getting the title at the beginning.
- Find the method to read the c file
- Put all keyword lists into string groups
- Find out the key words one by one and compare them
3.Design and implementation process. The design includes how the code is organized and the flow chart of the key functions.
- Read the file and combine it as a string
- Put the keyword table into the array
- Match all keywords according to the regular expression and count them
- The cases of Switch, case, if-else, and if-elseif-else are solved respectively

4.Code description. Show the key code of the project and explain the idea.
- level 1:
String keywords="abstract、assert、boolean、break、byte、case、"
+ "catch、char、class、continue、default、do、double、else、"
+ "enum、extends、final、finally、float、for、if、implements、"
+ "import、int、interface、instanceof、long、native、new、"
+ "package、private、protected、public、return、short、static、"
+ "strictfp、super、switch、synchronized、this、throw、throws、"
+ "transient、try、void、volatile、while";
String []keyArr=keywords.split("、");
public static void findKey(String[] keyArr,String c){
int key_num = 0;
for(int i = 0; i<keyArr.length; i++) {
Pattern p=Pattern.compile("[^a-z]"+keyArr[i]+"[^a-z]");
Matcher matcher=p.matcher(c);
while(matcher.find()) {
key_num++;
}
}
System.out.println("key num is "+key_num);
}
level 2: find the switch and output the number of "case" corresponding to each group
public static void findSwitch(String c){
//check switch
Pattern p=Pattern.compile("switch");
Matcher matcher=p.matcher(c);
while(matcher.find()) {
switch_num++;
}
//find the number of case
p=Pattern.compile("switch.*?}");
matcher=p.matcher(c);
List case_num=new ArrayList();
while(matcher.find()) {
String tempText=matcher.toString();//get one switch section
Pattern temp_p=Pattern.compile("case");
Matcher temp_matcher=temp_p.matcher(tempText);
int temp_case_num=0;
while(temp_matcher.find()) {
temp_case_num++;
}
case_num.add(temp_case_num);
}
System.out.println("switch num is "+switch_num);
System.out.print("case num are ");
for(int i=0;i<case_num.size();i++) {
System.out.print(case_num.get(i)+" ");
}
System.out.println();
}
level 3 and 4: find else if and if-else if -else
public static void processElse(String c) {
Pattern p = Pattern.compile("else\\s*if|else|if");
Matcher matcher=p.matcher(c);
Stack<String> s = new Stack();
while(matcher.find()) {
String temp=c.substring(matcher.start(),matcher.end());
s.push(temp);
}
Stack<String> res = new Stack<String>();
boolean flag = false;
while (!s.isEmpty()) {
String temp = s.pop();
if (temp.equals("else")) {
res.push(temp);
} else if (temp.equals("else if")) {
res.push(temp);
} else {
while (res.peek().equals("else if")) {
res.pop();
// make a little notation that its from else if, not else
flag = true;
}
if (res.peek().equals("else")) {
res.pop();
}
//if it's elseif ,add to ifElseIfNum
if (flag) {
ifElseIfNum++;
flag = false;
} else {
ifElseNum++;
}
}
}
System.out.println("if-else num: " + ifElseNum);
System.out.println("if-elseif-else: " + ifElseIfNum);
}
5.Unit test screenshots and description.

6.Unit test coverage optimization and performance testing, performance optimization screenshots and descriptions.
In the process of adding all the keywords and counting the numbers, I chose to use RE and stack for the statistics. This greatly reduces the amount of code and is easy to understand.
7.Summarize this assignment.
Through this experiment, I understand that if a project wants to be completed quickly and better, first of all we need to make a preliminary plan, and we need to have a full understanding and analysis of the subject. Draw the flowchart of the program to facilitate us to complete the implementation of the code.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?.docx
技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?
省级科技管理部门在制定技术交易补贴政策时,通常优先支持哪类平台?.docx
科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元
水泥稳定碎石基层施工安全交底要点(含现场管控项).docx
水泥稳定碎石基层施工安全交底要点(含现场管控项)
普通职员月度工作总结知识笔记(结构+话术+案例).docx
普通职员月度工作总结知识笔记(结构+话术+案例)


