0% found this document useful (0 votes)
277 views3 pages

Compiler Construction: University of Central Punjab

This document provides instructions for a compiler construction project involving the implementation of a parser for a Tiny-C++ language. Students must: 1. Convert the grammar into LL(1) form and document it 2. Implement a predictive parser using either a parsing table or recursive descent 3. Handle syntax errors using panic mode The project has two phases, with the first focusing on converting the grammar and the second on implementing the parser. Students will be evaluated based on correctly reflecting details in their code, handling sample input/output, and reporting errors. Group discussion is allowed but not sharing code.

Uploaded by

Tyler
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
277 views3 pages

Compiler Construction: University of Central Punjab

This document provides instructions for a compiler construction project involving the implementation of a parser for a Tiny-C++ language. Students must: 1. Convert the grammar into LL(1) form and document it 2. Implement a predictive parser using either a parsing table or recursive descent 3. Handle syntax errors using panic mode The project has two phases, with the first focusing on converting the grammar and the second on implementing the parser. Students will be evaluated based on correctly reflecting details in their code, handling sample input/output, and reporting errors. Group discussion is allowed but not sharing code.

Uploaded by

Tyler
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

University of Central Punjab

Faculty of Information Technology

Compiler Construction
Project Phase # 2

Submission Before (Phase 2 – Part 1): 11:55PM - 30-11-2020


Submission Before (Phase 2 – Part 2): 11:55PM - 13-12-2020
(Late will be penalty of deduction of 2 absolute marks per day)

TINY-C++:
This is a subset of C++ language. Description of the language as follow:

Detail Example
1 Identifiers (_|L)(L|_|D)*(D|_) _rate2, _rate_,
rat1e2 …etc
2 Numbers [+-]?(D+)(\.D+)?, and exponent numbers. 3.43433E+13,

3 Operators <,>,!=, <>, :=, ==, *, +, /,-, >>,<<, ++, =+, &&, ||, =>, =<,
%, :, =, ::, -- , ;
4 Punctuations [,{,(,),},]
5 Keyword loop, agar, magar, asm, else, new, this, auto, enum,
operator, throw, bool , explicit, private, true, break,
export, protected , try, case, extern, public, typedef,
catch, false, register, typeid, char, float, typename,
class, for, return, union, const, friend, short, unsigned
goto, signed, using, continue, if, sizeof, virtual, default,
inline, static, void, delete, int, volatile, do, long, struct,
double, mutable, switch, while, namespace
Complete Grammar
Right down grammar for C-Like syntax

Function  Type identifier ( ArgList ) CompoundStmt


ArgList  Arg | ArgList ,Arg
Arg  Type identifier
Declaration  Type IdentList ;
Type  int | float
IdentList  identifier ,IdentList | identifier
Stmt  ForStmt | WhileStmt | Expr ; | IfStmt
| CompoundStmt | Declaration |;
ForStmt  for < Expr ; OptExpr ; OptExpr > Stmt // use <> instead of ()
OptExpr  Expr |
WhileStmt  while < Expr > Stmt // use <> instead of ()
IfStmt  if < Expr > StmtElsePart // use <> instead of ()
ElsePart  else Stmt | 
CompoundStmt [ StmtList ] // use [] instead of {}
StmtList  StmtListStmt | 
Expr  identifier := Expr | Rvalue
Rvalue  Rvalue Compare Mag | Mag
Compare  == | < | > | <= | >= | != | <>
Mag  Mag + Term
| Mag - Term
| Term
Term  Term * Factor
| Term / Factor
| Factor
Factor  ( Expr )
| identifier
| number

Sub- Grammar
Function  Type identifier ( ArgList ) CompoundStmt
ArgList  Arg | ArgList ,Arg
Arg  Type identifier
Stmt  WhileStmt | Expr ;| CompoundStmt | Declaration |;
Declaration  Type IdentList ;
Type  int | float
WhileStmt  while < BoolExpr > Stmt
CompoundStmt [ StmtList ]
StmtList  StmtListStmt | 
BoolExpr  identifierCompare Mag
Compare  == | < | > | <= | >= | != | <>
Expr  identifier := Mag
Mag  Mag + Term| Mag – Term| Term
Term  Term * Factor| Term / Factor| Factor
Factor  ( Expr )| identifier| number
Assignment Description:

For this assignment,

1. You have to write a Parserfor above Grammar.


2. Parser will get Token from scanner and built a parse tree.
3. Parser will built the parse tree using Predictive Parser (LL(1)) grammar.
4. Panic Mode approach will be implemented to output the syntax error.
5. This assignment includes following parts:

Submission
Phase (s) PARTS Output Marks
Date

1 Phase 1 Convert grammar to LL(1) grammar. 30-Nov-2020 Documentation 20

Implement Parser using Source Code


2 Phase 2 13-Dec-2020 50
i) LL1 Parsing Table or Files

Total 70

Absolute 10

Rules:
1. This is an individual assignment. Each student has to submit his/her assignment work.
2. Group discussion is allowed but don’t share code and other part of assignment with other student.
3. Plagiarism is not tolerable in any of its form. Minimum penalty would be an ‘0’ marks in the project
module.

Tools:
Language (For Development): C++

Note: Student cannot use built-in data structure. Student can use his own data structure Hash Table, Linked
List which he/she developed in data structure course. In this case student should know about the data
structure.

Evaluating Criteria:
1. Source code should reflect the detail given in documents (other parts).
2. A text file with valid source code will be input of the scanner and Token file will be output of the scanner
tool.
3. A text file will show the productions in separate lines used in building the parse tree.
4. A text file show the errors generated from both scanner and parser.

You might also like