Beruflich Dokumente
Kultur Dokumente
Final Assignment
Left Recursive Predictive Parser
1. By writing context free grammar, create a structured programming language which must have the
following characteristics, you may ignore left recursion and ambiguity:
[50 marks]
Declaration Statement
o Single and multiple declaration
o Array declaration
Expressions
Assignment Statement
Conditional Statement (If-else)
Loops (for, while)
Functions
Code
CodeStatmentsList
CodeStatment
DataType
LexemesList
Lexeme
CodeBlock
CodeBlockRange
CodeRange
DeclerationRangeStam
ent
PointersOption
DeclerationStament
DeclerationStamentList
Decleration
IfRangeStatment
FcalRangeStatment
ReturnRangeStatment
LoopRangeStatment
CodeStatmentsList|
CodeStatment CodeStatmentsList|
CodeStatment
DataType id (LexemesList) CodeBlock
int | char| float | string | bool
Lexeme , LexemesList | Lexeme |
id | literal | num
{ CodeBlockRange }
CodeRange CodeBlockRange | CodeRange
DeclerationRangeStament
| IfRangeStatment
| LoopRangeStatment
| FcalRangeStatment
| ReturnRangeStatment
| BreakRangeStatment
| ExpressionRangeStatment
DataType
PointersOption
DeclerationStament;
*|
DeclerationStamentList | Decleration
Decleration,
DeclerationStamentList
|
Decleration
id | id [ num ]
if Expression CodeBlock
| if Expression CodeBlock else CodeBlock
call id ( LexemesList );
return; | return (Lexeme); | return Lexeme ;
WhileStatment
|
ForStatment
|
Software Construction
WhileStatment
ForStatment
ForOption
DoWhileStatment
ForEachStatment
ForeachIn
ExpressionRangeStatm
ent
BreakRangeStatment
Expression
Operator
DoWhileStatment | ForEachStatment
while Expression CodeBlock
for ( DataType id = num; id < num; id
ForOption )
++ | -do CodeBlock while (Expression)
foreach (DataType id ForeachIn id)
in
Expression ;
break ;
Expression
Operator
Expression
(Expression) | id | literal | num
| id = Expression
+ | - | * | / | > | >= | < | <= | != | =
DeclerationRangeStam
ent
PointersOption
DeclerationStament
DeclerationStamentList
DeclerationStamentList
Decleration
Decleration
[10 marks]
CodeStatmentsList |
CodeStatment CodeStatment
CodeStatmentList|
DataType id (LexS) CodeBlock
int | char| float | string | bool
LexemesList, LexemesList|
, LexemesList |
id | literal | num
{ CodeBlockRange }
CodeRange CodeRange
CodeBlockRange |
DeclerationRangeStament
| IfRangeStatment
| LoopRangeStatment
| FcalRangeStatment
| ReturnRangeStatment
| BreakRangeStatment
| ExpressionRangeStatment
DataType
PointersOption
DeclerationStament;
*|
DeclerationStamentList | Decleration
Decleration DeclerationStamentList
, DeclerationStamentList |
id Decleration
[num] |
Software Construction
IfRangeStatment
IfRangeStatment
FcalRangeStatment
ReturnRangeStatment
ReturnRangeStatment
LoopRangeStatment
WhileStatment
ForStatment
ForOption
DoWhileStatment
ForeachStatment
ForeachIn
ExpressionRangeStatm
ent
BreakRangeStatment
Expression
Expression
Expression_
Operator
else CodeBlock |
call id ( LexemesList );
return ReturnRangeStatment;
(Lexeme) | Lexeme |
WhileStatment
|
ForStatment
|
DoWhileStatment | ForeachStatment
while Expression CodeBlock
for ( DataType id = num; id < num; id
ForOption)
++ | -do CodeBlock while (Expression)
foreach (DataType id ForeachIn id)
in
Expression ;
break ;
Expression_ Expression
Operator Expression
(Expression) | id | literal | num
+ | - | * | / | > | >= | < | <= | != | =
3. Evaluate first and follows, and develop a parsing table as a text file.
Symbol
Code
CodeStatmentsList
CodeStatmentsList
CodeStatment
Datatype
LexemeList
LexemeList
Lexeme
CodeBlock
CodeBlockRange
CodeBlockRange
First
int char float string
bool double
int char float string
bool double
int char float string
bool double
int char float string
bool double
int char float string
bool double
id literal num
,
id literal num
{
int char float string
bool double if for
while do foreach
call return break
( id literal num
int char float string
Follow
$
$
$
$
id * $
)$
)$
)$
Else while $
}$
}$
[20 marks]
Software Construction
CodeRange
PointersOption
DeclerationStament
DeclerationStamentLis
t
DeclerationStamentLis
t
Decleration
Decleration
IfRangeStatment
*
id
Id
;$
id
[ num ]
if
IfRangeStatment
else
FcalRangeStatment
call
ReturnRangeStatment
return
ReturnRangeStatment
( id literal num
;$
;$
int char double string
float bool if for while do
foreach call
return
break ( id literal num
}$
int char double string
float bool if for while do
foreach call
return
break ( id literal num
}$
int char double string
float bool if for while do
foreach call return
break ( id literal num
}$
Int char double string
float bool if for while do
foreach call return
break ( id literal num
}$
Int char double string
float bool if for while do
DeclerationRangeSta
ment
Software Construction
LoopRangeStatment
WhileStatment
ForStatment
ForOption
DoWhileStatment
ForeachStatment
ForeachIn
ExpressionRangeStat
ment
BreakRangeStatment
Expression
Expression
Expression _
Operator
);
+
=
+ - * / > >= < <= +
!= =
=
( id literal num
+
=
+ - * / > >= < <= +
!= =
=
$
=
=
=
=
*
$
*
$
*
$
*
$
[20 marks]
Software Construction
SUBMISSION
When:
What:
Group:
Just after the final examinations; when the copies will be displayed.
Hardcopies of grammar and its versions, and softcopy of the software.
May consists of 4 to 5 members