EE308 LAB1-2
LAB1-2
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
| The Aim of This Assignment | To achieve a program function, it can extract keywords of different levels from the C or C++ code files that are read in. |
| MU STU ID and FZU STU ID | 20123949_832002115 |
目录
- LAB1-2
- guithub link
- PSP table
- Problem solving ideas
- Design and implementation process
- The key code description
- Unit test
- Performance Optimization Analysis
- Summarize
guithub link
https://github.com/GTXGTA/EE308_LAB1_2
PSP table
| PSP | Personal Software Process tages | Estimated time/hour | Actual time/hour |
|---|---|---|---|
| Planning | plan | ||
| Estimate | Estimate how long the task will take | 0.5 | 0.75 |
| Development | exploitation | ||
| Analysis | Requirements analysis (including learning new technology) | 1.5 | 2 |
| Design Spec | Generating design documentation | 1 | 2 |
| Design Review | design review | 1 | 1 |
| Coding Standard | Code specification (appropriate specification for current development) | 1.5 | 2.5 |
| Design | detail design | 1.5 | 1 |
| Coding | absolute coding | 3 | 8 |
| Code Review | code review | 1 | 2 |
| Test | Test (self test, change code, commit changes) | 3 | 9 |
| Reporting | Reporting | 2.5 | 2 |
| Test Report | Test Report | 1 | 1 |
| Size Measurement | computational effort | 1.5 | 1.5 |
| Postmortem & Process Improvement Plan | Summarize afterwards | 1.5 | 2.5 |
| total | 20.5 | 35.25 |
Problem solving ideas
- File input
- To read in a code file, we first need to figure out how to read the contents of the file.
- I searched the Internet and learned about reading files.
- Cut the string
- When the file is read in, it is read in line, and the string needs to be cut into individual words to detect.
- So I should know which ones should be used as cut identifiers in c++/c files.
- Keyword detection
- I might need an array of constants as a dictionary for my later code to look up in that dictionary.
- On switch-case detection.
- I can use a counter to calculate.
- When a switch occurs, it means that the previous switch structure will not appear case again, case num is listed, and the counter is reset.
- I think the queue size should be the number of switch structures.
- On if-else and if-else if-else detection
- When I think about it, I think there's an if-else structure or an if-else if-else structure when it ends with an else.
- So I should use a stack to handle it.
Design and implementation process
The way I organize my code is around the Code_test class.

The key code description
class Code_test
- My Code_test class encapsulates the main function, cut function, keyword detection,if-else structure and if-else if-else structure with count and output functions.
class Code_test { public: Code_test(){} bool Divide(int &index); void T1(string divided_unit); void T2(int &index); void T_File(string filename); void Display(int level); private: string str_line,word; int Keyword_Count; ifstream Infile; ofstream OutFile; stack <int> if_else_Stack; queue <int> switch_Queue; bool Is_Previous_Else; int If_else_count; int If_elseif_else_count; int Switch_Count; };Divide function
bool Code_test::Divide(int &index) { if(str_line[index] == '"') { int j = index; for(index = index + 1; index < str_line.size(); index++) { if(str_line[index] == '"') return true; } index = j; return true; } if(str_line[index] == '/' && str_line[++index] == '*') { for(index = index + 1; index < str_line.size(); index++) { if(str_line[index] == '*' && str_line[++index] == '/') return true; } while(getline(Infile, str_line)) { for(index = 0; index < str_line.size(); index++) { if(str_line[index] == '*' && str_line[++index] == '/') return true; } } } if(str_line[index] == '(' || str_line[index] == ')') return true; else if(str_line[index] == '<' || str_line[index] == '>') return true; else if(str_line[index] == '&' || str_line[index] == '*') return true; else if(str_line[index] == '{' || str_line[index] == '}') return true; else if(str_line[index] == '\n'|| str_line[index] == '\0' || str_line[index] == '\t') return true; else if(str_line[index] == ' ' || str_line[index] == ',' || str_line[index] == ';' || str_line[index] == ':') return true; return false; }T1 function
void Code_test::T1(string divided_unit) { for(int i = 0; i < 32; i++) if(divided_unit == kKeyWordName[i]) Keyword_Count++; if(divided_unit == "switch" && Switch_Count) { switch_Queue.push(Switch_Count); Switch_Count = 0; } if(divided_unit == "case") Switch_Count++; if(divided_unit == "if") { if_else_Stack.push(-1); if_else_Stack.push(1); } if(divided_unit == "else") Is_Previous_Else = true; }T2 function
void Code_test::T2(int &index) { for(index; index < str_line.size(); index++) if (!(str_line[index] == ' ' || str_line[index] == '\t')) break; if(index == str_line.size()) { int flag = 0; while (getline(Infile, str_line)) { for(index = 0; index < str_line.size(); index++) { if (!(str_line[index] == ' ' || str_line[index] == '\t')) { flag = 1; break; } } if(flag) break; } } if(str_line[index] == 'i' && str_line[index+1] == 'f') { if_else_Stack.push(1); index++; Keyword_Count++; } else { int ifelse_stack_count_ = 0; while(if_else_Stack.top() > 0 && !if_else_Stack.empty()) { ifelse_stack_count_ += if_else_Stack.top(); if_else_Stack.pop(); } if(ifelse_stack_count_ > 1) If_elseif_else_count++; else if(ifelse_stack_count_ == 1) If_else_count++; } }
Unit test
Below are the unit test results for levels 1,2,3, and 4, respectively.
- Level 1 unit test results.

- Level 2 unit test results.

- Level 3 unit test results.

- Level 4 unit test results.

Performance Optimization Analysis
As you can see from the figure below, the functions that occupy more resources are Divide function,T1 function,T_File function.


Summarize
- Learning and Gain
- In this practice, I learned to master some usage methods of github and csdn, and consolidated my markdown related syntax, so that I am more skilled in using them.
- At the same time, I also practice the keyword detection of c++, for the programming, the if_else judgment, and the string cutting problem all let me benefit a lot.
- Difficulties encountered and solutions
- Very inexperienced with github
- I tried to learn the related use methods of github on the Internet, and spent time simply learning and understanding some basic use methods of github.
- Programming problems
- When writing the c++ keyword recognition program, I have a lot of doubts about the method of identifying keywords. In the case of searching information online and asking surrounding students, I basically understand the solution and ideas. At the same time, I encountered many errors when trying to write the code. After my careful elimination, I successfully solved the problems I encountered.
- Very inexperienced with github
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
【工业自动化】欧姆龙PLC产品线与编程软件应用:从选型架构到调试排错的全流程技术指南
内容概要:本文《欧姆龙PLC与编程软件完全手册》系统介绍了欧姆龙PLC的产品架构、软件体系、通信协议、选型策略及编程调试技巧。重点区分了两大技术平台:基于CX-Programmer的传统C系列(CP/CJ/CS)与基于Sysmac Studio的新一代Sysmac平台(NJ/NX/NY),强调二者在软件生态、寻址方式和通信架构上的根本差异。手册详细对比了各系列PLC的性能参数,并提供与西门子产品的功能对标,帮助用户快速定位。深入讲解了编程操作中的关键问题,如任务结构设计、间接寻址、FB封装陷阱、在线调试五件套等,特别指出“FB使能关闭时状态不初始化”等易出错点。最后汇总了选型路径与现场避坑清单,极具实战指导价值。; 适合人群:具备一定工业自动化基础,从事PLC编程、设备调试、系统集成的研发工程师和技术人员,尤其是从西门子平台转向欧姆龙或参与新项目选型的1-5年经验从业者。; 使用场景及目标:① 新项目选型时判断应选用C系列还是Sysmac平台;② 编程调试过程中掌握高效操作技巧与常见问题排查方法;③ 实现跨平台迁移、系统升级或接手他人项目时规避架构与逻辑陷阱;④ 提升对欧姆龙PLC任务机制、间接寻址、FB设计等高级功能的理解与应用能力。; 阅读建议:本手册理论结合实践,建议按“先架构后操作”的顺序阅读,重点章节需结合实际工程反复演练。特别是FB设计规范、任务切换处理、强制操作收尾流程等内容,应在仿真环境中验证后再应用于现场。注意版本匹配问题,操作前确认所用软件与控制器固件版本兼容。
CISP-CSE注册云安全工程师备考资源包
CISP-CSE注册云安全工程师备考资源包
科技中介服务机构如何通过AI技术降低技术评估与匹配服务的操作门槛?.docx
科技中介服务机构如何通过AI技术降低技术评估与匹配服务的操作门槛?
国央企创新负责人如何借助平台实现创新资源的高效配置与项目落地?.docx
国央企创新负责人如何借助平台实现创新资源的高效配置与项目落地?


