# Precedence Table Construction Algorithm for CFGs Regardless of Being OPGs
## 4 Approach
### Problem Analysis
#### 4.2.3 An Intuitive Way to Observe the Elements of Each Set  
**Vision of Left(\(\cdot\)):**  
Given the CFG:  
\(A\longrightarrow CDE\)  
\(E\longrightarrow eh\)  
\(D\longrightarrow d\)  
\(C\longrightarrow cF\)  
\(F\longrightarrow f\)  
The rightmost derivation of the string \(cfdeh\) carries the following way of creating the \(Left(A)\) or \(\mathcal{L}(A)\).  
\[A\Longrightarrow\underset{\lessdot}{\lessdot}CDE\Longrightarrow CDeh \Longrightarrow Cdeh\Longrightarrow cFdeh\Longrightarrow cfdeh.\]  
The terminal symbols \(e\), \(d\), and \(c\) are viewed from the left and recorded in \(\mathcal{L}(A)\). The symbol \(e\) is the first one seen from the left and is recorded in \(\mathcal{L}(A)\), and the symbol \(h\) is blocked by \(e\) since both appear when \(E\) is substituted. Then, \(D\) is replaced by \(d\), which is observed and recorded in \(\mathcal{L}(A)\). When \(cF\) replaces \(C\), we observe and record \(c\) in \(\mathcal{L}(A)\). Finally, when the substitution of \(F\) by \(f\) is carried out, it can no longer be observed (blocked by \(c\)) and cannot be registered. Consequently:  
\[\mathcal{L}(A)=\{e,d,c\}.\]  
**Vision of Right(\(\cdot\)):**  
Given the CFG:  
\(A\longrightarrow abBC\)  
\(B\longrightarrow eF\)\(C\longrightarrow cD\)  
\(D\longrightarrow d\)  
\(F\longrightarrow f\)  
The rightmost derivation of the string \(abefcd\) carries the following way of creating the \(Right(A)\) or \(\mathcal{R}(A)\).  
\(A\Longrightarrow a\mathbf{b}BC\Longrightarrow abB\mathbf{c}D\Longrightarrow abB \mathbf{c}\mathbf{d}\Longrightarrow ab\mathbf{e}Cd\Longrightarrow ab \mathbf{e}\mathbf{f}cd\).  
\(b\)\(c\)\(d\)\(\geqslant\)  
The terminal symbols \(b\), \(c\), and \(d\) are viewed from the right and recorded in \(\mathcal{R}(A)\). The symbol \(b\) is the first one observed and recorded in \(\mathcal{R}(A)\). The symbol \(a\) is blocked by \(b\), since both appear when \(A\) is derived. \(C\) is then replaced by \(cD\) and \(c\) is observed and recorded in \(\mathcal{R}(A)\). When \(D\) is substituted for \(d\), we observe and record \(d\) in \(\mathcal{R}(A)\). Then \(B\) is derived by \(eF\) but \(e\) cannot be recorded since the previous inclusion of \(c\) and \(d\) in \(\mathcal{R}(A)\) makes it invisible or blocks it from being observed from the right. Finally, when substituting \(F\) for \(f\), it cannot be observed from the right either (blocked by \(c\) and \(d\)) and cannot be recorded. Consequently:  
\(\mathcal{R}(A)=\{b,c,d\}\).  
**Vision of Leftmost(\(\cdot\)):**  
Given the CFG:  
\(S\longrightarrow dAB\)  
\(A\longrightarrow fa\)  
\(B\longrightarrow Cb\)  
\(C\longrightarrow c\)  
The rightmost derivation of the string \(dfacb\) carries the following way of creating the \(Leftmost(B)\) or \(\mathcal{L}_{m}(B)\), as shown in Figure 1.  
It can be seen that \(\mathcal{L}(B)=\{b,c\}\). When \(B\) derivates \(Cb\), we observe that \(\mathcal{L}_{m}(B)=\{b\}\) because no more terminal symbols are seen up to that point. In the following derivation, \(C\) is replaced by \(c\); therefore, \(c\) is located further to the left of the substring \(cb\), leaving \(\mathcal{L}_{m}(B)=\{c\}\).  
Figure 1: Derivation of \(dfacb\) chain and \(Leftmost(B)\) set creation sequence.