Lexical analysis of--c language subroutine for pairing programming

Source: Internet
Author: User
Tags assert case statement naming convention

First, the problem description
      1. Definition of a small subset of C language tables
    • 2. Design the value of the word attribute, all kinds of tables (representing the identifier table, Chang), word symbols and in-machine representations, using standard input and output methods. The program receives the code from the keyboard, ends with a code Terminator "#", and prints the results of the lexical analysis to the screen. Required implementations:

      • (1) The identification of the correct source program;
      • (2) Identification of the source program containing the notes//and/* * *;
      • (3) Identification of the source program that contains the error identifier.
Ii. Review FormCode conding Links
Function Module Name Lexical analysis of a small subset of C language
Censor person Wang Shu Date of review 2018.4.5
Code Name Lexical analysis of a small subset of C language Code author Zhoulei
File structure
Importance Review items Conclusion
is the name of the header file and the definition file reasonable? Is
  Is the directory structure of the header file and definition file reasonable? Is
  is the copyright and version statement complete? Whether
Important Does the header file use the IFNDEF/DEFINE/ENDIF preprocessing block? Is
  Does the header file contain only "declarations" without "definition"? Is
     
Layout of the program
Importance Review items Conclusion
  is the blank line decent? Is
  Is the space within the line of code appropriate? Is
  is long line splitting appropriate? Is
  Do "{" and "}" each take one row and align to the same column? Is
Important Does a line of code only do one thing? If you define only one variable, write only one statement. Whether
Important The If, for, while, and do statements take on a single line, regardless of the number of execution statements, add "{}". Whether
Important When defining a variable (or parameter), does the modifier * and & Close the variable name? Is the note clear and necessary? Is
Important Does the comment have errors or may cause misunderstandings? Whether
Important The public of the class structure, protected, does the private order remain consistent in all programs? Is
     
Naming rules
Importance Review items Conclusion
Important is the naming convention consistent with the style of the operating system or development tool being used? Is
  Is the identifier intuitive and can be spelt? Is
  Should the length of identifiers conform to the "Min-length && max-information" principle? Is
Important Are the same local variables and all variables present in the program? Whether
  are class names, function names, variables and arguments, and constants written in a format that follows certain rules? Is
  are static variables, global variables, and class member variables prefixed? Is
     
Expressions and Basic statements
Importance Review items Conclusion
Important If there are more operators in the line of code, is it clear that the order of operations of the expression is determined with parentheses? Is
  Do you write complex expressions that are too complicated or multipurpose? Is
Important Do you want to confuse a composite expression with a "true mathematical expression"? Whether
Important Do you want to write an if statement in an implicitly incorrect way? Whether
Whether (1) The Boolean variable is compared directly with true, false, or 1, 0. Whether
  (2) Use the floating-point variable with "= =" or "! = "Compared to any number. Whether
  (3) Use the pointer variable "= =" or "! = "Compared to NULL. Whether
  If there is a logical judgment in the loop and the number of loops is large, is the logic Whether
  Off to the outside of the loop body? Whether
Important Does the end of the case statement forget to add a break? Not used
Important Have you forgotten to write the default branch of switch? Not used
Important Do you leave a hidden danger when using goto statements? For example, skipping the construction of certain objects, initialization of variables, important calculations, and so on. Not used
     
Constant
Importance Review items Conclusion
  Do you use represented, which is intuitive, to represent numbers or strings that will appear more than once in a program? Is
  In a C + + program, do you use const constants instead of macro constants? Whether
Important If a constant is closely related to other constants, is this relationship included in the definition? Whether
  Have you misunderstood the Const data members in the class? Because const data members are only in an object Whether
  The lifetime is a constant, but it is mutable for the whole class. Whether
     
function design
Importance Review items Conclusion
  Is the writing of the parameter complete? Don't be greedy. Write only the type of the parameter and omit the parameter name. Is
  is the parameter named and order reasonable? Is
  is the number of arguments too many? Is
  Do you use parameters of type and number uncertainties? Whether
  Is the type of the function return value omitted? Is
  Does the function name conflict with the return value type semantically? Whether
Important Do you want to mix the normal and error flags back together? The normal value should be obtained with an output parameter, and the error flag is returned with a return statement. Whether
Important In the "entrance" of the function body, is the validity of the parameter checked with an assert? Whether
Important Use abuse of assert? For example, to confuse illegal situations with erroneous situations, the latter being inevitable and must be dealt with. Whether
Important Does the return statement return a pointer or reference to "stack memory"? Whether
  Do you use const to improve the robustness of a function? A const can enforce the protection of a function's arguments, return values, or even the definition of a function. "Use const whenever need" Whether
     
Memory management
Importance Review items Conclusion
Important Does the pointer value be checked for null immediately after requesting memory with malloc or new? (Prevent use of memory with pointer value NULL) Is
Important Do you forget to assign an initial value to both arrays and dynamic memory? (Prevents uninitialized memory from being used as the right value) Is
Important is the subscript of an array or pointer out of bounds? Whether
Important is the request for dynamic memory paired with the release? (Prevent memory leaks) Is
Important Is the "memory exhaustion" problem handled effectively? Whether
Important Do you want to modify the contents of pointers to constants? Whether
Important Is there a wild pointer? For example (1) The pointer variable is not initialized; (2) After releasing memory with free or delete, forget to set the pointer to null. Whether
Important Do you confuse Malloc/free with New/delete? Whether
Important Is the malloc statement correct? For example, is the number of bytes correct? is the type conversion correct? Whether
Important Is the New/delete statement correct when creating and releasing a dynamic object array? Not used
     
Other FAQs
Importance Review items Conclusion
Important Data type issues:  
  (1) Is there an error in the data type of the variable? Whether
  (2) Are there assignments of different data types? Whether
  (3) Is there a comparison of different data types? Whether
Important Variable Value problem:  
  (1) Is there an error in the initialization or default value of the variable? Whether
  (2) Are there overflow or underflow of variables? Whether
  (3) is the accuracy of the variable sufficient? Is
Important Logical judgment Question:  
  (1) is the comparison invalid due to the accuracy reason? Whether
  (2) Is there an error in the priority of an expression? Whether
  (3) is the logical judgment turned upside down? Whether
Important Cyclic problems:  
  (1) is the cyclic termination condition incorrect? Whether
  (2) Unable to terminate normally (dead loop)? Whether
  (3) Do you want to modify the loop variable incorrectly? Whether
  (4) Is there an accumulation of errors? Whether
Important Error handling issues:  
  (1) forgot to do error handling? Whether
  (2) Error handler block has never had a chance to be run? Whether
  (3) Is there a problem with the error handler block itself? If the reported error is inconsistent with the actual error, the processing method is incorrect, and so on. Whether
  (4) is the error handler block "Hindsight"? The software has been faulted before it was called. Whether
Important File I/O issues:  
  (1) Do you want to operate on a file that does not exist or is wrong? Whether
  (2) Does the file open in the correct way? Whether
  (3) is the file end judged incorrect? Whether
  (4) Did you close the file correctly? Whether
     
Iii. Summary
  • 1. Program Notes

    Most of the programs do not have comments, in the process of re-reading will need to re-analyze the execution of the program, this process takes a lot of time, for the source program comments modified the following changes to the section

    //deal '//' and '/* */'if(ch = = '/') {ch = nike[nummber++];Switch(CH) {//find//     Case'/': flag++; while(nike[nummber]!=' \ n ') nummber++; Var =-3;//set Var     Break;//find/*     Case' * ': Flag + +; while(nike[nummber]!= ' * ') && (nike[nummber+1]!= '/')) nummber++; Var =-3;//set VarNummber = Nummber+2; ch = nike[nummber]; Break;//'/' only a symble    default: Var =6; Save[m++]=ch; Break; }
Modify part of the codeCoding Links
    • 2. Summary of the experience The lexical analysis of C-language small subset program is one of the experimental contents of our compiling principle course, the impression of the algorithm is already vague, and this review of the teammate Code makes me fully aware of the importance of the comment for the code retrial, or later maintenance. It can not only improve the efficiency of reading, but also make our thinking more clear.

      By reading the code of Zhoulei classmate, I can feel his idea of solving this problem is very clear, the overall logic of the code is very good, in the same time to reiterate the code of the classmate I also reflect on their own, on the one hand should pay attention to algorithmic logic learning, so that the program more efficient implementation. On the other hand, in code style, naming format, and so on some team projects and even their own daily programming, it is important to follow the standard code programming specifications, so that the code review, program maintenance easier and more efficient.

Lexical analysis of--c language subroutine for pairing programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.