“MINI C COMPILER USING LEX AND YACC”

Nikitha D Reddy
3 min readMay 3, 2021

Design and implementation of Mini C Compiler using LEX and YACC compiler generating package.

ABSTRACT

We have developed a compiler for C language which makes use of the C lexer to scan the given C input file and yacc parser to parse the file

There are several intermediate code like postfix notation, syntax tree, 3 address code.

We used 3 address code in our project. Thus, the annotated parse tree obtained from the previous semantic phase is converted into machine independent linear representation like three address code.

S/W & H/W Requirements

Hardware requirements
RAM

Software requirements
Ubuntu

c language

Introduction:

Intermediate Code Generation phase is the glue between the frontend and backend of the compiler design stages. The final goal of a compiler is to get programs written in a high-level language to run on a computer. This means that, eventually, the program will have to be expressed as machine code which can run on the computer.

Most common independent intermediate representations are: 1. Postfix notation 2. Three Address Code 3. Syntax tree.

Three address code is a type of intermediate code which is easy to generate and can be easily converted to machine code. It makes use of at most three addresses and one operator to represent an expression and the value computed at each instruction is stored in a temporary variable generated by the compiler.

Yacc provides a general tool for describing the input to a computer program. The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized. Yacc turns such a specification into a subroutine that handles the input process frequently, it is convenient and appropriate to have most of the flow of control in the user’s application handled by this subroutine. Lexer can be used to make a simple parser.

Flow Chart

OUTPUT SCREENSHOT

CONCLUSION

The yacc script presented in this report takes care of all the rules of C language.

Our future work would include making the script even more robust in order to handle all aspects of C language and making it more efficient.

Link for code-Page not found · GitHub · GitHubhttps://github.com/niksy20/Mini-c-compiler

Team Members
B MONISHA — (ENG18CS0055)

NIKITHA D REDDY — (ENG18CS0193)

PRAKEERTHY TOLETY — (ENG18CS0212)

VSN AKHILA — (ENG18CS0323)

Special Thanks
SPECIAL THANKS

We owe our deep gratitude to our mentor Dr. Anbunathan R, Founder and CEO, DigiTran solutions, Bangalore, Adjunct Professor, who helped us in this project by giving more understanding in the topic of compiler design.

--

--