The Pairwise disjoint test is used to check whether a grammar is LL grammar or not. The test is used to determine whether the RHS can be chosen using single token. If the grammar fails the pairwise disjoint test then the grammar cannot be used to create a top-down parser with one lookahead. For checking whether a grammar rule follows the pairwise disjointness test we need to find the FIRST for each production and if the answers are disjoint then the production passes the test.
a) For A -> aB|eAb|cBb
FIRST(aB) = a
FIRST(eAb) = e
FIRST(cBb) = c
This answers don't intersect and hence passes the test.
b) For B->dB|c
FIRST(dB) = d
FIRST(c) = c
This answers don't intersect and hence passes the test.
24. State if the following grammar rules as a group passes the pairwise disjointness test and...
Q5: (20 points) Consider the following grammars T → int | float L → L,id I id a) Perform the pairwise disjointness test for grammar (I). b) Is grammar (I) LL1 grammar? Why? Consider the grammar (II) and the input string "int id, id; ", show the content of the Stack of the Shift-Reduce algorithm. Is it conflict-free and why? c)
Consider the following grammar: A -> aB | b | cBB B -> aB | bA | aBb C -> aaA | b | caB Perform the pairwise disjoint test for the grammar. Rewrite the above grammar so that all grammar rules pass the pairwise disjoint test. Suppose lex() is the lexical analyzer which gets the next lexeme and puts its token code in the global variable nextToken. And suppose the token codes for terminals a, b, and c are...
Consider the following context free grammar. Write an attribute grammar that specifies the calculation rules, i.e. how the value of E or T is calculated. There is no need to perform type checking. We assume all types are matched correctly. Please clearly specify the type of attribute(s) you introduce, i.e. synthesized, inherited, or intrinsic. E ::= E + T | T T ::= T * F | F F ::= NUM NUM ::= 1 | 2 | 3 | 4...
The following context-free grammar (CFG) generates palindromes. This CFG has the following rules: S → ε, S → a, S → b, ..., S → z, S → aSa, S → bSb, ..., S → zSz. On an example of a palindrome cattac, show, step-by-step, how this palindrome will be generated by this grammar.
Class 37 1. The state diagram below is designed to output four values in sequence according to the following rules: W-2 passes through the sequence at double-speed, W-1 passes through the sequence at normal speed, and W-o causes the output to remain unchanged. Assume that W-3 cannot occur. 1 2 1 2 10000C a. (15 points) Draw the state table for this state diagram. b. (10 points) Use the following state assignments. A:00, B 01, c-10, D:11. Draw the state-assigned...
Consider the following grammar G, whose productions rules are the following (an upper case letters represents a nonterminal symbol, a lower case letter represents a terminal symbol). Untitled Note Eile Edit Format View Help S -asCB A b A -aA C B d A Which of the following sentences are in the language generated by the grammar G? |Untitled - Notepad X Eile Edit Format View Help А. асcbd B. abcd c. acccbcc D. acd Е. ассс F. CCC G....
Using the algorithm described in Section 4.4.2, remove direct left recursion form the following grammar rules. A → Aa | Abc | bc | d
Consider the following grammar: (//some alternative rules are listed on separate lines without using symbol |): stmt −> assignment −> subr call assignment −> id := expr subr call −> id ( arg list ) expr −> primary expr tail expr tail −> op expr −> ε primary −> id −> subr call −> ( expr ) op −> + | - | * | / arg list −> expr args tail args tail −> , arg list −> ε...
please provide good explanation.
Consider the following grammar for variable and class
declarations in Java:
<Decl> -> <VarDecl>
| <ClassDecl>
<VarDecl> -> <Modifiers> <Type> <VarDec> SEM
<ClassDecl> -> <Modifiers> CLASS ID LBRACE <DeclList> RBRACE
<DeclList> -> <Decl>
| <DeclList> <Decl>
<VarDec> -> ID
| ID ASSIGN <Exp>
| <VarDec> COMMA ID
| <VarDec> COMMA ID ASSIGN <Exp>
Indicate any problems in this grammar that prevent it from being
parsed by a recursive-descent parser with one token lookahead. You
can simply...
Compute CLR-1 and LALR-1 Table of following grammar, Analyze the table and find, if there are any conflicts?? If YES, what type of conflicts are they?? Also parse following input along semantic rules by showing stack state while parsing. a id bi id * + [CLO-4, PLO-36] (10+4) S→SE+|Ef|F { print top of stack 2 times} E→EE*|F {if top of stack is E , print Good, else print Bad } F→aF|bi|id {print how many elements are there in stack}