    # KEHOME/doc/MKRgrammar.html
    # Apr/24/2003

    #=======================#
    # MKR grammar           #
    # version 5.5           #
    #                       #
    # Richard H. McCullough #
    #=======================#
    # see also KEHOME/doc/MKRtoken.html

    knowledge := man do identify od existent done;
    knit is knowledge with view;			# knowledge unit
    knit haspart proposition list;

    proposition ::=
    	context { proposition list } ;
    	context ;
    	sentence
    context ::=
    	at stvlist
    stvlist ::=
    	space=s,time=t,view=v			# v is name of knit

    sentence ::=
    	statement
    	question
    	command
    	assignment
    	product := sentence
    	{ proposition list }

    statement ::=
        definition
        group
        control statement
        subject is      object;			# identity, i.e. alias
        subject rel     object;			# ke relation
        subject isin    relation=infon;		# user relation
        subject has     attribute=value;		# attribute
        subject haspart part=value;			# part
        subject do      action=event pplist done;	# action
        subject causes  object;			# interaction

    definition ::=
    	concept   definition
    	method    definition
    	relation  definition

    control statement ::=
        if proposition list:1	# conditional
        then proposition list:2
        else proposition list:3
        fi;

        every generator:1 {		# iteration
    	proposition list:2
        };

        exit;			# exit ke

    question ::=
        if statement fi;		# true or false
        statement[?]		# form-based search: embedded ?
        set variable = ?;		# form-based search: embedded ?

    command ::=
        do  action pplist done;	# ke do action pplist done
        !   action pplist done;	# sh do action pplist done
        vdo action pplist done;	# all views

    assignment ::=
        set   variable = value;	# ke has variable = value
        vset  variable = value;	# all views
        unset variable;

        set   ..  = next;		# set current genus
        set   .   = value;		# set current concept
        set   ... = next;		# set current species|unit

    concept definition ::=	# genus-differentia
        concept is  genus     with essential characteristic;
        concept isa genus     with essential characteristic;
        species iss genus     with essential characteristic;
        unit    isu primitive with essential characteristic;

        product :=  entity do action pplist done;  # ":=" means "is product of"

    method definition ::=	# user-defined command
        mycmd is method with
    	    automatic,			# declarations: NONE,ISA*,ISA,ISS,ISU
    	    separator,			# default: ","
    	    meantype,			# procedure or proposition list
    	    label=[string:1,...],	# user-friendly
    	    format=[class:1,...],	# argument class list
    	    meaning={ ... $1 ... };	# proposition list

    relation definition ::=	# user-defined relation
        myrel is relation with
    	    automatic,			# declarations: NONE,ISA*,ISA,ISS,ISU
    	    separator,			# default: ";"
    	    meantype,
    	    label=[...],
    	    format=[...],
    	    meaning={...};
        begin relation myrel; 		# set kformat = rel
    	  ...
    	  arg1,...;			# relstatement: infon
    	  ...
        end relation myrelation;		# set kformat = ku

    # group
    #   hierarchy, unithierarchy, lattice
    #   directory
    #   relation
    #   ntriple, mcf
    #   utype is group unit type
    #   automatic ::= NONE | ISA* | ISA | ISS | ISU
    gtype ::=
        hierarchy		# isg, iss; unique   genus
        unithierarchy	# isp, isu; unique   genus
        directory		# isg, iss; multiple genus; isp, isu; rootname
        lattice		# isc, isa; multiple genus
        relation		# isin
        ntriple		# RDF
        mcf			# TAP
    gtype definition ::=	# user-defined gtype
        myhi is gtype of utype with
    	automatic,
    	separator;
        begin gtype mygroup;# set kformat = gtype
        groupstatement;
          ...
        end gtype mygroup;	# set kformat = ku

    # hierarchy format (also unithierarchy,lattice,directory)
        begin hierarchy myhi;# set kformat = ho
          honame;		# hostatement: local root
          ...
          //.../  honame;	# hostatement: down hierarchy
          ...
          \\...\  honame;	# hostatement: up hierarchy
          ...
        end hierarchy myhi;	# set kformat = ku

    # relation format
        begin relation myrel;# set kformat = rel
          arg1,arg2,...;	# relstatement: null arg permitted
          ...
        end relation myrel;	# set kformat = ku

    # group definition
    #   list, sequence, Set, multiset, enumeration
    #   utype is group unit type
    #   automatic ::= NONE | ISA* | ISA | ISS | ISU | ISALT | ISMEM
    gtype ::=
        list		# ingroup: isall, ismem; order=space
        sequence		# ingroup: isall, ismem; order=time
        Set			# ingroup: isall, ismem; order=none
        multiset		# ingroup: isall, ismem; order=none, repeated units
        enumeration		# exgroup: isany, isalt; order=none
    rel ::=
        isany
        isall
    gtype definition ::=	# user-defined gtype
        mygroup is gtype of utype with
            automatic,
            separator;
        mygroup rel		# isany, isall
            unit:1,
            ...,
            unit:n;

    #======================================================================#
    # details of action & command format

    do action pplist done ::=
        do action
    	with action characteristics	# e.g. option
    	out  products			# output: product := subject do ... done
        	od   direct objects		# input: argument list
    	from initial characteristics	# e.g. input file
    	to   final   characteristics	# e.g. output file
        done;

    #======================================================================#
    # basic word, phrase, list
    # NOTE: some wphrase, wplist are generalized to bphrase, bplist

    subject  ::= phraselist
    object   ::= phraselist

    argument list	::= nvlist
    characteristic  ::= nvlist
    relation=infon  ::= nvlist
    attribute=value ::= nvlist
    part=value      ::= nvlist
    variable=value  ::= nvlist
    action=event    ::= nvlist

    nvlist ::= list of nvphrase with separator=comma
    pplist ::=
    	null
    	list of prepphrase with separator=whitespace
    phraselist       ::= list of phrase  with separator=comma
    bplist           ::= list of bphrase with separator=comma
    proposition list ::= list of proposition with separator=whitespace

    nvphrase ::=
    	phrase nvop value
    value ::=
    	phrase
    	[ phraselist ]
    	{ proposition list }
    nvop ::=
    	=	# assignment
    	+=	# Set add
    	-=	# Set delete
    	*=	# Set intersection

    prepphrase ::=
    	preposition prepobject
    prepobject ::=
    	nvlist
    	{ proposition list }
    preposition ::=
    	at	# context: space,time,view
    	of	# composition, e.g. unit type
    	with	# differentia, e.g. option
    	out	# output: e.g. product
    	od	# input:  e.g. direct object, argument list
    	from	# initial characteristic, e.g. input file
    	to	# final   characteristic, e.g. output file

    phrase ::= list of word with separator=whitespace
    qphrase ::=
    	phrase
    	quantifier phrase
    bphrase ::=
    	phrase
    	phrase and phrase
    	phrase or  phrase
    quantifier ::=
        a		# one
        some	# one or more
        the		# one
        any		# one
        all
        no		# none
        not		# complement relative to existent
        non		# complement relative to genus

    relphrase ::= list of relword with separator=whitespace

    hophrase ::= list of howord with separator=whitespace

    # words -- see KEHOME/src/symbol.icn
    word    ::= (wordchar)+
    relword ::= (relchar)+
    howord  ::= (hochar)+

    # tokens -- see KEHOME/src/token.icn
    wordchar ::= &cset -- separator
    relchar  ::= &cset -- ',;'
    hochar   ::= &cset

    #======================================================================#
    # more reserved words

    rel ::=			# verb - see KEHOME/kb/ke.def for complete list
        isa isa* isa**n	# unit|species isa concept
        isc isc* isc**n	# concept      isc unit|species

        isp   isp*		# primitive   isp   unit
        isu   isu*		# unit        isu   primitive
        isg   isg*		# genus       isg   species
        iss   iss*		# species     iss   genus
        isany isany*	# exgroup     isany alternative
        isalt isalt*	# alternative isalt exgroup
        isall isall*	# ingroup     isall member
        ismem ismem*	# member      ismem ingroup

        haspart		# entity haspart part
        isapart		# part   isapart entity

        isd			# concept differentiation
        isi			# concept integration
        in			# variable in concept list

    conjunction ::=
        ";"			# proposition list
        "&"			# and, asynchronous execution
        "|"			# or,  pipe
        and			# logic
        or			# logic
        iff			# logic
        implies		# logic
        supports		# situation theory: view supports sentence
        causes		# event:1 causes event:2
        means		# symbol means concept; concept means existent

    action ::=		# see KEHOME/kb/tabrasa.def
        mycmd		# user defined method
        COMMAND		# ke command
        identify		# KEHOME/knowledge/theory/Epistemology/Identify.htm
        sense		# KEHOME/knowledge/theory/Epistemology/Identify.htm
        measure		# KEHOME/knowledge/theory/Epistemology/Identify.htm
        classify		# KEHOME/knowledge/theory/Epistemology/Identify.htm
        live
        move

    COMMAND ::=		# see KEHOME/kb/ke.def for complete list
        menu		# KE smart input menu
        find		# find name with wildcard
        print		# display concept or string
        dump		# display all characteristics of concept
        read		# file i/o
        write		# file i/o
        ftype		# file i/o
        read directory	# file system hierarchy i/o
        write directory	# file system hierarchy i/o
        cd			# change directory
        hwalk		# do action up/down hierarchy
        check		# check hierarchy for errors
        clock		# time stamp
        csize		# count concepts in subhierarchy
        psize		# count primitives in subhierarchy
        usize		# count units in subhierarchy
        clist		# list concepts in subhierarchy
        plist		# list primitives in subhierarchy
        ulist		# list units in subhierarchy
        glb			# greatest lower bound of concepts
        lub			# least uppper bound of concepts
        isd			# concept formation
        isi			# concept formation
        measure		# concept formation
        classify		# concept formation
        sh			# UNIX shell
        pwd			# UNIX command
        ls			# UNIX command
        grep		# UNIX command
        vi			# UNIX command
        cmd			# Windows shell
        wfind		# Windows command
        notepad		# Windows command
        explorer		# Windows file system shell
        rebol		# internet messaging shell

    attribute ::=
    	variable	# ke attribute
    	purpose
    	format
    	meaning
    	automatic
    	separator

    variable ::=		# see KEHOME/kb/ke.def for complete list
    	kformat		# input format
    	echo		# echo input proposition
    	kerror		# input error count
    	hformat		# output format
    	charformat	# characteristic output format - line or column
    	hfocus		# output concept Set
    	debug		# extra output
    	kehome		# install directory
    	keview		# file system directory