Wirth–Weber precedence relationship explained

In computer science, a Wirth–Weber relationship between a pair of symbols

(Vt\cupVn)

is necessary to determine if a formal grammar is a simple precedence grammar. In such a case, the simple precedence parser can be used. The relationship is named after computer scientists Niklaus Wirth and Helmut Weber.

The goal is to identify when the viable prefixes have the pivot and must be reduced. A

\gtrdot

means that the pivot is found, a

\lessdot

means that a potential pivot is starting, and a
eq
means that a relationship remains in the same pivot.

Formal definition

G=\langleVn,Vt,S,P\rangle

\begin{align} X

eq

Y&\iff\begin{cases}A\to\alphaXY\beta\inP\A\inVn\\alpha,\beta\in(Vn\cup

*
V
t)

\X,Y\in(Vn\cupVt)\end{cases}\\ X\lessdotY&\iff\begin{cases}A\to\alphaXB\beta\inP\B+Y\gamma\A,B\inVn\\alpha,\beta,\gamma\in(Vn\cup

*
V
t)

\X,Y\in(Vn\cupVt)\end{cases}\\ X\gtrdotY&\iff\begin{cases}A\to\alphaBY\beta\inP\B+\gammaX\Y*a\delta\A,B\inVn\\alpha,\beta,\gamma,\delta\in(Vn\cup

*
V
t)

\X,Y\in(Vn\cupVt)\a\inVt\end{cases}\end{align}

Precedence relations computing algorithm

We will define three sets for a symbol:

\begin{align} Head+(X)&=\{Y\midX+Y\alpha\}\\ Tail+(X)&=\{Y\midX+\alphaY\}\\ Head*(X)&=(Head+(X)\cup\{X\})\capVt \end{align}

The pseudocode for computing relations is:

A\to\alpha\inP

X

eq

Y

)

X\lessdotHead+(Y)

)

Tail+(X)\gtrdotHead*(Y)

)

\$\lessdotHead+(S)

) where is the initial non terminal of the grammar, and $ is a limit marker

Tail+(S)\gtrdot\$

) where is the initial non terminal of the grammar, and $ is a limit marker

Examples

Example 1

S\toaSSb|c

S\toaSSb

a

eq

S

a\lessdotHead+(S)

a\lessdota

a\lessdotc

S

eq

S

S\lessdotHead+(S)

S\lessdota

S\lessdotc

Tail+(S)\gtrdotHead*(S)

b\gtrdota

b\gtrdotc

c\gtrdota

c\gtrdotc

S

eq

b

Tail+(S)\gtrdotHead*(b)

b\gtrdotb

c\gtrdotb

S\toc

precedence table:

\begin{array}{c|ccccc} &S&a&b&c&\$ \\ \hlineS&

eq

&\lessdot&

eq

&\lessdot&\ a&

eq

&\lessdot&&\lessdot&\ b&&\gtrdot&\gtrdot&\gtrdot&\gtrdot \ c&&\gtrdot&\gtrdot&\gtrdot&\gtrdot \ \$&&\lessdot&&\lessdot&\end{array}

Example 2

S\toa|aT|[S]

T\tob|bT