Skip to content

Latest commit

 

History

History
80 lines (52 loc) · 1.26 KB

File metadata and controls

80 lines (52 loc) · 1.26 KB

C Source Analyzer

A C program analysis toolkit with two utilities.
Designed to remove comments and check basic syntax errors in C source files while handling strings, character literals, and non-nesting comments correctly.


Features

1. strip_comments

  • Removes all C comments (// and /* */) from source files.
  • Correctly handles:
    • Quoted strings ("...")
    • Character constants ('a')
    • Escape sequences (\", \', \\)
  • Usage:
./strip_comments < input.c > output.c

2. check_syntax

  • Checks C programs for rudimentary syntax errors:

    • Unmatched parentheses ()

    • Unmatched brackets []

    • Unmatched braces {}

  • Ignores:

    • Strings and character literals

    • Comments and escape sequences

  • Usage:

./check_syntax < input.c

Compilation

  • Using GCC directly
# Build strip_comments
gcc src/main_strip.c src/lexer.c -o strip_comments
# Build check_syntax
gcc src/main_check.c src/lexer.c src/stack.c -o check_syntax
  • Using Makefile
make

Example Usage

  • Remove comments from a file
./strip_comments < example_input.c > example_output.c
  • Check for basic syntax errors
./check_syntax < example_input.c

License

  • MIT license