simple parser for c

15
SIMPLE PARSER FOR C BY -PRADEEP RAGAV(1RV12IS031) -PUNITH KUMAR S(1RV12IS035)

Upload: naveenthefuture

Post on 25-Dec-2015

243 views

Category:

Documents


2 download

DESCRIPTION

different parser

TRANSCRIPT

Page 1: Simple Parser for c

SIMPLE PARSER FOR C

BY-PRADEEP RAGAV(1RV12IS031)

-PUNITH KUMAR S(1RV12IS035)

Page 2: Simple Parser for c

Contents

Introduction Types of parser High level design Implementation Conclusion References

Page 3: Simple Parser for c

Introduction

PARSER Component of a

complier design.

Checks the syntax of the language.

Takes tokens as input and outputs the parse tree.

Page 4: Simple Parser for c

Types of parser

Top down parser One first looks at the

highest level of the parse tree and works down the parse tree.

Disadvantages dangling else problem.

Example:- LL parser

Page 5: Simple Parser for c

Types of parser

Bottom up parser It identifies and

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

Example:- SLR, LALR

Page 6: Simple Parser for c

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

Page 7: Simple Parser for c

High level design

DFD level 0

DFD level 1

Page 8: Simple Parser for c

High level design

DFD level 2

Page 9: Simple Parser for c

JFLAP THIN

software for experimenting with formal languages topics.

Here we use it get the shift reduce table for the given grammar.

Page 10: Simple Parser for c

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.

Page 11: Simple Parser for c

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.

Page 12: Simple Parser for c

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 stackLet 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;

Page 13: Simple Parser for c

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.

Page 14: Simple Parser for c

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.

Page 15: Simple Parser for c