• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Lexical Analyzer for Subset of C

June 21, 2011 by ProjectsGeek 2 Comments

Implement Lexical Analyzer for the subset of C

Aim : Write a program in C to implement Lexical Analyzer for the subset of C.

Objective:

  1. To understand the basic principles in compilation.

  2. To study lexical analysis phase of compiler.

Theory:

Compiler takes input as a source program & produces output as an equivalent sequence of machine instructions. This process consists of two-step processing of source program.

  1. Analysis of source program.

  2. Synthesis of target program.

Analysis step:

It consists of three sub steps

  1. Lexical Analysis – Determine lexical constituents in source program.

  2. Syntax Analysis – Determine structure of source string.

  3. Semantic Analysis – Determine meaning of source string.

Synthesis Step:

It deals with memory allocation & code generation. The actions in analysis phase are uniquely defined for a given language. But synthesis step consists of many action instances where actions depend on the aspect concerning the execution environment of the compiler.

e.g. – Operating system interfaces target machine features such as instruction set, addressing modes, etc.

Lexical analysis: The action of scanning the source program into proper syntactic classes is known as lexical analysis.

Task of Lexical Analysis:

  1. To scan the program into basic elements or tokens of the language.

  2. To build the Uniform symbol table (table of tokens).

  3. To build the symbol & literal table.

  4. To remove white spaces & comments.

  5. To detect errors such as invalid identifier or constant.

Data structures / Databases required:

  1. Source program – Original Source program, which is scanned by compiler as string of characters.

  2. Terminal Table – A permanent database that has entry for each terminal symbols such as arithmetic operators, keywords, punctuation characters such as ‘;’ , ‘,’etc Fields: Name of the symbol.

  3. Literal Table – This table is created during lexical analysis so as to describe all literals in the program.

Fields: Name of the literal.

4. Identifier Table – Created during lexical analysis and describes all identifiers in the program.

Fields: Name of the identifier.

5. Uniform Symbol Table – Created during lexical analysis to represent the program as a string of tokens, rather than of individual characters. Each uniform symbol contains the identification of the table to which it belongs.( IDN – Identifier table, LIT – Literal Table TRM – Terminal Symbol Table)and index within that table.

6. Buffer – One buffer or two buffer schemes to load source program part by part to reduce disk i/o.

Keywords can be stored either in the terminal table or in the keyword table.

Basic steps in algorithm

1. Initialize line no to 1.

2. Read the source program line by line ( Buffer is line)

3. For each line separate the tokens such as

i) identifier/ function name / keywords : Follow the transition diagram to detect this; i.e. letter followed by letter or digit. Search in keyword table for existence of keyword, otherwise it is identifier or function name.

ii) Integer Constant : Digit followed by digit

iii) All types of operators such as >, >=, ++, +, – etc

iv) Remove comments of the type /* */

v) Remove all white spaces.

4. Assign a line no and increment a line number.

5. Repeat steps 2-4 till end of file.

Other Projects to Try:

  1. Regular Expression to DFA
  2. Two Pass Assembler Source Code
  3. Calculator using LEX and YACC
  4. Lexical analyzer Code in C Language
  5. B tech final year project-Source Code Analyzer

Filed Under: System Programming

Reader Interactions

Comments

  1. Lawyer News says

    October 1, 2013 at 2:39 am

    I found your blog on yahoo and can bookmark it currently. carry on the good work.

    Reply
  2. sameer jadhav says

    July 23, 2011 at 6:35 am

    nice post!!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy