Related articles |
---|
How detect cycle in grammar ? a.moderacja@gmail.com (Borneq) (2011-11-20) |
Re: How detect cycle in grammar ? haberg-news@telia.com (Hans Aberg) (2011-11-21) |
Re: How detect cycle in grammar ? gene.ressler@gmail.com (Gene) (2011-11-21) |
Re: How detect cycle in grammar ? anton@mips.complang.tuwien.ac.at (2011-11-22) |
Re: How detect cycle in grammar ? a.moderacja@gmail.com (Borneq) (2011-11-23) |
Re: How detect cycle in grammar ? a.moderacja@gmail.com (Borneq) (2011-11-24) |
Re: How detect cycle in grammar ? quinn_jackson2004@yahoo.ca (Quinn Tyler Jackson) (2011-11-25) |
Re: How detect cycle in grammar ? gene.ressler@gmail.com (Gene) (2011-11-27) |
Re: How detect cycle in grammar ? gene.ressler@gmail.com (Gene) (2011-11-27) |
[5 later articles] |
From: | Gene <gene.ressler@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Mon, 21 Nov 2011 10:20:43 -0800 (PST) |
Organization: | Compilers Central |
References: | 11-11-041 |
Keywords: | parse, design |
Posted-Date: | 21 Nov 2011 23:06:05 EST |
On Nov 20, 5:48 pm, Borneq <a.modera...@gmail.com> wrote:
> A->B
> B->B
> This grammar is not correct, B is looped.
>
> A->B
> B->C
> C->A
> This another grammar, cycle can be arbitrarily long.
> Is cycle when First(Nonterminal) not contain any terminal, even not
> epsilon?
>
> A->B
> B-> (=B->epsilon)
> in first A and B is epsilon
Cycles aren't the problem. You'll need cycles to represent lists and
nestings. Nonterminals that can never derive a terminal string are the
problem.
You should look up useless nonterminals in the Dragon Book or similar
reference. This includes the algorithm for removing them from
grammars.
As I recall the algorithm starts with the lhs's of rules that expand
entirely to terminals (including epsilon) and recursively marks
nonterminals that have a rule where the entirely right hand side is
either marked or terminal. When you're done marking in this manner,
the unmarked nonterminals are useless. All rules involving them can
be deleted without changing the represented language. If the start
symbol is unmarked, the language is empty.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.