Question 1-2

Consider the following Ada code, based on the parser of Project 1.

procedure Parse is
begin
    case Token.Category is
    when A =>
        Chomp(A);
        while(Token.Category == A) Chomp(T_A);
        parse;
        Chomp(T_B);
        while(Token.Category == B) Chomp(T_B);
        parse;
    when B =>
        Chomp(B);
        Chomp(T_B);
        Parse;
        Chomp(T_A);
        Parse;
    when C =>
        Chomp(C);
    default:
        Put_Line("unexpected token: expected A, B, or C");
        raise Parse_Error;
    end case;
end Parse;
Give an EBNF grammar describing what language this function accepts. Your grammar should have only one nonterminal (name it S) and three nonterminals, A, B, and C.

Solution

S -> A {A} S B {B} S | B S A S | C

Program proofs

Back to Review for Quiz 1