Grammar AntlrCGIFParser
ANTLR-generated HTML file from cgp/translators/AntlrCGIFParser.g

Terence Parr, MageLang Institute
ANTLR Version 2.7.0; 1989-1999

	
	package cgp.translators;
	
		import antlr.SemanticException;
	
		import cgp.translators.ContextScope;
		import cgp.translators.ContextScopeStack;
		import cgp.translators.DefinedQuantifier;
		import cgp.translators.NumericQuantifier;
	
		import notio.Actor;
		import notio.Concept;
		import notio.ConceptAddError;
		import notio.ConceptReplaceException;
		import notio.ConceptType;
		import notio.ConceptTypeHierarchy;
		import notio.CopyingScheme;
		import notio.Designator;
		import notio.Graph;
		import notio.KnowledgeBase;
		import notio.LiteralDesignator;
		import notio.Macro;
		import notio.Marker;
		import notio.MarkerDesignator;
		import notio.MarkerSet;
		import notio.NameDesignator;
		import notio.Parser;
		import notio.QuantifierMacro;
		import notio.Referent;
		import notio.Relation;
		import notio.RelationAddError;
		import notio.RelationType;
		import notio.RelationTypeHierarchy;
	
		import java.util.ArrayList;
	

/**
 * A Notio CGIF parser for a conceptual graph language which embodies Guy
 * Mineau's process formalism.
 * Copyright (C) 2001 David Benn
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Note that this parser is based upon the modified June 2001 CG Standard 
 * found at: http://www.cs.nmsu.edu/~hdp/CGTools/cgstand/cgstandnmsu.html
 * This will be referred to as "The Standard" or "The CGIF Standard" herein. 
 *
 * All parser and lexer productions are preceded by the text from the 
 * aforementioned URL given for each production or its equivalent, although
 * the ordering may not be as found in that document depending upon what
 * makes sense for the ANTLR-based grammar. Notes and questions regarding
 * the original productions have been added.
 *
 * David Benn, June 2001
 */
class AntlrCGIFParser extends LLkParser


actor[Actor a]
	:	LANGLE type ( arc )* VERTBAR ( arc )* 
		(	COMMENT 
		|	
		) 
		RANGLE 
	;


type[String label]
	:	typeLabel 
	|	typeExpression 
	;


arc[Concept c]
	:	concept 
	|	boundLabel 
	;


concept[Concept c]
	:	LBRACK 
		(	type 
		|	
		) 
		
		(	( referent[c] corefLinks[scope, c] ) => ( referent[c] corefLinks[scope, c] ) 
		|	( corefLinks[scope, c] referent[c] ) => ( corefLinks[scope, c] referent[c] ) 
		|	( referent[c] ) => referent[c] 
		|	corefLinks[scope, c] 
		|	
		) 
		
		(	COMMENT 
		|	
		) 
		RBRACK 
	;


boundLabel[Concept c]
	:	QUESTION IDENTIFIER 
	;


cgStream[Graph[] stream]
	:	cg ( DOT cg )* 
	;


cg[Graph g]
	:	(	( NEGATION_PREFIX ) => specialContext[g] 
		|	( LBRACK specialConLabel ) => specialContext[g] 
		|	concept 
		|	relation 
		|	actor 
		|	COMMENT 
		)* 
	;


specialContext returns [Graph g]
	:	negation 
	|	LBRACK specialConLabel COLON cg RBRACK 
	;


specialConLabel
	:	"if" 
	|	"then" 
	|	"either" 
	|	"or" 
	|	"sc" 
	;


relation[Relation r]
	:	LPAREN type ( arc )* 
		(	COMMENT 
		|	
		) 
		RPAREN 
	;


referent returns [Concept c]
	:	COLON 
		(	( designator[r] descriptor[r] ) => ( designator[r] descriptor[r] ) 
		|	( descriptor[r] designator[r] ) => ( descriptor[r] designator[r] ) 
		|	( descriptor[r] ) => descriptor[r] 
		|	designator[r] 
		|	
		) 
	;


corefLinks[Concept boundConcept] returns [ContextScope scope, Concept c]
	:	defLabel[scope, c] 
	|	( boundLabel )* 
	;


conjuncts
	:	typeTerm ( AMPERSAND typeTerm )* 
	;


typeTerm
	:	(	TILDE 
		|	
		) 
		type 
	;


defLabel returns [ContextScope enclosingContext, Concept theConcept]
	:	STAR IDENTIFIER 
	;


descriptor returns [Referent r]
	:	structure 
	|	cg 
	;


structure
	:	(	PERCENT IDENTIFIER 
		|	
		) 
		LBRACE ( arc )* RBRACE 
	;


designator returns [Referent r]
	:	literal 
	|	locator 
	|	quantifier 
	;


literal[Object lit]
	:	number 
	|	QUOTEDSTR 
	;


locator[Designator d]
	:	NAME 
	|	( individualMarker ) => individualMarker 
	|	indexical 
	;


quantifier[QuantifierMacro m]
	:	AT 
		(	UNSIGNEDINT 
		|	IDENTIFIER 
			(	LBRACE QUOTEDSTR ( COMMA QUOTEDSTR )* RBRACE 
			|	
			) 
			
		) 
	;


disjuncts
	:	conjuncts ( VERTBAR conjuncts )* 
	;


formalParameter
	:	type 
		(	defLabel[null, null] 
		|	
		) 
	;


indexical[String s]
	:	HASH 
		(	IDENTIFIER 
		|	
		) 
		
	;


individualMarker[String s]
	:	HASH UNSIGNEDINT 
	;


lambdaExpression
	:	LPAREN "lambda" signature cg RPAREN 
	;


signature
	:	LPAREN 
		(	formalParameter ( COMMA formalParameter )* 
		|	
		) 
		RPAREN 
	;


number[Number num]
	:	INT_NUM 
	|	FLOAT_NUM 
	;


negation[Relation r]
	:	NEGATION_PREFIX cg RBRACK 
	;


typeLabel
	:	IDENTIFIER 
	;


typeExpression
	:	( LPAREN "lambda" ) => lambdaExpression 
	|	LPAREN disjuncts RPAREN 
	;