DEV Community

Eyuel Berga Woldemichael
Eyuel Berga Woldemichael

Posted on

5 2

De-Comment Program in C

De-commenting is one of the primary tasks of the C preprocessor. This article demonstrates a simplified C program to remove comments from source-code.

DFA Design

The deterministic finite state automaton (DFA) expresses the required de-commenting logic. The DFA is represented using the traditional "labeled ovals and labeled arrows" notation. Each oval represent a state. Each state is given short name with detailed descriptions of the left. Each arrow represent a transition from one state to another. Each arrow is labeled with the single character that causes the transition to occur.
DFA

Usage

$ ./decomment <file_path>
Enter fullscreen mode Exit fullscreen mode
  • If the program is run without argument, the code to be decommented will be read from the standard input and displayed[decommented code] on the standard output
  • If argument is given, the code to be decommented will be read form the file and displayed in the standard output.

The full source-code for the project is on GitHub:

GitHub logo eyuelberga / decomment-program-c

C program to remove comments from source-code

De-Comment Program

C program to remove comments from source-code

DFA Design

The deterministic finite state automaton (DFA) expresses the required de-commenting logic. The DFA is represented using the traditional "labeled ovals and labeled arrows" notation. Each oval represent a state. Each state is given short name with detailed descriptions of the left. Each arrow represent a transition from one state to another. Each arrow is labeled with the single character that causes the transition to occur.

deterministic finite state automaton (DFA)

Build

You can compile the program using gcc.

$ gcc decomment.c -o decomment
Enter fullscreen mode Exit fullscreen mode

Usage

$ ./decomment <file_path>
Enter fullscreen mode Exit fullscreen mode
  • If the program is run without <file_path> argument, the code to be decommented will be read from the standard input and displayed[decommented code] on the standard output

  • If <file_path> argument is given, the code to be decommented will be read form the file and displayed in the standard output.

Test

test.py contains a simple…

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay