Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming language grammar

I have this question in a Compilers coursework but I don't really know how to approach it. Could anyone please give me a better hint than what was given in the rubric?

Show that all binary strings generated by the following grammar have values divisible by 3.

Hint: use induction on the numerical values for nodes in the parse tree.

num -> 11 | 1001 | num 0 | num num
like image 717
Sorin Cioban Avatar asked Dec 22 '25 11:12

Sorin Cioban


1 Answers

Here are two hints:

  1. Appending a 0 to a binary representation is equivalent to multiplication by 2.

  2. Appending a binary representation to itself is equivalent to multiplication by 2^N + 1.

like image 184
Oliver Charlesworth Avatar answered Dec 24 '25 11:12

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!