Consider the following grammar
S -> a + A
A -> (S)
A -> a
If we want to write a recursive descent parser for the above grammar then which one of the
following functions will correctly represent production A?
(NOTE: The match ( ) is a function which matches the next token in the parsing with the
current terminal derived in the grammar and advancing the i/p pointer to the next token)
(A) A( )
{
if next_token = = ‘(’ && ‘)’ {
S ( );
Else
match(‘a’);
}
(B) A( )
{
if next_token = = ‘(’ {
match(‘(’);
S ( );
match (‘)’);
else
if next_token = = ‘a’ {
match(‘a’)
}
else error ( );
}
(C) A( )
{
if next_token = = ‘)’ || ‘a’
match(‘(’);
S( );
match(‘)’);
else error( );
}
(D) None of these