I am studying the Dragon Book about compilers and it has exercises which I try to solve. Unfortunately, there is no-one nearby who could check my solutions. Is it appropriate to post my solutions here asking someone experienced to check them?

Some of the exercises do not require writing code (like this):

Exercise 2.2.1:
Consider the context-free grammar S -> S S + | S S * | a

a) Show how the string aa+a* can be generated by this grammar.
b) Construct a parse tree for this string.
c) What language does this grammar generate? Justify your answer.

Example of the answer

a) Show how the string aa+a* can be generated by this grammar.

  1. Let S1 = a according to the 3-rd production.
  2. From the 1-st production we get: S2 -> S1 S1 + => S2 = aa+
  3. From the 2-nd production: S3 -> S2 S1 * => S3 = aa+a*

We got the required string S3 using the rules of the grammar.

  • 3
    \$\begingroup\$ Can you provide an example of the answer(s)? I'm pretty sure the answers will not contain any code, and so will not be on-topic on Code Review. However, I may be surprised. \$\endgroup\$
    – Peilonrayz Mod
    Mar 12 at 8:09
  • \$\begingroup\$ @Peilonrayz Done. Please, look. \$\endgroup\$
    – user4035
    Mar 12 at 8:36
  • 4
    \$\begingroup\$ The example is certainly not code, so certainly outside the scope of Code Review. Consider having a look at the Help Centre and/or Meta of Software Engineering to see whether that's an appropriate venue. \$\endgroup\$ Mar 12 at 9:26
  • 1
    \$\begingroup\$ Thank you. To a degree I think you are asking a 2-in-1 question -- is non-code on-topic on Code Review, and is reviewing answers on-topic. The former question is clear cut, non-code is not on-topic on Code Review. However, the second question isn't clear cut. If you can provide a Q&A from the book where the answer is 100% obviously code, then I think we could answer the second. However, if you are only interested in non-code Q&A, pivoting the question to focus on the second is probably not helpful. \$\endgroup\$
    – Peilonrayz Mod
    Mar 12 at 9:26
  • \$\begingroup\$ @TobySpeight Maybe, move this question to meta of Software Engineering, so I won't need to duplicate it there? Or should I duplicate? \$\endgroup\$
    – user4035
    Mar 12 at 11:02
  • 1
    \$\begingroup\$ @user4035 IIRC Code Review has little to no migration paths. You like need a moderator to migrate your post. I would recommend you manually duplicate the post if you want to post on Software Engineering; I don't know the sites scope (whether your question is already answered), and I think CR should keep a record of the question. \$\endgroup\$
    – Peilonrayz Mod
    Mar 12 at 18:27
  • \$\begingroup\$ The (red) dragon book = Compilers: Principles, Techniques, and Tools \$\endgroup\$ Mar 15 at 5:03


You must log in to answer this question.

Browse other questions tagged .