Context Free Grammar clarification

60 views Asked by At

I created the following grammar for a minishell, but i realized that the parser never goes to command_p, it only stays at cmd_prefix. Can somebody please clarify for me since i've seen a similar grammar in the official shell grammar

command         : cmd_prefix command_p
                ;

command_p       : cmd_name cmd_suffix command_p
                | ε
                ;

cmd_prefix      : io_redirect cmd_prefix
                | word cmd_prefix
                | ε
                ;

cmd_name        : word
                ;

cmd_suffix      : io_redirect cmd_suffix
                | word cmd_suffix
                | ε
                ;

I tried to make a simpler grammar than the official shell grammar for Recursive Descent parser, but later on i found out that maybe there is no need for the other rules since cmd_prefix keeps calling itself recursively.

0

There are 0 answers