150 likes | 282 Views
C Program Checker . By: Advisor: Mike Burgio Dr. Fischbach Chris Addis. Goals . Make a program that detects potential errors in freshman C programs Specifically errors not detected by the gcc compiler. Includes syntax and semantic errors
E N D
C Program Checker By: Advisor: Mike Burgio Dr. Fischbach Chris Addis
Goals • Make a program that detects potential errors in freshman C programs • Specifically errors not detected by the gcc compiler. • Includes syntax and semantic errors • Print out the line numbers where the potential error has occurred.
Syntax Errors • Syntax is a set of rules that define the sequence of symbols that are considered to be correctly structured programs in that language • The gcc compiler finds all syntax errors.
In terms of our project • We are looking for errors that do not violate the syntax of the language, but might not be what the programmer intended. • Ex. Using scanf statement without an “&” • scanf(“%d”, x);
Syntax Example • A simple control structure int x = 2, y = 4; if(x = y) { printf(“Same!\n”); } else { printf(“Not Same\n!”); }
Semantic Errors • Semantics of a program are what the actual statements do and what the expressions mean when the program is executed. • Specific examples of semantic errors: • Failure to initialize variable • Proper type conversion • Ex. Truncating a real number unintentionally
Semantic Example A common while loop int i; while(i<5) { printf(“Hello World”); i = i + 1; }
Grammar • Grammar for C defines what is acceptable code to be read by a compiler • In our grammar, we define what is acceptable and unacceptable for specific cases, and skip the rest • This is an extendable project, allowing us to add more errors as we progress
JavaCC • To make our C Checker, we used JavaCC • JavaCC is a parser generator and lexical analyzer that allows us to define our grammar • JavaCC analyzes the program as follows: • Breaking up each line into tokens • Tokens are processed to determine the structure of the program • Checks to see if the sequence of tokens matches our correct case, or matches our incorrect case
Our Program checks… • Only one equal sign in if statements, for/while loops • Scanf/printf statements containing improper ampersand • Inconsistent amount of variables and percent codes • Truncation from real number to integer • Variables being used before being initialized • Ensuring the types match with variables • Performs a usage analysis at the end of the program and prints any unused variables • And more!
What is a GUI • GUI is a graphical user interface • This allows users to interact with electronic devices with images rather than text commands • GUI’s have become very common in modern programming
Our GUI • In order to make our program easy to use, we implemented a GUI • Our program can also run as a text command if the user prefers.