I was preparing for my exam and have some questions that can possibly come on the test. There is a task to make pushdown automata from a given code:
void compile_while() {
// while ( expression )
if (symbol == SYM_WHILE) {
get_symbol();
if (symbol == SYM_LPARENTHESIS) {
get_symbol();
compile_expression();
if (symbol == SYM_RPARENTHESIS) {
get_symbol();
// zero or more statements: { statement }
if (symbol == SYM_LBRACE) {
get_symbol();
while (is_not_rbrace_or_eof())
compile_statement();
if (symbol == SYM_RBRACE)
get_symbol();
else {
syntax_error_symbol();
exit(EXITCODE_PARSERERROR);
}
} else
// only one statement without {}
compile_statement();
} else
syntax_error_symbol();
} else
syntax_error_symbol();
} else
syntax_error_symbol();
}
First of all, I don't understand why we need to construct PDA for it because we can do it without stack too and second, I don't understand how the pushdown automata for it would look like.
Can someone help me to understand this task and show me how the PDA for it looks like?
while
statement includes anotherwhile
statement. $\endgroup$ – rici Jan 30 '20 at 1:38