Skip to content

This is our Formal Languages and Automata Theory Project. This repo contains Program of Lexical Analyzer for C++ that will tokenize C++ program.

License

Notifications You must be signed in to change notification settings

JunaidSalim/Lexical_Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lexical Analyzer

This is our Formal Languages and Automata Theory Project. This repository contains a program for a Lexical Analyzer for C++ that will tokenize a C++ program.

Installation and Usage

  1. Install Flex

    Make sure Flex is installed on your system. You can download it from Flex's official website or install it using your package manager.

  2. Add Flex to Environment Variables

    Ensure that the path to the Flex binary is added to your system's environment variables.

  3. Run Flex on the Lexer File

    Use Flex to generate the C source file from the lexer definition file:

    flex lexer.l

    This command will generate a file named lex.yy.c.

  4. Compile the Generated C File

    Compile the generated C file using GCC (or any C compiler):

    gcc lex.yy.c -o [outputFile]
  5. Run the Lexical Analyzer

    Run the compiled executable with an input C++ file to tokenize it:

    ./[outputFile] [InputFile]

    Replace [outputFile] with the name of your executable and [InputFile] with the path to the C++ file you want to tokenize.

    The tokens will be printed in the terminal.

Example

Here's a quick example to demonstrate the steps:

  1. Install Flex and add it to your PATH.

  2. Create a file named lexer.l with your lexer definitions.

  3. Run Flex:

flex lexer.l
  1. Compile the generated C file:
gcc lex.yy.c -o lexer
  1. Tokenize a C++ file:
./lexer input.cpp

Contributors

About

This is our Formal Languages and Automata Theory Project. This repo contains Program of Lexical Analyzer for C++ that will tokenize C++ program.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published