Question 1-1

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

procedure Parse_Term is
begin
    if Token.Category = Ident then
        Chomp(Ident);
    else
        Chomp(Num);
    end if;
end Parse_Term;

procedure Parse_Expr is
begin
    if Token.Category = Semi then
        Chomp(Semi);
    else
        Parse_Term;
        Chomp(Plus);
        Parse_Expr;
    end if;
end Parse_Expr;
Give an BNF grammar that describes the language that Parse_Expr accepts. The terminals of the language are PLUS, SEMI, IDENT, and NUM.

Solution

expr -> SEMI | term PLUS expr

term -> IDENT | NUM

Back to Review for Quiz 1