0% found this document useful (0 votes)
119 views4 pages

Switch - STMT Expr (

The document describes a switch statement syntax with keywords like switch, case, default, and expressions that can be used in the statement. It includes the statement structure with parentheses and curly braces. Cases and the default case can contain blocks of statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views4 pages

Switch - STMT Expr (

The document describes a switch statement syntax with keywords like switch, case, default, and expressions that can be used in the statement. It includes the statement structure with parentheses and curly braces. Cases and the default case can contain blocks of statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

switch_stmt

switch

case

expr

literal

default

stmt_list

stmt_list

3.
(a) <assign> => <id> := <expr>
=> A := <expr>
=> A := <id> * <expr>
=> A := A * <expr>
=> A := A * ( <expr> )
=> A := A * ( <id> + <expr> )
=> A := A * ( B + <expr> )
=> A := A * ( B + ( <expr> ) )
=> A := A * ( B + ( <id> * <expr> ) )
=> A := A * ( B + ( C * <expr> ) )
=> A := A * ( B + ( C * <id> ) )
=> A := A * ( B + ( C * A ) )

25

<assign>

<id>

:=

<expr>

<id>

<expr>
(

<id>

(expr) )

<expr>

( <expr> )

<id>

<expr>
<id>

4.
(a) <assign> => <id> := <expr>
=> A := <expr>
=> A := <term>
=> A := <factor> * <term>
=> A := ( <expr> ) * <term>
=> A := ( <expr> + <term> ) * <term>
=> A := ( <term> + <term> ) * <term>
=> A := ( <factor> + <term> ) * <term>

26

=> A := ( <id> + <term> ) * <term>


=> A := ( A + <term> ) * <term>
=> A := ( A + <factor> ) * <term>
=> A := ( A + <id> ) * <term>
=> A := ( A + B ) * <term>
=> A := ( A + B ) * <factor>
=> A := ( A + B ) * <id>
=> A := ( A + B ) * C
<assign>
<id>

:=

<expr>

<term>
<factor>

<expr>

<expr>

<term>
<factor>

<term>

<id>

<term>

<factor>

<factor>

<id>

<id>

27

5. The following two distinct parse tree for the same string prove that the grammar is
ambiguous.

<A>
<A>

<S>

<S>

<A>

<A>

<A>

<A>

<A>
b

<A>
<A> +

<A
c

6. Assume that the unary operators can precede any operand. Replace the rule
<factor> <id>
with
<factor> + <id>
| - <id>

7. One or more a's followed by one or more b's followed by one or more c's.
10. S a S b | a b
11.
S

28

You might also like