

%union {String; YYterminal; Integer}

%token <Integer> '('   ')'   INDVAR  SEQVAR TRUE FALSE
%token <Integer> STRING  NUMBER  EQ  NOTEQ  IMPLIES
%token <Integer> IMPLIED  EQUIV  EQLESS  LESS  EQGREATER
%token <Integer> GREATER  QUOTE  FORALL  EXISTS  AND
%token <Integer> OR  NOT  IF  COND  LISTOF  DEFOBJECT
%token <Integer> DEFFUNCTION  DEFRELATION  DEFLOGICAL
%token <Integer> CONSTANT PLACEHOLDER

%type  <YYterminal> tLPAREN   tRPAREN   tINDVAR  tSEQVAR tTRUE tFALSE
%type  <YYterminal> tSTRING  tNUMBER  tEQ  tNOTEQ  tIMPLIES
%type  <YYterminal> tIMPLIED  tEQUIV  tEQLESS  tLESS  tEQGREATER
%type  <YYterminal> tGREATER  tQUOTE  tFORALL  tEXISTS  tAND
%type  <YYterminal> tOR  tNOT  tIF  tCOND  tLISTOF  tDEFOBJECT
%type  <YYterminal> tDEFRELATION  tDEFLOGICAL  tCONSTANT

%type  <String>   form  
%type  <String>   sentence relsent logconst logsent hornsent
%type  <String>   term 
%type  <String>   termseq  relsentseq  sentseq 
%type  <String>   definition

%start form
%%

form		:	sentence 	
					{	
						// case-1
						Result.string = $1; 
						System.out.println("-- " + $1 + " --");
					}
			|	definition
					{
						// case-1.1
						Result.string = $1; 
						System.out.println("-- " + $1 + " --");
					}
			;
sentence	:	logconst	
					{ 
						// case-2
						$$ = $1;  
					}
			|	relsent		
					{ 
						// case-3 
						$$ = $1;  
					}
			|	logsent		
					{ 
						// case-4 
						$$ = $1;  
					}
			|	hornsent	
					{ 
						// case-5 
						$$ = $1;  
					}
			;
logconst	:	tTRUE		
					{ 
						// case-6 
						$$ = ($1).toString();  
					}	
			|	tFALSE		
					{ 
						// case-7 
						$$ = ($1).toString();  
					}
			;
relsent		:	tLPAREN tCONSTANT termseq tRPAREN 
					{ 
						// case-8 
						$$ = new String(($1).toString() + ($2).toString() + $3 + ($4).toString());  
					}
			;
logsent		:	tLPAREN tNOT sentence tRPAREN 
					{ 
						// case-11 
						$$ = new String(($1).toString() + ($2).toString() + $3 + ($4).toString());  
					}
			|	tLPAREN tAND sentence sentseq tRPAREN 
					{ 
						// case-11.1 
						$$ = new String(($1).toString() + ($2).toString() + $3 + $4 + ($5).toString());  
					}
			|	tLPAREN tOR sentence sentseq tRPAREN 
					{ 
						// case-11.2 
						$$ = new String(($1).toString() + ($2).toString() + $3 + $4 + ($5).toString());  
					}
			|	tLPAREN tIMPLIES sentseq sentence tRPAREN 
					{ 
						// case-11.3 
						$$ = new String(($1).toString() + ($2).toString() + $3 + $4 + ($5).toString());  
					}
			|	tLPAREN tIMPLIED sentence sentseq tRPAREN 
					{ 
						// case-11.4   
						$$ = new String(($1).toString() + ($2).toString() + $3 + $4 + ($5).toString());  
					}
			|	tLPAREN tEQUIV sentence sentence tRPAREN 
					{ 
						// case-11.5 
						$$ = new String(($1).toString() + ($2).toString() + $3 + $4 + ($5).toString());  
					}
			;
hornsent	:	tLPAREN relsent tIMPLIED relsentseq tRPAREN 
					{ 
						// case-12 
						$$ = new String(($1).toString() + $2 + ($3).toString() + $4 + ($5).toString());  
					}
			;
relsentseq	:	relsent			
					{ 
						// case-13  
						$$ = $1; 
						System.out.println("relsentseq1 = " + $$); 
					}
			|	relsentseq relsent	
					{ 
						$$ = new String($1 + $2); 
						System.out.println("relsentseq2 = " + $$); 
						// case-14 
					}
			;
sentseq		:	sentence			
					{ 
						// case-13 
						$$ = $1; 
						System.out.println("sentseq1 = " + $$); 
					}
			|	sentseq sentence	
					{ 
						// case-14 
						$$ = new String($1 + $2); 
						System.out.println("relsentseq2 = " + $$); 
					}
			;
definition	:	tDEFOBJECT
					{ 
						//  case-14.1	
						$$ = new String("Object Defination"); 
					}
			;
term		:	tSTRING				
					{ 
						// case-15 
						$$ = new String(($1).toString()); 
						System.out.println("term1 = " + $$); 
					}
			|	tINDVAR				
					{ 
						// case-16 
						$$ = new String(($1).toString()); 
						System.out.println("term2 = " + $$); 
					}
			|	tCONSTANT			
					{ 
						// case-16.2 
						$$ = new String(($1).toString()); 
						System.out.println("term3 = " + $$); 
					}
			;
termseq		:	term			
					{ 
						// case-9 
						$$ = new String($1);  
						System.out.println("termseq1 = " + $$);
					}
			|	termseq term	
					{ 
						// case-10 
						$$ = new String($1 + $2);  
						System.out.println("termseq2 = " + $$);
					}
			|	tSEQVAR
					{
						// case-9 
						$$ = new String(($1).toString());  
						System.out.println("termseq1 = " + $$);
					}
			|	termseq tSEQVAR	
					{ 
						// case-10 
						$$ = new String($1 + ($2).toString());  
						System.out.println("termseq2 = " + $$);
					}
			;



/*	Copy out the text corresponding to each token
*/
tLPAREN		:	'('			{$$ = new YYterminal ('(', yytext); } ;
tRPAREN		:	')'			{$$ = new YYterminal (')', yytext); } ;
tINDVAR		:	INDVAR		{$$ = new YYterminal (INDVAR, yytext); } ;
tSEQVAR		:	SEQVAR		{$$ = new YYterminal (SEQVAR, yytext); } ;
tTRUE		:	TRUE		{$$ = new YYterminal (TRUE, yytext); } ;
tFALSE		:	FALSE		{$$ = new YYterminal (FALSE, yytext); } ;
tSTRING		:	STRING		{$$ = new YYterminal (STRING, yytext); } ;
tNUMBER		:	NUMBER		{$$ = new YYterminal (NUMBER, yytext); } ;
tEQ			:	EQ			{$$ = new YYterminal (EQ, yytext); } ;
tNOTEQ		:	NOTEQ		{$$ = new YYterminal (NOTEQ, yytext); } ;
tIMPLIES	:	IMPLIES		{$$ = new YYterminal (IMPLIES, yytext); } ;
tIMPLIED	:	IMPLIED		{$$ = new YYterminal (IMPLIED, yytext); } ;
tEQUIV		:	EQUIV		{$$ = new YYterminal (EQUIV, yytext); } ;
tEQLESS		:	EQLESS		{$$ = new YYterminal (EQLESS, yytext); } ;
tLESS		:	LESS		{$$ = new YYterminal (LESS, yytext); } ;
tEQGREATER	:	EQGREATER	{$$ = new YYterminal (EQGREATER, yytext); } ;
tGREATER	:	GREATER		{$$ = new YYterminal (GREATER, yytext); } ;
tQUOTE		:	QUOTE		{$$ = new YYterminal (QUOTE, yytext); } ;
tFORALL		:	FORALL		{$$ = new YYterminal (FORALL, yytext); } ;
tEXISTS		:	EXISTS		{$$ = new YYterminal (EXISTS, yytext); } ;
tAND		:	AND			{$$ = new YYterminal (AND, yytext); } ;
tOR			:	OR			{$$ = new YYterminal (OR, yytext); } ;
tNOT		:	NOT			{$$ = new YYterminal (NOT, yytext); } ;
tIF			:	IF			{$$ = new YYterminal (IF, yytext); } ;
tCOND		:	COND		{$$ = new YYterminal (COND, yytext); } ;
tLISTOF		:	LISTOF		{$$ = new YYterminal (LISTOF, yytext); } ;
tDEFOBJECT	:	DEFOBJECT	{$$ = new YYterminal (DEFOBJECT, yytext); } ;
tDEFOBJECT	:	DEFOBJECT	{$$ = new YYterminal (DEFOBJECT, yytext); } ;
tDEFRELATION:	DEFRELATION	{$$ = new YYterminal (DEFRELATION, yytext); } ;
tDEFLOGICAL	:	DEFLOGICAL	{$$ = new YYterminal (DEFLOGICAL, yytext); } ;
tCONSTANT	:	CONSTANT	{$$ = new YYterminal (CONSTANT, yytext); System.out.println("as tCONSTANT"); } ;


%%

public
void
yyverror(String s) throws ParseException
{
	String msg = yyerror_verbose(s);
	System.out.print("yyverror: line ");
	System.out.print(yyloc.lineno()+1);
	System.out.println(" ; " + msg);
	throw new ParseException(s);
}

