183
社区成员




The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ?category=0 |
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/600798588 |
The Aim of This Assignment | Code personally & learn git and github & learn the process of writing a project & learn unit test and performance test |
MU STU ID and FZU STU ID | 19105886 &831902204 |
My Github Library
https://github.com/zxc123asd456/nova
Personal Software Process Stages | Estimated Time (minutes) | Actual Time (minutes) |
---|---|---|
Planning | 20 | 15 |
Estimate | 20 | 20 |
Development | 0 | 0 |
Analysis | 240 | 360 |
Design Spec | 0 | 0 |
Design Review | 0 | 0 |
Coding Standard | 30 | 30 |
Design | 60 | 50 |
Coding | 120 | 150 |
Code Review | 60 | 60 |
Test | 60 | 60 |
Test Report | 0 | 0 |
Size Measurement | 20 | 15 |
Postmortem & Process Improvement Plan | 20 | 20 |
Total | 650 | 780 |
The reconsider and be prepared to think about it in terms of text matching. According to the requirements, due to the characteristics of THE C language, the format of the code is changeable, the requirements of the code only meet the basic condition can be compiled, so in the white space and so on the processing should be very careful. Therefore, after reading in the function, we need to do some special formatting for the function. Firstly, we need to remove the content of the comment part, and secondly, we need to process the string. All the strings in the code are replaced to prevent the comment or the content in the string from being matched.
Keyword judgment
It took a long time to reintroduce the DFA I had thought of before, mainly learning the ideas and code implementation. The pre-processed code section is passed in, and a DFA tree is built through DFA, followed by keyword matching.
The switch to determine
After discovering that the code block is formatted, you only need to match switch() {through regular expression, match the corresponding position of the close parenthesis through parenthesis matching, and then count the number of case occurrences in the code segment in parenthesis using regular expression again to achieve the function.
if-else if-else if-else
This part is the most difficult part in this homework, also need to consider the details of the most part, I find some relevant information about the compiler code, but because the compiler is service for compilation, so in the process of dealing with many other factors, far more than the requirements of the job, so you need to make their own design. In the process of thinking, referring to the idea of state matching in DFA, that is, through the transfer of state between if, else if and else to complete the statistical work of the code, I designed the following state transition diagram based on the examples given:
First we read the file, it is easy so let's just do it in the main method.
cout<<"输入文件路径:";
cin>>filename;
ifstream fin(filename.c_str());
if ( ! fin)
{
cout << "file open" error <<endl;
}
else
{
while (getline(fin,temp))
{
Keywords(temp);
}
fin.close();
}
Second Keyword record
Because only keywords and {} symbols are needed, only these are recorded. If the character is a letter, continue reading until it is a space, and then compare it with the keyword table. If it is one of the characters, note it down.
keyword[32] = { "auto","break","case","char","const", "continue","default","do",
"double","else","enum","float","for","goto","if","int",
"long","register","while","reuturn","short","signed","sizeof","static",
"struct","switch","typedef","union","unsigned","void","volatile","while",};
third output
void Print()
{
int sum;//total num
for (int i = 0; i < 32; i++)
{
if (p[i].number != 0)
{
sum += p[i].number;
}
}
cout << "total num: " << sum << endl;
bool Case_flag = false;
cout << "switch num: " << switch_number << endl;
cout << "case num: ";
for (int i = 0; i < 50; i++)
{
if (case_number[i] != 0)
{
cout << case_number[i] << " ";
Case_flag = true;
}
}
if (Case_flag == false)
{
cout << "0";
}
cout << endl;
cout << "if-else num: " << ifelse_number << endl;
cout << "if-elseif-else num: " << ifelseifelse_number << endl;
}
For this assignment, at first look at the words a little confused, after all, seems to have not played code for a long time. After thinking, I came up with an idea, but thinking is not the same as making it. Practice is a hard process, which is a good help for training my ability and mentality. I tried many methods, but encountered many difficulties.I hope to make the soft engineering practice of this semester more meaningful and exercise my ability in continuous learning.