Sei sulla pagina 1di 15

SIMPLE PARSER FOR C

BY
-PRADEEP RAGAV(1RV12IS031)
-PUNITH KUMAR S(1RV12IS035)

Contents

Introduction
Types of parser
High level design
Implementation
Conclusion
References

Introduction

PARSER
PARSER

Component of a
Component of a

complier design.
complier design.

Checks the syntax of


Checks the syntax of

the language.
the language.

Takes tokens as input


Takes tokens as input

and outputs the parse


and outputs the parse
tree.
tree.

Types of parser

Top
down
parser
Top down parser

One first looks at the


One first looks at the

highest level of
highest level of
the parse tree and works
the parse tree and works
down the parse tree.
down the parse tree.
Disadvantages dangling
Disadvantages dangling
else problem.
else problem.
Example:- LL parser
Example:- LL parser

Types of parser

Bottom
up
parser
Bottom up parser

Itidentifies and
Itidentifies and

processes the
processes the
text's lowest-level
text's lowest-level
small details first,
small details first,
before its mid-level
before its mid-level
structures, and
structures, and
leaving the
leaving the
highest-level
highest-level
overall structure to
overall structure to
last.
last.
Example:- SLR, LALR
Example:- SLR, LALR

Software requirements
specification

SOFTWARE REQUIREMENTS:
OPERATING SYSTEM: Ubuntu 14.04
COMPILER USED : GCC version 3.2.2
EDITOR: VI Editor version 6.1
PROGRAMMING LANGUAGE : GNU C, Lex version
2.5.4

HARDWARE REQUIREMENTS:
MAIN PROCESSOR : Pentium IV (500MHz)
RAM SIZE : 128 MB
CACHE MEMORY:256KB
DISKETTE DRIVE:1.FFMB,3.5inches

High level design

DFD level 0

DFD level 1

High level design

DFD level 2

JFLAP THIN

software for
experimenting with
formal languages
topics.

Here we use it get


the shift reduce
table for the given
grammar.

Implementation

Programming language used: C programming language.


Because

Easier to understand
There is no need for higher level language such

as C++, Java since we do not need object


oriented programming.

Platform used:
Linux operating system.
Since it is easier to use and it is easier to code
in this platform.

Implementation

Parser has four moves in our program.


Action[sm,a]=shift s, parser will execute shift
move.
Action[sm,a]=reduce r, parser will execute
reduce move.
Action[sm,a]=acc(r0), input is accepted.
Parsing is complete.
Action[sm,a]=error. Parser as encountered a
error.

Implementation

Algorithm :-Shift_reduce_operation(char a, int t)

Input: char a, int t


Output: stack
If(action[s, a]=shift s)
Push t on to the stack
Let a be the next input symbol
Else if(action[s, a]=reduce a->b)
Pop(b); symbols of the stack.
Push(a);
Let t be top of the stack.

Else if(action[s, a]=acc)


Input is accepted;

Conclusion
Advantages

The program can be directly entered or the filename of


the source code can be given as input.

Future scope

The parser must be capable of parsing the entire


source code. The implemented parser exits on
encountering the first error.
Displaying appropriate error messages. Error handling
and recovery strategies can be implemented.
Identifying the number of format specifiers and
matching the data types with the variable type in
printf and scanf statements.

References

[1] Alfred W Aho, Monica S Lam, Ravi


Sethi, Jeffrey D Ullman, Compilers
Principles, Techniques and Tools, Pearson
Education, 2008.
[2] Leland L. Beck, System Software,
Third Edition, Addison-Wesley, 1997.

Potrebbero piacerti anche