Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given the following grammar of Propositional Logic written in Extended B

ID: 3697392 • Letter: Y

Question

You are given the following grammar of Propositional Logic written in Extended Backus -Naur Form (EBNF). GRAMMAR: ::= []+ ::= "=,' | | ::= | ::= | Do one of the following for our parsing purpose Design and implement a Recursive Descent LL Parser program in C programming language that can parse and generate a trace of given EBNF statements and also the parse tree. Use ANTLR LL(*) based Parser Generator and produce a JAVA parser code that distinguishes correct and incorrect sentences of the grammar and generate parse tree, automatically.

Explanation / Answer

Answer:

typedef enum {identifir, number, leftparenthesis, rightparenthesis, times, slit, addsymbol,

substractsymbol, equl, notequal, less, lessthanequal, greater, greaterthanequal, requestsymbol, startsymbol, semicolonsymbol,
endsymbol, ifsymbol, whilesymbol, makes, thensymbol, dosymbol, constsymbol, commasymbol,
uniquesymbol, funcsymbol, period, oddsymbol} Notation;

Notation symbol;
void picksymbol(void);
void exception(const char message[]);
void statement(void);

int allow(Notation s) {
if (symbol == s) {
picksymbol();
return 1;
}
return 0;
}

int assume(Notation s) {
if (allow(s))
return 1;
exception("expect: unassumed symbol");
return 0;
}

void multiply(void) {
if (allow(identifir)) {
;
} else if (allow(number)) {
;
} else if (allow(leftparenthesis)) {
statement();
assume(rightparenthesis);
} else {
exception("factor: syntax error");
picksymbol();
}
}

void stage(void) {
multiply();
while (symbol == times || symbol == slit) {
picksymbol();
multiply();
}
}

void statement(void) {
if (symbol == addsymbol || symbol == substractsymbol)
picksymbol();
stage();
while (symbol == addsymbol || symbol == substractsymbol) {
picksymbol();
stage();
}
}

void check(void) {
if (allow(oddsymbol)) {
statement();
} else {
statement();
if (symbol == equl || symbol == notequal || symbol == less ||
symbol == lessthanequal || symbol == greater || symbol == greaterthanequal) {
picksymbol();
statement();
} else {
exception("check:valid operator");
exception("check: invalid operator");
picksymbol();
}
}
}

void statement(void) {
if (allow(identifir)) {
assume(makes);
statement();
} else if (allow(requestsymbol)) {
assume(identifir);
} else if (allow(startsymbol)) {
do {
statement();
} while (allow(semicolonsymbol));
assume(endsymbol);
} else if (allow(ifsymbol)) {
check();
assume(thensymbol);
statement();
} else if (allow(whilesymbol)) {
check();
assume(dosymbol);
statement();
}
}

void disallow(void) {
if (allow(constsymbol)) {
do {
assume(identifir);
assume(equl);
assume(number);
} while (allow(commasymbol));
assume(semicolonsymbol);
}
if (allow(uniquesymbol)) {
do {
assume(identifir);
} while (allow(commasymbol));
assume(semicolonsymbol);
}
while (allow(funcsymbol)) {
assume(identifir);
assume(semicolonsymbol);
disallow();
assume(semicolonsymbol);
}
statement();
}

void application(void) {
picksymbol();
disallow();
assume(period);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote