COM1205 J-Sem-Check 1Project
============================================================================

Name:      Virginia Magan
	   Arkadiy N. Sukharenko
	   Stanislav Paltis

Account:   jinny, stas, ark

URL:       http://www.ccs.neu.edu/home/stas/com1205.html
          
Project:   The purpose for this project is to convert part of sem-check, 
	   which was originaly written for Demeter/C++ to Demeter/Java. 


Directory: Combined files in:

           /proj/demsys/com1205/w97/ark/project/phase3
           /proj/demsys/com1205/w97/stas/project/final

	   Separated files in:

	   /proj/demsys/com1205/w97/jinny/project/phase1
	   /proj/demsys/com1205/w97/jinny/project/phase4
           /proj/demsys/com1205/w97/ark/project/phase1
           /proj/demsys/com1205/w97/ark/project/phase2
           /proj/demsys/com1205/w97/stas/project/phase1
           /proj/demsys/com1205/w97/stas/project/phase2

Credits:   Used class dictionary from:
           
	   Read Propagation patterns from
	   /proj/adaptive/www/evaluation/dibiaso
           These Propagation patterns were written by Dino Biaso
============================================================================

to run program:

In order to run a program, you should go to one of our directories with
final sources and type: 

java Main < program.input

or just type 'runme'
============================================================================

Use Cases:

case1 : 
input:
A = B.
A =.

Output: Class is declared twice.

Case2:
input: 

List(S) ~ A {S}.

Output : Repetition production on the right hand side is wrong.

Case 3:
Input:

A=B(X,Y).
B=X.

Output : B is not used properly.

Case 4:
Input:

I(S) = S(X).

Output: Parameter can not be parameterzied class.


============================================================================

Class Dictionary :  
(@
    import java.util.*;
    import java.io.*;
@)

ClassGraph		= <classes> DList(ClassDef).

ClassDef		= ParamClassName ClassParts "." .

ParamClassName		= ClassName ["(" <parameters> Commalist(ClassName) ")"].

ClassParts		: ConstOrAltClass | RepetitionClass.

ConstOrAltClass		: ConstructionClass | AlternationClass
			*common* + + +
				<parts> List(PartOrSyntax)
				<parents> ClassParents
				 - - -.

PartOrSyntax		: Part | OptionalPart | Syntax.

Part			= [ "<" PartName ">" ] ClassSpec.

OptionalPart		= "[" <part> Sandwich(Part) "]".

ClassParents		= [ "*extends*" <parent> Superclass ]
			  [ "*implements*" <interfaces> Commalist(Interface) ] .

Superclass		= ClassSpec.
Interface		= ClassSpec.

ConstructionClass	= "=".

AlternationClass	= ":" + + + <subclasses> Barlist(Subclass) - - -
			[ Common ].

Subclass		= ClassSpec.

Common			= *l + + + "*common*" - - -.

RepetitionClass		= "~" <sandwiched> Sandwich(RepeatedPart).

RepeatedPart		= [ <nonempty> ClassSpec ]
			"{" <repeated> Sandwich(ClassSpec) "}".

Sandwich(S)		= <first> List(Syntax) <inner> S <second> List(Syntax) .

ClassSpec		= ClassName
			["(" <actual_parameters> Commalist(ClassSpec) ")" ]
			.

Syntax			: PlainSyntax | PrintCommand
			.

PlainSyntax		= <string> String.

PrintCommand		: PrintIndent | PrintUnindent | PrintSkip | PrintSpace.
PrintIndent		= "+" .
PrintUnindent		= "-" .
PrintSkip		= "*l" .
PrintSpace		= "*s" .


// Terminal buffer classes.
DirName			= <name> Ident.
ClassName		= <name> Ident.
PartName		= <name> Ident.


// Parameterized class definitions.
List(S) ~ {S}.
SList(S) ~ S { *l S } *l .
DList(S) ~ S { *l *l S } *l .
Commalist(S) ~ S {"," S}.
Barlist(S) ~ S { *l "|" S}.

// Extra utility parameterized classes.
Parameterized		= Commalist(Part).
SyntaxTable		= List(PlainSyntax).


// Visitors added by j-sem-check group.
//

//Part 1 & 4
//
ClassCollector          = <lparams> ClassContainer <pparams> ClassContainer <level> Integer.
PartCollector           = <lparts> ClassContainer <pparts> ClassContainer.
ParamCollector          = <aparams> ClassContainer.
ActualPCollector        = <aparts> ClassContainer.

ClassContainer = *extends* Vector.
TranspVisitor = *extends* Vector.


//Part 2
//
SimpleChecker           = .
DeeperVisitor           = <carried> ClassName <level> Integer.

//Part 3
//
CompleteChecker		= <rc> RightChecker <lc> LeftChecker.
RightChecker            = <rcnt> RightCounter <rcon> ComplexContainer.
LeftChecker             = <lcnt> LeftCounter <lcon> ComplexContainer.

ComplexContainer 	= *extends* Vector.

RightCounter		= <nparams> Integer <classik> ClassName <level> Integer.
LeftCounter             = <nparams> Integer <classik> ClassName.

//Main Class
//
Main = .

Behavior File :
// Northeaster University. College of Computer Science.
//
//	J-SEM-CHECK (Part1)
//
//  Developers:  Stanislav Paltis (stas)
//		 Virginia Magan (jinni)
//		 Arkadiy Sukharenko (ark)
//
//  COM 1205
//  Last date modified: 03/11/97
//
//
//
// ****** CLASSES ******
//
ClassGraph
{   (@
     // Class methods:
     //
     	void check_parameters() throws Exception
      	{
           System.out.println("\n Checking that every parameterized class is consistently defined and used ...\n");
	   RightChecker right_c = new RightChecker(null, new ComplexContainer());
           LeftChecker left_c = new LeftChecker(null, new ComplexContainer());
	   this.check_right(right_c);
           this.check_left(left_c);
           
	   for (int i = 0; i < right_c.get_rcon().size(); i+=2)
           {
		int location = left_c.get_lcon().indexOf(right_c.get_rcon().elementAt(i));
		if (location == -1)
		    System.out.println("    J-Sem-Check:Error: Class " + right_c.get_rcon().elementAt(i) +
					" is not defined on the left hand side!");
		else
		    if (!right_c.get_rcon().elementAt(i+1).equals(left_c.get_lcon().elementAt(location+1)))
			System.out.println("    J-Sem-Check:Error: Number of parameters of the Class "+
						right_c.get_rcon().elementAt(i) + " do not match!");
	   }
       	}    
	void check_right(RightChecker rc) { this.tr(rc); }
        void check_left(LeftChecker lc) { this.tl(lc); }
  	void check_repetition() {
    	    SimpleChecker sc = new SimpleChecker();
            this.trepet(sc);
  	}
   	void lookAtClasses () throws Exception
   	{
   		ClassCollector  cc = new ClassCollector(new ClassContainer(), new ClassContainer(), new Integer(0));
   		this.allClassNames (cc);
   		PartCollector pc = new PartCollector(cc.get_lparams(), cc.get_pparams());
   		Vector allClasses = pc.get_lparts();
   		allClasses.addElement("Ident");
   		allClasses.addElement("Integer");
   		allClasses.addElement("String");
   		allClasses.addElement("Text");
   		allClasses.addElement("Double");
   		this.allParamClasses (pc);
   		ParamCollector  ac = new ParamCollector(new ClassContainer());
   		this.allPClassNames (ac);
   		ActualPCollector apc = new ActualPCollector(ac.get_aparams());
  		this.allActualPClasses (apc);
  
   	}
       @)
   
   // Traversals:
   //
   traversal tr(RightChecker rc)
   {
       bypassing ParamClassName
       to ClassSpec;
   }

   traversal tl(LeftChecker lc)
   {
       bypassing ClassParts
       to ParamClassName;
   }

   traversal trepet(SimpleChecker sc)  
   { 
       bypassing ConstOrAltClass 
       to RepetitionClass ; 
   }
   traversal allClassNames(ClassCollector cc)
   {
        bypassing ClassParts to ClassName;
   } 
  
   traversal allParamClasses(PartCollector pc)  
   {
       bypassing ParamClassName to ClassName;
   }
           
   traversal allPClassNames(ParamCollector ac)
   {
       bypassing {ClassParts, ->ParamClassName,classname,*} to ClassName;
   }
      
   traversal allActualPClasses (ActualPCollector apc)
   {     
       bypassing {SuperClass,Interface,SubClass,->*,actual_parameters,*}
       to ClassSpec;
   }

}


RepetitionClass
{  (@
        void go_deeper(){
                DeeperVisitor dv = new DeeperVisitor(null, new Integer(0));
                this.tdeeper(dv);
        }
   @)
   traversal tdeeper(DeeperVisitor dv) {to ClassName; }
}


ClassSpec 
{  (@ 
   void count_right(RightCounter rcnt) { this.trr(rcnt);}
   void ActualParamNames() 
   {
       TranspVisitor tv = new TranspVisitor();
       this.tjin(tv);
       int r = tv.size();
       if (r >1)
           System.out.println("   J-Sem-Check: Error: Formal Parameteres in class " + 
				this.get_classname().get_name() + 
				" cannot be a parameterized class!");
    }
   @)
  
   traversal trr (RightCounter rcnt) {to ClassName;}
   traversal tjin (TranspVisitor tv) {to ClassName; }
}


ParamClassName
{
  (@ void count_left(LeftCounter lcnt) { this.tll(lcnt);} @)
  traversal tll (LeftCounter lcnt) {to ClassName;}
}


// ****** MAIN ******
//
Main 
{   (@
    static public void main(String args[]) throws Exception 
    {
        System.out.println("\n Starting J-Sem-Check. \n");
        Runtime rt = Runtime.getRuntime();
        rt.traceMethodCalls( true );
        ClassGraph a = ClassGraph.parse(System.in);
        a.lookAtClasses();
        a.check_repetition();
        a.check_parameters();
        System.out.println("J-Sem-Check complete.");
    }
    @)
}


// ****** VISITORS ******
//

// Visitors used for part 2.
// 

SimpleChecker 
{
    before ClassGraph
	(@ 
	    System.out.println("\n Checking that two class names on the right " +
                                          "hand side of every repetition production " +
                                          "are identical...");
	    System.out.println();
	@)

    before RepetitionClass (@ host.go_deeper(); @)
}


DeeperVisitor
{

   before ->*,actual_parameters,* (@ level = new Integer (level.intValue() + 1); @)
   after ->*,actual_parameters,* (@ level = new Integer (level.intValue() - 1); @)

    before ClassName
    (@
        if (carried == null)
                carried = host;
        else
        {
                if ((!carried.get_name().toString().equals(host.get_name().toString()))
			&& (this.get_level().intValue() == 0)) 
                        System.out.println("    J-Sem-Check: Error: Not identical class instances (" +
                                                carried.get_name() + " and " + host.get_name() +
                                                ") on the right hand side of repetition production!" );
        }
   @)
}

// Visitors used for part 3.                                                             
//                          

RightChecker
{
     before ClassSpec
	(@ 
	    if (host.get_actual_parameters() != null)
	    {
		  RightCounter right_cnt = new RightCounter(new Integer(0), null, new Integer(0));
		  host.count_right(right_cnt);
		  rcon.addElement(right_cnt.get_classik().get_name().toString());
                  rcon.addElement(right_cnt.get_nparams());
	    }
	@)
}


LeftChecker
{
     before ParamClassName
        (@
            if (host.get_parameters() != null)
            {
                  LeftCounter left_cnt = new LeftCounter(new Integer(-1), null);
                  host.count_left(left_cnt);
                  lcon.addElement(left_cnt.get_classik().get_name().toString());
                  lcon.addElement(left_cnt.get_nparams());
            }
        @)   
}


RightCounter
{
   before ->*,actual_parameters,* (@ level = new Integer (level.intValue() + 1); @)
   after ->*,actual_parameters,* (@ level = new Integer (level.intValue() - 1); @)

   before ClassName
   (@
	if (this.get_level().intValue() == 1)
	    nparams = new Integer (nparams.intValue() + 1);
	if (this.get_classik() == null)
	    this.set_classik(host);
    @)
}


LeftCounter
{
   before ClassName  
   (@
        nparams = new Integer (nparams.intValue() + 1);
        if (this.get_classik() == null)
            this.set_classik(host);
    @)
}

// Visitors for part 1 & 4
//
ClassCollector {

  before ClassGraph (@
        System.out.println("\n Checking that every class is defined exactly once ...\n "); @)
      
   before ->*,parameters,* (@ level = new Integer (level.intValue() + 1); @)
   after ->*,parameters,* (@ level = new Integer (level.intValue() - 1); @)


  before ClassName (@
        Vector namessofar = this.get_lparams();
        Vector param_name = this.get_pparams();
        Ident thisclass = host.get_name();
        // We have a vector of classes we have seen, and an ident of this class name.
	if (this.get_level().intValue() == 0)
            if (namessofar.contains(thisclass))
               System.out.println ("    J-Sem-Check: Error: Class " + thisclass + " has been defined more than once!");
            else
               namessofar.addElement(thisclass);
  	else
            if (!param_name.contains(thisclass))
               param_name.addElement(thisclass);

  @)
}
    
PartCollector {
       
  before ClassGraph (@
        System.out.println("\n Checking that every class is defined at least once ...\n "); @)
   
  before ClassName (@
        Vector allnames = this.get_lparts();
        Vector paramnames = this.get_pparts();
        Ident tclass = host.get_name();
        if (!(allnames.contains(tclass) || paramnames.contains(tclass)))
            System.out.println ("     J-Sem-Check: Error: Class " + tclass + " has not been defined!");    
@)
}
    
ParamCollector {
 
  before ClassGraph (@
  System.out.println("\n Checking that formal parameters are not used as parameterized classes...\n "); @)
   
  before ClassName (@
      Vector cnames = this.get_aparams();
      Ident thclass = host.get_name();
      if (!cnames.contains(thclass))
          cnames.addElement(thclass);
 @)
}

ActualPCollector {
              
  before ClassSpec (@
    Vector pnames = this.get_aparts();
    Ident ptclass = host.get_classname().get_name();  
    if (pnames.contains(ptclass))  
       host.ActualParamNames();
    else
       ;
 @)
}


TranspVisitor {
   before ClassName (@
   this.addElement(host.get_name());
 @)
}


============================================================================

Growth Phases:

           /proj/demsys/com1205/w97/jinny/project/phase1
           /proj/demsys/com1205/w97/jinny/project/phase4
           /proj/demsys/com1205/w97/ark/project/phase1
           /proj/demsys/com1205/w97/ark/project/phase2
           /proj/demsys/com1205/w97/stas/project/phase1
           /proj/demsys/com1205/w97/stas/project/phase2

============================================================================

Bugs and parts of project that would have been developed further:

We were unable to specify to the user which line in the Class Dictionary
we found a problem. But, we do tell the user which class in the class 
dictionary is given errors. No bugs in the project were found. We tested
all the possible cases we could imagine.

============================================================================

Test inputs:
We created universal input file, but many input files can be found in our 
directory.
Here is our universal test case:
A = <b> B <c> C.
B = DD ( AA ( BB ( CC)), F(C, CC), G).
C = BL.
D = F(G).
G =.
F(X) = <x> X(X).
X =. 
List(S) ~ S {S}.
Alt(X1, Y1) : Alt1(X1, Y1) | Alt2(X1, Y1).
List2(X2, Y2) ~ Alt2(X2,Y2) {Alt1(X2,Y2)}.
Alt1(X1, Y1) = X1(Y1).
Alt2(X1, Y1) =.
AA(S, SS) =.
BB(S) =.
CC(S) =.
DD(N,O,P) =.
A =.
F =.


============================================================================

Test input/output case:
And here is an output for the universal case:


 Starting J-Sem-Check.


 Checking that every class is defined exactly once ...

    J-Sem-Check: Error: Class A has been defined more than once!
    J-Sem-Check: Error: Class F has been defined more than once!

 Checking that every class is defined at least once ...

     J-Sem-Check: Error: Class BL has not been defined!

 Checking that formal parameters are not used as parameterized classes...

   J-Sem-Check: Error: Formal Parameteres in class X cannot be a
parameterized class!
   J-Sem-Check: Error: Formal Parameteres in class X1 cannot be a
parameterized class!

 Checking that two class names on the right hand side of every repetition
production are identical...

    J-Sem-Check: Error: Not identical class instances (Alt2 and Alt1) on
the right hand side of repetition production!

 Checking that every parameterized class is consistently defined and used
...

    J-Sem-Check:Error: Number of parameters of the Class AA do not match!
    J-Sem-Check:Error: Number of parameters of the Class F do not match!
    J-Sem-Check:Error: Class X is not defined on the left hand side!
    J-Sem-Check:Error: Class X1 is not defined on the left hand side!
J-Sem-Check complete.


============================================================================

Other Info:

None of the generated Java  code that were generated from the demjava.cd 
and demjava.beh files were changed.

The generated Makefile that j-gen-make produced was not changed.

============================================================================
 
Approach:

Our group was responsible for the 4 out of the 15 tests that sem-check 
executes.  The project was divided into 3 phases.