Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2668

Re: About finding the start symbol of a grammar

From Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Newsgroups comp.compilers
Subject Re: About finding the start symbol of a grammar
Date 2021-05-21 17:02 +0200
Organization Compilers Central
Message-ID <21-05-017@comp.compilers> (permalink)
References <21-05-015@comp.compilers>

Show all headers | View raw


On 5/21/21 12:49 PM, Eduardo Costa wrote:
> I've been lately dealing with a parser generator for LL grammars, and since
> it's inception I've always been blindy assuming the first element read from
> within the input file is going to be the start symbol or starting rule.
>
> So I've been wondering all this time, just out of curiosity, if there exists a
> method or algorithm to find out the start symbol of a given grammar?

Graph analysis methods exist to find unreachable nodes which can become
start symbols. In short any node that is a predecessor of *all* nodes
can be a start symbol. If no such node exists then the grammar is faulty
(discontiguous).

> While there would exist grammars we could recursively check to find out which
> it's start symbol is (i.e.: it's the only rule that used the rest of them,
> where checking every other resulted in dangling rules that weren't even called
> in), there might be other grammars for which more than one rule yields full
> coverage (all of these obviously defining different languages) and so leading
> to ambiguity.

IMO this problem can be solved by introduction of an artificial start
symbol that allows to reach all other symbols but can not be reached
itself. Please note that this solution solves a syntactic problem but
may not prevent or even cause semantic problems.

> I only contemplate a simple coverage test, even though other techniques could
> exist, again, all of them leading to a point where we couldn't ascertain if
> one or the other is what the user meant.
>
> So I'm wondering if this is even an issue in production-grade
> parser-generators out there?

A useful parser generator should include checks for grammar sanity.

DoDi

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

About finding the start symbol of a grammar Eduardo Costa <ecosta.tmp@gmail.com> - 2021-05-21 03:49 -0700
  Re: About finding the start symbol of a grammar Kaz Kylheku <563-365-8930@kylheku.com> - 2021-05-21 14:14 +0000
    Re: About finding the start symbol of a grammar anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2021-05-21 15:32 +0000
  Re: About finding the start symbol of a grammar Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2021-05-21 17:02 +0200
  Re: About finding the start symbol of a grammar "Ev. Drikos" <drikosev@gmail.com> - 2021-05-22 06:52 +0300

csiph-web