a) Give a Backus-Naur Form (BNF) grammar for Java integer literals (decimal, hexa, octal).
b) Show a BNF grammar that is ambiguous.
c) Is a BNF able to express “the maximum of a byte literal is 127” ? Why or why not?
a)
This is the BNF Grammar for Java Literals. Although the question has asked for integer literals only, other literals (floating-point, boolean, character, string etc.) have been added for completeness and clarity.
b)
This grammar is ambiguous because the string yyxzx can have either of these two parse trees:
c)
A BNF Grammar will not be able to express "the maximum of a byte literal is 127" because it cannot count. A BNF Grammar can only tell if a particular string is part of the grammar or not. There is nothing limiting the recurrence at 127 or for that matter any number. This may not cause a problem during compilation, however the code will be buggy because of this error during execution.
a) Give a Backus-Naur Form (BNF) grammar for Java integer literals (decimal, hexa, octal). b) Show...
Please answer the questions below: 7. Rewrite the following BNF grammar using the form of EBNF described on the bottom half of page 127 in Sebesta. <import_decl> → import <import_list> ; <import_list> → <package_list> | <package_list> . * <package_list> → <identifier> | <package_list> . <identifier> <identifier> → a | b | c Make the resulting grammar as simple as possible, but keep all four of the original nonterminals, which will now be named ImportDecl, ImportList, PackageList, and Identifier. (Note: There...
(b) Using the Davis-Putnam-Logemann-Loveland (DPLL) algorithm, determine whether the following formula is satisfiable. Show each step. [3 marks] (c) Give an example of a conjunctive normal form (CNF) formula where the pure literal rule can be applied, but the unit propagation rule cannot. The formula must have at least 3 clauses. [3 marks
(b) Using the Davis-Putnam-Logemann-Loveland (DPLL) algorithm, determine whether the following formula is satisfiable. Show each step. [3 marks] (c) Give an example of a conjunctive normal form...