Skip to content

samdani91/SPL-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

102 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Code Comprehension (3C)

C Code Comprehension is a software tool developed to help beginners understand and analyze C source code. It provides static and dynamic analysis of C programs through lexical tokenization, line-by-line interpretation, and intermediate value tracing of variables.


🧠 Features

✅ Static Analysis

  • Preprocesses source code by removing comments and blank lines.
  • Performs tokenization into:
    • Identifiers
    • Keywords
    • Operators
    • Literals
    • Comments
  • Interprets tokens line by line using a map-based data structure.
  • Detects common syntax errors:
    • Missing semicolons
    • Incorrect & usage in scanf

✅ Dynamic Analysis

  • Executes C source code line by line in a controlled environment.
  • Tracks and displays intermediate variable values throughout execution.
  • Determines the path taken by conditional statements (if/else).

🛠 Implementation Highlights

  • Developed in C++ using file handling, string processing, and external compilation.
  • Implements a tokenization engine using character classification and string pattern matching.
  • Dynamic execution is performed via:
    • Writing each line of the original source into a separate testCode.c
    • Compiling and executing this test file
    • Capturing outputs to a result file

💻 How It Works

1. Static Analysis Flow

Input C Code → Preprocessing → Tokenization → Interpretation → Error Detection

2. Dynamic Analysis Flow

Input C Code → Write Line to testCode.c → Compile & Execute → Output Variable Values


🧪 Example Use Case

Given a simple C program with variable assignments and conditionals, 3C will:

  • Display a structured breakdown of tokens
  • Highlight errors like missing semicolons
  • Trace the evolution of each variable through dynamic execution

Run Locally

Clone the project

  git clone https://github.com/samdani91/SPL-1

Dynamic Analysis

  cd Dynamic Analysis

Run

  g++ dynamicAnalysis.cpp

Static Analysis

  g++ main.cpp tokenHelp.cpp tokenization.cpp interpretFunc.cpp -o testrun

Run

  ./testrun

🚧 Challenges Overcome

  • Deep dive into C++ file handling and project structuring
  • Managing line-by-line execution of code within another program
  • Designing a token interpreter from scratch

📈 Possible Extensions

  • Support for:
    • Nested loops
    • Multiple functions
    • Complex expressions
    • More comprehensive error detection
  • GUI-based interface for better usability

👨‍🎓 Author

A. M Samdani Mozumder
BSSE Roll No.: 1412
Session: 2021–2022
Institute of Information Technology, University of Dhaka


📚 References

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors