Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the grammar defined by the following set of production rules which represent a subset of MODULA-2 programming language : module-decl ( module-heading declarations procedure-decl

Given the grammar defined by the following set of production rules which represent a subset of MODULA-2 programming language :
module-decl ( module-heading declarations procedure-decl block name .
module-heading ( module name ;
block ( begin stmt-list end
declarations ( const-decl var-decl
const-decl ( const const-list | (
const-list ( ( name = value ; )*
var-decl ( var var-list | (
var-list ( ( var-item ; )*
var-item ( name-list : data-type
name-list ( name ( , name )*
data-type ( integer | real | char
procedure-decl ( procedure-heading declarations block name ;
procedure-heading ( procedure name ;
stmt-list ( statement ( ; statement )*
statement ( ass-stmt | read-stmt | write-stmt | if-stmt
| while-stmt | repeat-stmt | exit-stmt | call-stmt | (
ass-stmt ( name := exp
exp ( term ( add-oper term )*
term ( factor ( mul-oper factor )*
factor ( ( exp ) | name | value
add-oper ( + | -
mul-oper ( * | / | mod | div
read-stmt (readint ( name-list ) | readreal ( name-list )
| readchar ( name-list ) | readln
write-stmt (writeint ( write-list ) | writereal ( write-list )
writechar ( write-list ) | writeln
write-list ( write-item ( , write-item )*
write-item ( name | value
if-stmt ( if condition then stmt-list elseif-part else-part end
elseif-part ( ( elseif condition then stmt-list )*
else-part ( else stmt-list | (
while-stmt ( while condition do stmt-list end
repeat-stmt ( loop stmt-list until condition
exit-stmt ( exit
call-stmt ( call name (* This is a procedure name *)
condition ( name-value relational-oper name-value
name-value ( name | value
relational-oper ( = | |= | | >=
name ( letter ( letter | digit )*
value ( integer-value | real-value
integer-value ( digit ( digit )*
real-value ( digit ( digit )*. digit ( digit )*
Note: The tokens in bold are reserved words or standard identifiers (library functions or procedures).
Write an a recursive descent parser for the above grammar.
* Use only Java as a host language.
* You should work individually only, any signs of cheating will be penalized severely.
* Your program will be tested with my text files (programs), either it works correctly or doesnt.
* No programs will be accepted after the deadline for any reason whatsoever.
* In the ERROR function, report the error clearly and precisely showing the line and token
image text in transcribed
lavenage: block name . module-heries at medule same : Mlock berin stme-lina ced Aeclarations coneded va-dect constlist a (nume - value ; ) var-dect a var var-lis if 1 var-liat a (var-item ; ) var-ifem namelist : detatyse name-lias a name (,marne)+ dato-type inteser | real | char procedure-dect a procedare-beafing decturutions block name : provodure-beading a procidere narse : stme 1 ass-stmr d name :- exp exp term (addernor term ) torm a factor (mul-opor faction ) add-eper a * | . mul-oper a * | I | mod | fir name-liat "r" list n) writechar "T" writelist"Y =ritieln write-item a name 1 value cad else-part al whe inselint || while-strmt al while conditioe be itmethat end exit-stme di cuit namevaluc name | valar relaticel-oper a - +10 name lenter ( latter | digit ) value at integer-valos | seal-value integer-value at digit ( Aigit ) real-value da dipit (digit ), dipit ( Sipit ) Nete: The wolets in bold are ncicriod wunds or standard identifiers (library functions oe peecedares). - Use only Java as a host lanpuags * Yoe should work individuallv ooly, any vigms of cheatits will be penalized scructely. it worls comectly or doesi't - No programs will be accepted after the deadline for aby reason whatseever. - In the ERROR function, repoet the erner clearly and procisely showing the line and tokes whore the Frror occurs and exit the peopram (panic mode) error handling. Project-F23* ea Ritaj wclb page

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

=+f. Audience Engagement encourage consumer participation.

Answered: 1 week ago

Question

=+d. Emotional Approach appeal to consumers' emotions.

Answered: 1 week ago