Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Linux is addictive, I'm hooked! -- MaDsen Wikholm's .sig


devel / comp.compilers / Re: How detect grammar not derive nonterminals ?

SubjectAuthor
* How detect grammar not derive nonterminals ?Andy
+* Re: How detect grammar not derive nonterminals ?gah4
|`* Re: How detect grammar not derive nonterminals ?Kaz Kylheku
| `- Re: How detect grammar not derive nonterminals ?gah4
`- Re: How detect grammar not derive nonterminals ?Andy

1
How detect grammar not derive nonterminals ?

<23-09-001@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=852&group=comp.compilers#852

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: borucki.andrzej@gmail.com (Andy)
Newsgroups: comp.compilers
Subject: How detect grammar not derive nonterminals ?
Date: Mon, 11 Sep 2023 08:58:17 -0700
Organization: Compilers Central
Sender: johnl%iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-09-001@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="86594"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, question
Posted-Date: 12 Sep 2023 13:42:24 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Andy - Mon, 11 Sep 2023 15:58 UTC

The simplest this case is grammar :
A -> A

but I have

A -> B
A -> b B
B -> A
B -> a A

it is trap for sequence generator. A->B->A->B->A....
How detect similar cases, especially without computing First and Follow sets ?

Re: How detect grammar not derive nonterminals ?

<23-09-002@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=853&group=comp.compilers#853

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah4@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: How detect grammar not derive nonterminals ?
Date: Tue, 12 Sep 2023 22:08:52 -0700
Organization: Compilers Central
Sender: johnl%iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-09-002@comp.compilers>
References: <23-09-001@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="75284"; mail-complaints-to="abuse@iecc.com"
Keywords: parse
Posted-Date: 13 Sep 2023 20:38:16 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-09-001@comp.compilers>
 by: gah4 - Wed, 13 Sep 2023 05:08 UTC

On Tuesday, September 12, 2023 at 10:42:28 AM UTC-7, Andy wrote:

(the subject not included in the message)

> How detect grammar not derive nonterminals ?

Ethernet uses the spanning tree protocol to detect loops in a switched network.

I think the same idea works here, but didn't try it.

Re: How detect grammar not derive nonterminals ?

<23-09-003@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=854&group=comp.compilers#854

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: borucki.andrzej@gmail.com (Andy)
Newsgroups: comp.compilers
Subject: Re: How detect grammar not derive nonterminals ?
Date: Wed, 13 Sep 2023 13:17:35 -0700
Organization: Compilers Central
Sender: johnl%iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-09-003@comp.compilers>
References: <23-09-001@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="75595"; mail-complaints-to="abuse@iecc.com"
Keywords: parse
Posted-Date: 13 Sep 2023 20:39:05 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-09-001@comp.compilers>
Lines: 106
 by: Andy - Wed, 13 Sep 2023 20:17 UTC

wtorek, 12 września 2023 o 19:42:28 UTC+2 Andy napisał(a):
> The simplest this case is grammar :
> it is trap for sequence generator. A->B->A->B->A....
> How detect similar cases, especially without computing First and Follow sets ?

I test my grammars:
above
;A->B->A->B....
A -> B
A -> b B
B -> A
B -> a A

;L grows up infinitely
G -> S
G -> L
G -> s
S -> i b t G
L -> i b t L e G
; if will exists L-: some_terminals it will ok, but not exists

E -> E + i
E -> E * i

S -> i S

S -> S i

I found solution: all w these cases handle computing minimal length of nonterminal and rules.
How correct compute it:
```
Rule {
boolean computeMinLen() {
int old = minLen;
minLen = 0;
for (Symbol symbol : this)
if (!symbol.terminal && grammar.getNT(symbol.index).minLen<0) {
minLen = -1;
return minLen != old;
}
for (Symbol symbol : this)
if (symbol.terminal)
minLen++;
else
minLen += grammar.getNT(symbol.index).minLen;
return minLen != old;
}
}

Nonterminal {
boolean computeMinLen() {
int old = minLen;
boolean changed = false;
for (Rule rule : rules) {
if (rule.computeMinLen())
changed = true;
}
for (Rule rule : rules) {
if (rule.minLen >= 0) {
if (minLen<0)
minLen = rule.minLen;
else
minLen = Math.min(minLen, rule.minLen);
}
}
return minLen != old || changed;
}
}

and loop if not change:
boolean changed = true;
while (changed) {
changed = false;
for (Nonterminal nt : nonterminals) {
if (nt.computeMinLen())
changed = true;
}
}

and check:
int index = 0;
for (Nonterminal nt : nonterminals) {
if (nt.minLen < 0)
throw new NoMinLenGrammarException("not computed minLen for " + getNonTerminalName(index));
for (Rule ruleInfo: nt.rules)
if (ruleInfo.minLen < 0)
throw new NoMinLenGrammarException("not computed minLen for " + ruleInfo.toString());
index++;
}

```
-----------------
But what doing if grammar is correct but has generator trap :
A->A
A->a
generates "a" but generator , which I write, calls A->A->...
should be transformed by eliminate A->A

A->B
A->a
B->A
B->b

is cycle A->B->A...
should be transformed by eliminate A->B or B->A

how detect all similar cases and how transform it in general case?

Re: How detect grammar not derive nonterminals ?

<23-09-006@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=856&group=comp.compilers#856

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.compilers
Subject: Re: How detect grammar not derive nonterminals ?
Date: Thu, 14 Sep 2023 03:41:12 -0000
Organization: Compilers Central
Sender: johnl%iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-09-006@comp.compilers>
References: <23-09-001@comp.compilers> <23-09-002@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="87929"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, comment
Posted-Date: 14 Sep 2023 18:40:45 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Kaz Kylheku - Thu, 14 Sep 2023 03:41 UTC

On 2023-09-13, gah4 <gah4@u.washington.edu> wrote:
> On Tuesday, September 12, 2023 at 10:42:28 AM UTC-7, Andy wrote:
>
> (the subject not included in the message)
>
>> How detect grammar not derive nonterminals ?
>
> Ethernet uses the spanning tree protocol to detect loops in a switched network.
>
> I think the same idea works here, but didn't try it.

Loops are allowed in a grammar, and are the essence of expressive
languages that can generate sentences of arbitrary length/depth.

The situation is similar to recursion: recursion can terminate
or run away.

This has a loop, but is okay, because it has a terminating case:

A := A b | b

This isn't okay; and note that all we did was take *away* the b case:

A := A b

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
[At the very least, you'd need some rules that don't have nonterminals
on the right side to make it possible to break loops. -John]

Re: How detect grammar not derive nonterminals ?

<23-09-007@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=857&group=comp.compilers#857

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah4@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: How detect grammar not derive nonterminals ?
Date: Thu, 14 Sep 2023 20:04:30 -0700
Organization: Compilers Central
Sender: johnl%iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-09-007@comp.compilers>
References: <23-09-001@comp.compilers> <23-09-002@comp.compilers> <23-09-006@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="39545"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, design, comment
Posted-Date: 15 Sep 2023 19:14:46 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-09-006@comp.compilers>
 by: gah4 - Fri, 15 Sep 2023 03:04 UTC

(our moderator wrote)

> [At the very least, you'd need some rules that don't have nonterminals
> on the right side to make it possible to break loops. -John]

So do it by back propagation.

Mark all rules that have a terminal on the right side.

Mark all rules that have a rule that has a terminal on the right side.

Repeat until there aren't any more to mark.

Any unmarked rules don't ever reach a terminal.
[It's not quite that, it's rules that have no nonterminals, that
is, either just terminals or empty. This will recognize a
possibly empty sequence of x's:

A: /* nothing */
A: x A

-John]

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor