I am currently working on a problem that is asking me to write the grammar productions for the try-catch-finally and throw C# statements. It states that "you can assume that there are nonterminals "Type", "Expression", and "Statement", as well as a terminal "Ident". I do not understand how this is possible using so few nonterminals and only one terminal

  • 1
    $\begingroup$ Welcome to Computer Science! What have you tried? Where did you get stuck? We do not want to just hand you the solution; we want you to gain understanding. However, as it is we do not know what your underlying problem is, so we can not begin to help. See here for tips on asking questions about exercise problems. If you are uncertain how to improve your question, why not ask around in Computer Science Chat? $\endgroup$ – Raphael Sep 28 '16 at 6:18

You need more terminals, for the reserved words try, catch, finally, and throw, and possibly for braces and for semicolon (depending on the interpretation of Statement).

Here is an example to help you get started. It gives the syntax of a simple if statement, assuming that Statement also includes compound statements (i.e. { ... }), and that statements do not end in a semicolon.

IfStatement → if ( Expression ) Statement


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.