Question: Consider the following grammar. - > a | b | c And the following operational semantics as a translation

Consider the following grammar.
->"a"|"b"|"c"
And the following operational semantics as a translation (written in Psudocode).
translate(A){
println("x=0")
translate_A(A)
}
translate_A(A){
if A.child[0]== a {
println("x=x+1")
translate_A(A.child[1])
} else if A.child[0]== b {
println("print_with_newline(x)")
} else if A.child[0]== c {
println("print_with_newline(-x)")
}
}
What is printed when running the program aaab?
-2
-3
2
3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!