KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > beaver > spec > NonTerminal


1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * This file is part of Beaver Parser Generator. *
3  * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>. *
4  * All rights reserved. *
5  * See the file "LICENSE" for the terms and conditions for copying, *
6  * distribution and modification of Beaver. *
7  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

8
9 package beaver.spec;
10
11 import beaver.comp.util.BitSet;
12
13 /**
14  * Represents grammar nonterminals.
15  */

16 public class NonTerminal extends GrammarSymbol
17 {
18     /** List of productions where this non-terminal is a LHS */
19     public Production.List definitions = new Production.List();
20
21     /** Non-terminal can be nullable if any of its productions can derive an empty string. */
22     public boolean is_nullable;
23
24     /**
25      * The set of terminals that begin strings derived from production rules
26      * where this non-terminal is a LHS
27      */

28     public BitSet first_set;
29
30     NonTerminal(String JavaDoc name)
31     {
32         super(name);
33     }
34
35     NonTerminal(String JavaDoc name, String JavaDoc type)
36     {
37         super(name);
38         super.type = type;
39     }
40     
41     /**
42      * @return true if the nullability status has been changed from false to true
43      */

44     boolean checkNullability()
45     {
46         if (is_nullable)
47             return false;
48
49         for (Production rule = definitions.start(); rule != null; rule = rule.next_definition)
50         {
51             if (rule.isNullable())
52             {
53                 return is_nullable = true;
54             }
55         }
56         return false;
57     }
58 }
59
Popular Tags