Advanced C Project | Source to HTML

Source to HTML

Project Brief

Display the source code in a browser by doing syntax highlighting.

Share via :

About this project

TYPE Individual project
DIFFICULTY Advanced
ESTIMATED TIME 50 hours
PUBLISHED 15th March, 2021
CONTACT training@emertxe.com

Introduction

Source to HTML : The goal of this project is to display source code in Browser. The Source to HTML program shall parse a source file and generate an equivalent HTML file. Browser which takes HTML files as input and renders it in Browser window to display source code. Reserved keywords, preprocessor directives, numerical constants, strings, ASCII characters etc must be displayed in predefined color. 

 

Importance of Syntax Highlighting:

Syntax highlighting is a feature of modern day text editors that are used for programming. The feature displays text, especially source code, in different colors and fonts as per the option set by the user. Modern day text editors which are often called as Integrated Development Environment (IDE) come with syntax highlighting as one of the important features. Some modern day IDEs like Visual Studio CodeSublime TextNotepad++ implement them very well with so many other options. 

 

Having this feature facilitates writing in a well written code both in terms of syntax and semantic handling. They also display syntax errors are visually distinct so that you as a developer can detect the issues earlier in your development. This feature is also employed in many programming related contexts such as programming manuals, either in the form of colorful books or online websites to make understanding code snippets easier for readers. Highlighting does not affect the meaning of the text itself. It is intended only for human readers.

 

Syntax highlighting in editors help to improve the readability of the code, especially if it spans several pages. The reader can easily ignore large sections of comments or code, depending on what they are looking for. Syntax highlighting also helps programmers find errors in their program. For example, most editors highlight string literals in a different color. Consequently, spotting a missing delimiter is much easier because of the contrasting color of the text. Brace matching is another important feature with many popular editors. This makes it simple to see if a brace has been left out or locate the match of the brace the cursor is on by highlighting the pair in a different color.

 

The goal of this project is to implement syntax highlighting of the given C program and convert it into an HTML file. As browsers read HTML by default it will display the output in the browser with syntax highlighted manner. Please note error handling is not part of this implementation, which can be added as the next level of requirements. By implementing this project will build a strong C programming expertise in you.

Requirement Details

Here are the high level requirements of this project: 

  1. Application should accept a C source file
  2. There should a provision to pass an output file name
  3. An option to add the line numbers to the output file

During implementation, it would require you to design a parser engine using a state-event approach. It will have the following states and transitions. 

  1. Stay in idle state at program start-up
  2. Identify words, comments, preprocessor, constants etc and move to specific state
  3. Store the characters in buffer while staying in the specific state
  4. Identify end of words, comments, preprocessor, numeric constants and return an event
  5. Leave the specific state and move back to Idle state

Skeleton Code

The skeleton code in a very interesting concept used in Emertxe. By looking into the skeleton code, you will get a clear picture into converting the given requirement into a working solution. This will also take care of important aspects like modularity, clean coding practices, re-usability etc.

Click Here to Download the Source Code for Source to HTML Project

Sample Output

Here are the sample output expected by the end of project execution.

Fig1: Usage

 

Fig2: Generating a HTML file from C Source Code

 

Fig3: Open the HTML file using Konqueror Browser

 

Fig4: Output

 

Fig5: Generating a HTML file from C Source Code with line numbers enabled

 

Fig6: Output with line numbers
Sample Output
  • Fig1: Usage
  • Fig2: Generating a HTML file from C Source Code
  • Fig3: Open the HTML file using Konqueror Browser
  • Fig4: Output
  • Fig5: Generating a HTML file from C Source Code with line numbers enabled
  • Fig6: Output with line numbers
Sample Output
  • Fig1: Usage
  • Fig2: Generating a HTML file from C Source Code
  • Fig3: Open the HTML file using Konqueror Browser
  • Fig4: Output
  • Fig5: Generating a HTML file from C Source Code with line numbers enabled
  • Fig6: Output with line numbers

similar projects