Aim:-

To design an online lexical analyzer simulator for C programming language that detects token and classifies them into keywords, identifiers, special characters and operators while ignoring tab, new line and redundant spaces.

Theory:-

Given line of code as user input, representing a program snippet, the task is to detect tokens in a C program called the lexical analysis of a compiler. Hence, this simulator is referred to as the lexical analyzer. The lexical analyzer is a part of the compiler that detects tokens of a program and sends it to the syntax analyzer. Token is the smallest logical unit of a program and can be of the following types:-




Simulation Logic:

Input/Output Examples:-

Online Simulator:-

Click on this Link to go to the Online Simulator.

Discussion:-

We wrote the online simulator using C programming language and integrated it with the website designed using HTML, CSS, JavaScript. The lexical analyzer simulator is designed for C language that detects token and classifies them into keywords, identifiers, string constants, special characters and operators while ignoring tab, new line and redundant spaces.

Source of Error & Error Recovery:-

There can be two possible sources of error for a string in the program snippet to be considered as an invalid identifier:



ERROR RECOVERY METHODS:

Although there are some of error recovery methods that are automatically performed by the compiler, it is not recommended as it may lead to problems in other parts of code if those are not changed accordingly. These are four methods by which an invalid identifier is turned into a valid one by the compiler-