Giter Club home page Giter Club logo

lexical-analyzer's Introduction

Lexical Analyzer for C++ written in C++.

Table of Contents:

About this project:

This project is a lexical analyzer generator written in C++. Lexical Analysis is the first phase of the compiler also known as a scanner. It converts the High level input program into a sequence of Tokens.

Tokens:

A lexical token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.

Example of tokens:

  • Type token (id, number, real, . . . )
  • Punctuation tokens (IF, void, return, . . . )
  • Alphabetic tokens (keywords)

How Lexical Analyzer functions

  1. Tokenization i.e. Dividing the program into valid tokens.
  2. Remove white space characters.
  3. Remove comments.

How to Run this Project:

  1. Clone the project using command: git clone https://github.com/Akshit6828/Lexical-Analyzer.git
  2. Change directory to Lexical-Analyzer using command: cd Lexical-Analyzer.
  3. Make a text file in this folder and write source code in C++. 3.1 Try the source code written written here
  4. Open Lex.exe file by double clicking on the file.
  5. You'll see all associated tokens from the source code.

Note: This is a Lexical Analyzer for a particular subset of C++ language explained under Assumptions: . It may not be able to parse the all token of C++ language.

ASSUMPTIONS:

While designing the LexicalAnalyzer, I have assumed the following assumptions for my Language:

  • Special Symbol: ; { } ( ) , #
  • Keyword: int, char, float, bool, cin, cout, main
  • Pre-processor Directives: include, define
  • Library: iostream, studio, string
  • Operators: *, +, >>, <<,>,<
  • Numbers/Integers: 0 to 9.
  • Identifies/ Variables: All alphabetic strings except the keywords, numbers, Pre-processor directive and library strings.

Sample Source Code:

MySourceCode.txt

#include <iostream>
#define LIMIT 5
using namespace std ;
int main(){
    // this comment is written by akshit mangotra for lexical analyzer to avoid reading the comments
    int A , B ;
    cin >> A >> B;
    cout << A * B ; 
}

Screen Shots:

MySourceCode.txt



Output(Console)



OutputFile.txt

lexical-analyzer's People

Contributors

akshit6828 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.