retagged by
1,295 views
0 votes
0 votes

retagged by

1 Answer

0 votes
0 votes

Given Grammar = 

S -> a | ^ | ( T )

T -> T , S | S

(b) .

Leading (S) =  Leading ( T ) =  {" a" , " ^"  , "  (  "

Trailing ( S) =  Trailing  ( T )  =  {  " )  " ,   " , (comma) "  , "  $  "  }

(c)  Precedence of operators =>

       Assuming here only two operators. 1. ^ 2. ,(comma).

       Precedence of , ( comma ) operator is greater than ^ operator.   

(a)  Given string S = ( ( ( a , a , ^ , (a) ) , a ).

  I think, The given string is not correct. Because,  it does not follow balanced parentheses.

 So, I am assuming it as S = ( ( a , a , ^ , (a) ) , a )

Now, lets see all shift and reduce steps.

  S - > ( T )                                    // shift = > S -> ( T)   

  S  - > ( T , S )                              // shift  = > T - > T , S

  S  ->  ( T , a )                              // reduction => S -> a

  S  - > ( S , a)                               // shift => T -> S

  S  - > ( ( T ) , a)                            / / shift  => S -> ( T )

  S  -> (  T , S )  , a )                       // shift =>  T - > T , S

  S  -> ( ( T , ( T ) ) , a)                     // shift  => S -> ( T )

  S  -> ( ( T , ( S ) ) , a)                     //  shift   => T -> S

  S  -> ( ( T , ( a ) ) , a)                     //reduction => S -> a  

  S  -> ( ( T , S , ( a ) ) , a)                // shift =>  T - > T , S

  S  -> ( ( T , ^ , ( a ) ) , a)                 //reduction => S -> ^

  S  -> ( ( T , S , ^ , ( a ) ) , a)            // shift =>  T - > T , S

  S  -> ( ( T , a , ^ , ( a ) ) , a)             //reduction => S -> a

  S  -> ( ( S , a , ^ , ( a ) ) , a)             //  shift   => T -> S

  S  -> ( ( a , a , ^ , ( a ) ) , a)              // reduction => S -> a

  

Correct me if I am wrong  .. 

Related questions

1 votes
1 votes
2 answers
1
0 votes
0 votes
1 answer
2