You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2006/12/08 00:50:22 UTC

svn commit: r483740 - /labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java

Author: elecharny
Date: Thu Dec  7 15:50:20 2006
New Revision: 483740

URL: http://svn.apache.org/viewvc?view=rev&rev=483740
Log:
Added the startingSymbol. Added a toString() method. Added some javadoc

Modified:
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java

Modified: labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java
URL: http://svn.apache.org/viewvc/labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java?view=diff&rev=483740&r1=483739&r2=483740
==============================================================================
--- labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java (original)
+++ labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java Thu Dec  7 15:50:20 2006
@@ -37,6 +37,7 @@
  * We also have those rules to follow :
  * - Each VN is declared in one RHS
  * - A production can't have more than one epsilon transition
+ * - The first VN will be the starting VN.
  * 
  *
  * @author <a href="mailto:dev@labs.apache.org">Dungeon Project</a>
@@ -50,11 +51,16 @@
     /** The set of all VN declared */
     private Set<String> vns;
     
+    /** The starting symbol for this MetaGrammar */
+    private Symbol startingSymbol;
+    
+    /** The list of all VNs on all the RHS parts */
     private Set<String> rhsVNs;
     
 	/**
      * 
-     * Creates a new instance of MetaGrammar.
+     * Creates a new instance of MetaGrammar. We have to initialize 
+     * a list of productions, and the set of VNs
 	 */
 	public MetaGrammar() 
 	{
@@ -62,6 +68,15 @@
         vns = new HashSet<String>();
         rhsVNs = new HashSet<String>();
 	}
+    
+    /**
+     * Set the starting symbol
+     * @param startingSymbol The starting symbol
+     */
+    public void setStartingSymbol( Symbol startingSymbol )
+    {
+        this.startingSymbol = startingSymbol;
+    }
 
     /**
      * 
@@ -89,6 +104,18 @@
     }
     
     /**
+     * Add a new VN to this grammar list of VNs 
+     * @param vn
+     */
+    public void addVN( Symbol vn )
+    {
+        if ( ! containsVN( vn.getName() ) )
+        {
+            vns.add( vn.getName() );
+        }
+    }
+    
+    /**
      * @return The list of all productions for this grammar
      */
     public List<Production> getProductions()
@@ -96,13 +123,72 @@
         return productions;
     }
 
+    /**
+     * @return The startingSymbol
+     */
+    public Symbol getStartingSymbol()
+    {
+        return startingSymbol;
+    }
+
+    /**
+     * @return the set of all VNs found in the RHS parts.
+     * This set should be equal to the vns set.
+     */
     public Set<String> getRhsVNs()
     {
         return rhsVNs;
     }
 
+    /**
+     * Add a new VN to the list of RHS vns
+     * @param vn The VN to be added
+     */
     public void addRhsVN( String vn )
     {
-        this.rhsVNs.add( vn );
+        if ( !rhsVNs.contains( vn ) )
+        {
+            rhsVNs.add( vn );
+        }
+    }
+    
+    /**
+     * @return The set of all VNs for this grammar
+     */
+    public Set<String> getVns()
+    {
+        return vns;
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "Grammar :\n" );
+        sb.append( "  Starting symbol : <" ).append( startingSymbol.getName() ).append( ">\n" );
+        sb.append( "  Set of VNs : {" );
+        
+        boolean isFirst = true;
+        
+        for ( String symbol:vns )
+        {
+            if ( isFirst )
+            { 
+                isFirst = false;
+            }
+            else
+            {
+                sb.append( ", " );
+            }
+            
+            sb.append( symbol );
+        }
+        
+        sb.append( "}\n" );
+        
+        return sb.toString();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org