# KEHOME/doc/KRgrammar.txt
# Jan/25/2003

#=======================#
# MKR grammar           #
# version 4.7           #
#                       #
# Richard H. McCullough #
#=======================#
# see also KEHOME/doc/KRtoken.txt

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
    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

definition ::=
	concept   definition
	method    definition
	relation  definition
	group     definition

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

    every sentence:1 { proposition list:2 }	# iteration

    exit					# exit ke

question ::=
    statement ?			# 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={...}
    myrel is begin relation		# set kformat = rel
	  ...
	  rplist;...			# relstatement: infon
	  ...
    end relation myrelation		# set kformat = ku

# group definition
# hierarchy, primitive, lattice
# utype is group unit type
# automatic ::= NONE | ISA* | ISA | ISS | ISU
gtype ::=
    hierarchy		# isg, iss; unique   genus
    primitive		# isp, isu; unique   genus
    lattice		# isc, isa; multiple genus
gtype definition ::=	# user-defined gtype
    myhi is gtype of utype with
	automatic,
	separator
    myhi is begin gtype	# set kformat = gtype
      ...
      hophrase		# hostatement: local root
      ...
      //.../  hophrase	# hostatement: down hierarchy
      ...
      \\...\  hophrase	# hostatement: up hierarchy
      ...
    end gtype myhi	# 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 characteristic	# e.g. option
	out  product			# output: product := subject do ... done
    	od   direct object		# input: argument list
	from initial characteristic	# e.g. input file
	to   final   characteristic	# e.g. output file
    done

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

subject  ::= wplist
object   ::= wplist

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
wplist           ::= list of wphrase     with separator=comma
bplist           ::= list of bphrase     with separator=comma
rplist           ::= list of relphrase   with separator=comma
proposition list ::= list of proposition with separator=conjunction

nvphrase ::=
	wphrase nvop value
value ::=
	wphrase
	[ wplist ]
	{ 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


wphrase ::= list of word with separator=whitespace
qphrase ::=
	wphrase
	quantifier wphrase
bphrase ::=
	qphrase
	qphrase and qphrase
	qphrase or  qphrase
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/kedef.ku 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/tabdef.ku
    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/kedef.ku 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/kedef.ku 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
