EE308-Lab1_2
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907?spm=1001.2014.3001.6377 |
| The Aim of This Assignment | <Extract keywords of different levels from the C or C++ code files> |
| MU STU ID and FZU STU ID | <20124279_832001119> |
1.the PSP of this work
| Program design process | What I do | ESTIMATE TIME(MIN) |
|---|---|---|
| Planning | Understand the requirements of the question, roughly construct the idea | 20 |
| design | Write down the general idea,draw a logical diagram | 20 |
| Write the code | Import different data for detection | 120 |
| Test | Import different data for detection | 30 |
| Improve my code | Summarize and improve the above tests | 30 |
| Wring Report | Wring Report | 60 |
After getting the problem, I solve the problem of general thinking, and process
- First of all, I think how to let program read c files
- The input c language file into an array form
- By looking up the data that through the positive expression can more easily calculate the required value, get the result(a Regular Expression is a pattern of text that includes both normal characters (for example, letters between A and z) and special characters (called "metacharacters"))
code
https://github.com/pikaquququ/lab1-2/blob/main/lab1-2
Test_code
1. #include <stdio.h>
2. int main(){
3. int i=1;
4. double j=0;
5. long f;
6. switch(i){
7. case 0:
8. break;
9. case 1:
10. break;
11. case 2:
12. break;
13. default:
14. break;
15. }
16. switch(i){
17. case 0:
18. break;
19. case 1:
20. break;
21. default:
22. break;
23. }
24. if(i<0){
25. if(i<-1){}
26. else{}
27. }
28. else if(i>0){
29. if (i>2){}
30. else if (i==2) {}
31. else if (i>1) {}
32. else {}
33. }
34. else{
35. if(j!=0){}
36. else{}
37. }
38. return 0;
39. }
Code writing process
Overall logic diagram

Reads the specified code file
public static void main(String[] args) throws IOException {
//read the test file
FileReader file = null;
try {
file = new FileReader("C:\\Users\\Desktop\\lab1-2.txt");
} catch (Exception e) {
e.getStackTrace();
}
BufferedReader input = new BufferedReader(file);
String lineString = "";
String tempString = input.readLine();
while(tempString!=null) {
lineString+=tempString;
tempString = input.readLine();
}
solution1(lineString);
solution2(lineString);
solution3_4(lineString);
}
Import c language keywords,And convert it into an array
c language keyword table(ANSI C standard C language has 32 keywords)
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";//all keywords
Calculate leve1

int num = 0;
for(int i = 0; i < keywords.length; i++) {
String regExpress = "[^a-zA-Z_]"+keywords[i]+"[^a-zA-Z_]";
Pattern pattern = Pattern.compile(regExpress);
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
num++;
}
}
System.out.println("The number of keywords is "+num+".");
System.out.println();
}
public static void solution2(String input) {
int num_switch = 0;
String regExpress = "[^a-zA-Z_]"+"switch"+"[^a-zA-Z_]";
Pattern pattern1 = Pattern.compile(regExpress);
Matcher matcher1 = pattern1.matcher(input);
while(matcher1.find()) {
num_switch++;
}
System.out.println("The number of 'switch' is "+num_switch+".");
Calculate the number of switches and cases

int num_case = 0;
int num = 0;
String regExpress2 = "switch.*?}";
Pattern pattern2 = Pattern.compile(regExpress2);
Matcher matcher2 = pattern2.matcher(input);
while(matcher2.find()) {
String regExpress3 = "[^a-zA-Z_]"+"case"+"[^a-zA-Z_]";
String tempText=matcher2.toString();
Pattern pattern3 = Pattern.compile(regExpress3);
Matcher matcher3 = pattern3.matcher(tempText);
while(matcher3.find()) {
++num_case;
}
num++;
System.out.println("The number of 'case' in switch "+ num +" is "+num_case+".");
num_case = 0;
}
System.out.println();
}
Calculate the number of if-else and if-elseif-else
public static void solution3_4(String input){
Stack<String> s = new Stack<String>();
int num_if_else = 0;
int num_if_elseif_else = 0;
String regExpress = "else *if|else|if";
Pattern pattern = Pattern.compile(regExpress);
Matcher matcher = pattern.matcher(input);
while(matcher.find()) {
String sub=input.substring(matcher.start(),matcher.end());
if(sub.equals("if")||sub.equals("else if")){
s.push(sub);
}else {
//s.pop() is 'if'
if(s.pop().equals("if")) {
num_if_else++;
}
//s.pop() is 'else if'
else{
num_if_elseif_else++;
//Keep popping the top of the stack until the top is 'if'
while(s.peek().equals("else if")) {
s.pop();
}
s.pop();
}
}
}
System.out.println("The number of 'if-else' is "+num_if_else+".");
System.out.println("The number of 'if-elseif-else' is "+num_if_elseif_else+".");
}
}
The results

summary
The result are all the correct with the reference ,Using regular expressions can simplify the code as much as possible, and in terms of code optimization, I use the Vector class to replace the previous string, which can save space.Because I have not used Java programming much, so I am not very skilled, took a long time, but at the same time got a lot of improvement
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
关于AI开发方法论-以文档为索引的高质量协作开发:让一次现象描述精准命中几个代码块
对AI的编码规范进行约束
YOLO26算法车道线检测+训练好的模型+360张数据集+pyqt可视化界面.zip
附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[未获取()] 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 55 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9512** mAP50-95 | 0.6746 Precision | 0.8796 Recall | 0.8825 train/box_loss | 0.8608 train/cls_loss | 0.7232 val/box_loss | 0.9955 val/cls_loss | 0.5511 【训练过程分析】 这轮训练我经历了从初始到稳定的曲折过程。前 20 个epoch,loss 曲线呈现了陡峭的下降趋势,mAP50 指标从 0.8 开始逐步攀升,仿佛在寻找一个合适的平衡点。然而,从第 21 个epoch 开始,mAP50 的提升速率显著放缓,整体曲线显得有些曲折,有时甚至停滞不前,让我一度以为训练出现了问题。直到第 35 个epoch,loss 开始逐渐趋于平稳,这标志着模型已经找到了一个较好的收敛区间。到了最后的 20 个 epoch,尽管 mAP50 依旧在稳步上升,但提升幅度已经不大,这意味着模型已经接近其性能天花板。 在这个过程中,我重点关注了 box_loss 和 cls_loss 的变化。初期阶段,box_loss 快速下降,从 0.9 逐渐降至 0.86,而 cls_loss 则从 0.75 逐步下降至... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。
syslog_test.py
syslog_test.py
Simulink “双碳”背景下汽车减少碳排放建模与仿真
内容概要:本文围绕“双碳”战略背景,系统阐述了基于Simulink的汽车碳排放建模与仿真技术,重点引入模糊PID控制优化动力系统性能,以实现节能减排目标。文档整合了多个Matlab/Simulink科研仿真案例,涵盖无刷直流电机(BLDC)控制、三相PWM整流器、电池管理系统、路径规划、信号处理、智能优化算法及图像处理等领域,全面展示Matlab在智能控制与绿色能源系统中的应用价值。同时强调科研应兼具严谨逻辑、创新思维与工具赋能,并提供完整的仿真资源链接与学习路径支持实践落地。; 适合人群:具备Matlab/Simulink基础,从事自动化、电气工程、车辆工程、控制科学、电力电子及智能制造等相关领域的科研人员或高年级本科生、研究生;适用于开展节能减排、新能源系统优化、智能控制算法研究等课题的研究者。; 使用场景及目标:①学习在Simulink中构建汽车能耗与排放仿真模型并应用模糊PID进行动态优化;②掌握BLDC、PWM整流器等关键部件的建模与控制策略设计;③借鉴丰富案例提升科研效率,拓展在智能控制、路径规划、信号处理等方向的应用能力;④通过提供的网盘资源获取完整代码与资料,支撑论文写作与项目开发。; 阅读建议:建议按照资源目录顺序系统学习,结合百度网盘提供的Matlab/Simulink代码动手实践,重点关注控制策略的设计、仿真结果的分析与优化过程,同时注重培养科研思维与工程实际问题的结合能力。


