Wirth–Weber precedence relationship

(Learn how and when to remove this message)

In computer science, a Wirth–Weber relationship between a pair of symbols ( V t V n ) {\displaystyle (V_{t}\cup V_{n})} 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 {\displaystyle \gtrdot } means that the pivot is found, a {\displaystyle \lessdot } means that a potential pivot is starting, and a {\displaystyle \doteq } means that a relationship remains in the same pivot.

Formal definition

G = V n , V t , S , P {\displaystyle G=\langle V_{n},V_{t},S,P\rangle }
X Y { A α X Y β P A V n α , β ( V n V t ) X , Y ( V n V t ) X Y { A α X B β P B + Y γ A , B V n α , β , γ ( V n V t ) X , Y ( V n V t ) X Y { A α B Y β P B + γ X Y a δ A , B V n α , β , γ , δ ( V n V t ) X , Y ( V n V t ) a V t {\displaystyle {\begin{aligned}X\doteq Y&\iff {\begin{cases}A\to \alpha XY\beta \in P\\A\in V_{n}\\\alpha ,\beta \in (V_{n}\cup V_{t})^{*}\\X,Y\in (V_{n}\cup V_{t})\end{cases}}\\X\lessdot Y&\iff {\begin{cases}A\to \alpha XB\beta \in P\\B\Rightarrow ^{+}Y\gamma \\A,B\in V_{n}\\\alpha ,\beta ,\gamma \in (V_{n}\cup V_{t})^{*}\\X,Y\in (V_{n}\cup V_{t})\end{cases}}\\X\gtrdot Y&\iff {\begin{cases}A\to \alpha BY\beta \in P\\B\Rightarrow ^{+}\gamma X\\Y\Rightarrow ^{*}a\delta \\A,B\in V_{n}\\\alpha ,\beta ,\gamma ,\delta \in (V_{n}\cup V_{t})^{*}\\X,Y\in (V_{n}\cup V_{t})\\a\in V_{t}\end{cases}}\end{aligned}}}

Precedence relations computing algorithm

We will define three sets for a symbol:

H e a d + ( X ) = { Y X + Y α } T a i l + ( X ) = { Y X + α Y } H e a d ( X ) = ( H e a d + ( X ) { X } ) V t {\displaystyle {\begin{aligned}\mathrm {Head} ^{+}(X)&=\{Y\mid X\Rightarrow ^{+}Y\alpha \}\\\mathrm {Tail} ^{+}(X)&=\{Y\mid X\Rightarrow ^{+}\alpha Y\}\\\mathrm {Head} ^{*}(X)&=(\mathrm {Head} ^{+}(X)\cup \{X\})\cap V_{t}\end{aligned}}}
information Head*(X) is X if X is a terminal, and if X is a non-terminal, Head*(X) is the set with only the terminals belonging to Head+(X). This set is equivalent to First-set or Fi(X) described in LL parser.
information Head+(X) and Tail+(X) are ∅ if X is a terminal.

The pseudocode for computing relations is:

information  {\displaystyle \lessdot } and {\displaystyle \gtrdot } are used with sets instead of elements as they were defined, in this case you must add all the cartesian product between the sets/elements.

Examples

S a S S b | c {\displaystyle S\to aSSb|c}

precedence table
S a b c $ S a b c $ {\displaystyle {\begin{array}{c|ccccc}&S&a&b&c&\$\\\hline S&\doteq &\lessdot &\doteq &\lessdot &\\a&\doteq &\lessdot &&\lessdot &\\b&&\gtrdot &\gtrdot &\gtrdot &\gtrdot \\c&&\gtrdot &\gtrdot &\gtrdot &\gtrdot \\\$&&\lessdot &&\lessdot &\end{array}}}

Further reading

  • v
  • t
  • e
Niklaus Wirth
Software
Programming
languages
Euler (1965) → PL360 (1966) → ALGOL W (1966) → Pascal (1970) → Modula (1975) → Modula-2 (1978) → Object Pascal (1986) → Oberon (1987) → Oberon-2 (1991) → Lola (1995) → Active Oberon (1998) → Oberon-07 (2007)
Operating systems
Oberon System (1987) → Active Object System (AOS, 2002), Bluebottle (2005), A2 (2008)
Formalisms
  • Wirth's law
  • Wirth syntax notation
  • Wirth–Weber precedence relationship
Books
Workstations
Lilith (1977) → Ceres (1985)
Workplaces
Collaborators
Awards
  • Category