grammar-unreachable-sort

A sort that no start rule reaches.

Group
Urscal grammars
Runs
On by default
Level
warning
Reads
Every file
Fix
None: another module may still refer to the sort

Why

No start rule of the grammar refers to the sort, directly or through other sorts, so no parse from a start rule builds it. Refer to it or remove it.

The fix, as Ur suggests it: refer to the sort from a rule a start rule reaches, or remove it.

For agents

Define a sort only when a start rule reaches it, directly or through other sorts.

Example

calc/Calc.rsc
module calc::Calc

track Calc = "1";
dialect Standard uses Calc;
profile "calc-1" = Standard Calc "1";

lexical Name = [a-z]+ \ Reserved;
lexical Number = [0-9]+;
layout Space = [\  \n]+;
keyword Reserved = "let";

start syntax Program = Program: Statement* statements;
syntax Statement = Let: "let" Name name "=" Expr value;
syntax Expr = Variable: Name name | Literal: Number number;
syntax Call = Call: Name function "(" {Expr ","}* arguments ")";
What Ur prints
$ ur lint --rule grammar-unreachable-sort
warning[grammar-unreachable-sort]: no start rule reaches the sort `Call`
  --> ./calc/Calc.rsc:15:8 `Call` is never reached
  = hint: refer to the sort from a rule a start rule reaches, or remove it
  = see: Introduction to Automata Theory, Languages, and Computation, section 7.1.1, Eliminating Useless Symbols, John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman, third edition (2006), https://catdir.loc.gov/catdir/toc/ecip0613/2006014263.html
0 clone classes and 1 grammar finding in 1 file

Try it in the playground →

Source

Introduction to Automata Theory, Languages, and Computation, section 7.1.1, Eliminating Useless Symbols, John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman, third edition (2006).