directed-acyclic-graphscompiler-constructiontac

what will be the LR(1) itemset of the following grammar?


I need to construct the clr parser for the following grammar:

E->E+T|T
T->T*F|F
F->(E)|id

I am confused what will the look aheads will be. I have tried to solve the first few item sets but something seems to be wrong.


Solution

  • Hope this helps After the comma is the lookahead and / means multiple lookaheads

    I0: E'-> .E,$
        E->.E+T,$/+
        E->.T, $/+
        T->.T*F, $/+/*
        T->.F, $/+/*
        F->.id, $/+/*
    
    I1: E->T., $/+
        T->T.*F, $/+/*
    
    I2: T->F., $/+/*
    I3: F->id., $/+/*
    I4: E'->E., $
        E->E.+T, $/+
    I5: E->E+.T, $/+
        T->.T*F, $/+/*
        T->.F, $/+/*
        F->.id, $/+/*
    I6: E->E+T., $/+
        T->T.*F, $/+/*
    I7: T->T*.F, $/+/*
        F->.id, $/+/*
    I8: T->T*F., $/+/*
    

    If I have missed out something then leave a comment so we can fix it together