Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give a context free grammar for a small part of any popular computer language. T

ID: 3629461 • Letter: G

Question

Give a context free grammar for a small part of any popular computer language. The definition should be between 10 and 20 rewrite rules. Give a reference stating the source of your grammar.

Explanation / Answer

int a, c; c = 10; a = c; if( a < 10 ) { c = 12; } then { a = 1; c = 10; } How do we write a rule? Consider the standards for HTML and the like: http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-Name What is considered a proper variable name in C, C++, or Java? * cannot start with numbers. * cannot have spaces. The build out from there. What is a valid constant expression? "...", '.', 324234, 324234l, 0x23423, etc. What about arithmetic operations +,-,*,/,%. Parenthesis? Now, a think of a statement. It must end in a ; Multiple statements must be in a block (e.g. { ... } ) If you run out of things, write rules for if/then/else, do/while, while, try/catch/finally. You'll be to 20 in no time. Here's a start. StartingChar --> [A-Z,a-z] AnyChar --> StartChar | [0-9,_,] Variable --> StartingChar AnyChar+ WhiteSpace --> ' ' | ' ' | ' ' . . . IfStructure --> 'if' WhiteSpace '(' Expression ')' WhiteSpace GroupOfStatements What would 'Expression' be defined as? How would you define 'GroupOfStatements' ? Perhaps: Statement ';' | '{' WhiteSpace* Statement WhiteSpace* '}' Recall that X+ means 1 or more of X. X* means 0 or more of X. Hope this starts you in the right dire
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote