Suppose we wanted to change our requirement that you have had under discussion in the following way:
In <cond> the same identifier cannot be used more than once. In other words, the previous modification to would have allowed the following: [(X>=Y+Z) and (U < X)]
This would have been allowed because although X appears twice in the <cond> it only appears once in each <comp> that makes up the <cond>. Under our new requirement above, this <cond> would not be allowed because X appears more than once across the entire <cond>. Answer the following question:
When is the earliest we can catch a violation of this altered requirement and produce an error? In other words, is this requirement regular (can be caught by the Tokenizer), context-free (can be built into the grammar itself), context-sensitive (can be caught before the execution phase, but only after obtaining more context than what is in the grammar itself) or runtime (can only be found as a runtime error while the CORE program is being executed)? Select one of the options from the list and provide a short (2-5 sentence) justification for your choice.
The violation can be caught by using Context-free grammar. Since, the grammar can be used as a way to disambiguate words, phrases, etc., the identifier can be built into the Grammar itself.
Context-free grammars can generate context-free languages. They do this by taking a set of variables which are defined recursively, in terms of one another, by a set of production rules.These rules can be applied regardless of context.
CFGs are used to describe the structure of sentences and words in natural language. They are also used in the Document Type of the Extensible Markup Language(XML)
Get Answers For Free
Most questions answered within 1 hours.