Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested

Question:

Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples:

abs := n

if n < 0 then abs := 0 - abs fi


sum := 0

read count

while count > 0 do

        read n
        sum := sum + n
        count := count - 1
od

write sum

Your grammar should support the six standard comparison operations in conditions, with arbitrary expressions as operands. It should also allow an arbitrary number of statements in the body of an if or while statement.

Figure 2.25:

+ stmtlist $$ stmt_list stmt list stmt stmt list stmt program stmt id := expr stmt + read id stmt write expr expr term expr expr add_op term term + factor term → term mult op factor factor → ( expr ) factor → id factor number add op +

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: