Using the syntax of C, write a recursive-descent subprogram that corresponds to
ID: 3675005 • Letter: U
Question
Using the syntax of C, write a recursive-descent subprogram that corresponds to the following EBNF rule:
<package_decl> --> { <package_modifier> } package <identifier> { . <identifier> } ;
In this rule, { and } are metasymbols. You may assume that the lex function reads a single lexeme, whose token code is left in the nextToken variable. Assume that the codes for the package, period, and semicolon tokens are PACKAGE_CODE,
PERIOD_CODE, and SEMICOLON_CODE, respectively. Have your function call the error function if it detects an error.
Explanation / Answer
C-Style Syntax is given below:
int package_decl()
{
//"{"
int successCondition = bracesOpen();
if(successCondition)
{
//{ <package_modifier> }
if(successCondition == package_modifier())
{
{ . <identifier> }
if(successCondition == identifier())
{
successCondition = identifier() && bracesClose();
}
}
}
return successCondition;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.