!PLEASE NOTE: IACC FILE TO GENERATE A COMPILER FOR CLC-INTERCAL
!
!Copyright (c) 2006-2008, 2023-2024 Claudio Calvelli, all rights reserved.
!
!CLC-INTERCAL is copyrighted software. However, permission to use, modify,
!and distribute it is granted provided that the conditions set out in the
!licence agreement are met. See files README and COPYING in the distribution.
!
!PERVERSION "CLC-INTERCAL/Base aux/sick.prefix 1.00"
!
# INITIALISATIONS
%BA <- 2
%RT <- ?CLC
%WT <- 0
%IO <- ?CLC
%CR <- ?ASCII
%CW <- ?ASCII
%CF <- 0
%DM <- 0
%RM <- 1
%SM <- 1
?TYPE <- ?COMPILER

# THE WHOLE PROGRAM
PROGRAM STATEMENT : STATEMENT

# FOR INTERCALC
CALC_EXPR EXPRESSION : "STS" * "ROU" 1 EXPRESSION
CALC_EXPR CALCULATION : "STS" * CALCULATION
CALC_FULL EXPRESSION : "STS" * "ROU" 1 EXPRESSION
CALC_FULL STATEMENT : STATEMENT

# DETERMINE END OF A COMMENT
END_JUNK STMT_LABEL :
END_JUNK DO_PLEASE :
END_JUNK "NAVALNY" :

# STATEMENTS
STATEMENT MAYBE_STMT_LABEL DO_PLEASE QUALIFIERS WVERB MAYBE_ONCE : \
	"STS" * MAYBE_STMT_LABEL DO_PLEASE QUALIFIERS MAYBE_ONCE WVERB
# COMMENTS WITH A LABEL NEED TO STILL PARSE THE LABEL
STATEMENT STMT_LABEL : "STS" * "LAB" STMT_LABEL
STMT_LABEL "(" CONSTANT ")" : CONSTANT
MAYBE_STMT_LABEL :
MAYBE_STMT_LABEL STMT_LABEL : "LAB" STMT_LABEL
DO_PLEASE "DO" :
DO_PLEASE "PLEASE" : "BIT" 5
DO_PLEASE "PLEASE" "DO" : "BIT" 5
QUALIFIERS :
QUALIFIERS DOUBLE_OH_SEVEN QUALIFIERS : DOUBLE_OH_SEVEN QUALIFIERS
QUALIFIERS NOT QUALIFIERS : NOT QUALIFIERS
DOUBLE_OH_SEVEN "%" CONSTANT : "DSX" CONSTANT
DOUBLE_OH_SEVEN "%" EXPRESSION : "DSX" EXPRESSION
NOT "NOT" : "NOT"
NOT "N" "'" "T" : "NOT"
NOT "¬" : "NOT"
MAYBE_ONCE :
MAYBE_ONCE "ONCE" MAYBE_AGAIN : "BIT" 3 MAYBE_AGAIN
MAYBE_ONCE "AGAIN" : "BIT" 4
MAYBE_AGAIN :
MAYBE_AGAIN "AND" "AGAIN" : "BIT" 4

# COMMENTS
WVERB NOT JUNK : "NOT" "MSP" *COMMENT 1 JUNK

# SUB-STATEMENTS AND LOOPS
WVERB VERB MAYBE_WHILE : MAYBE_WHILE VERB
WVERB EXPRESSION "WHILE" VERB : "ECB" EXPRESSION VERB
MAYBE_WHILE :
MAYBE_WHILE "WHILE" VERB : "CWB" VERB
MAYBE_WHILE "WHILE" EXPRESSION : "EBC" EXPRESSION
TEMPLATE "CONDITION" "WHILE" "BODY" : "CWB"
TEMPLATE "BODY" "WHILE" "CONDITION" : "BWC"
TEMPLATE "EXPRESSION" "WHILE" "STATEMENT" : "ECB"
TEMPLATE "STATEMENT" "WHILE" "EXPRESSION" : "EBC"
GERUND "LOOPING"=4 : "CWB" "BWC" "ECB" "EBC"
GERUND "WHILING"=4 : "CWB" "BWC" "ECB" "EBC"

# COMMENTS, BUGS AND STRAY GERUNDS
GERUND "COMMENTING"=1 : "MSP"
GERUND "COMMENTS"=1 : "MSP"
GERUND "COMPILER" "BUG"=1 : "BUG"
GERUND "QUANTUM" "COMPUTING"=1 : "QUA"
# NO TEMPLATE FOR COMMENTS AND BUGS

# CALCULATE
CALCULATION EXPRESSION "<" "-" EXPR_OR_DIM Q_CALCULATE : \
	Q_CALCULATE "STO" EXPR_OR_DIM EXPRESSION
VERB CALCULATION : CALCULATION
GERUND "CALCULATING"=1 : "STO"
TEMPLATE REG_EXPR "<" "-" "EXPRESSION" MAYBE_LIST : "STO"
Q_CALCULATE :
Q_CALCULATE "WHILE" "NOT" "ASSIGNING" "TO" "IT" : "QUA"

# STASH, RETRIEVE
VERB "STASH" NAMES Q_STASH : Q_STASH "STA" !NAMES NAMES
GERUND "STASHING"=1 : "STA"
TEMPLATE "STASH" "REGISTER" MAYBE_LIST : "STA"
Q_STASH :
Q_STASH "WHILE" "NOT" "STASHING" IT : "QUA"
VERB "RETRIEVE" NAMES Q_RETRIEVE : Q_RETRIEVE "RET" !NAMES NAMES
GERUND "RETRIEVING"=1 : "RET"
TEMPLATE "RETRIEVE" "REGISTER" MAYBE_LIST : "RET"
Q_RETRIEVE :
Q_RETRIEVE "WHILE" "NOT" "RETRIEVING" IT : "QUA"

# IGNORE, REMEMBER
VERB "IGNORE" NAMES Q_IGNORE : Q_IGNORE "IGN" !NAMES NAMES
GERUND "IGNORING"=1 : "IGN"
TEMPLATE "IGNORE" "REGISTER" MAYBE_LIST : "IGN"
Q_IGNORE :
Q_IGNORE "WHILE" "REMEMBERING" IT : "QUA"
VERB "REMEMBER" NAMES Q_REMEMBER : Q_REMEMBER "REM" !NAMES NAMES
GERUND "REMEMBERING"=1 : "REM"
TEMPLATE "REMEMBER" "REGISTER" MAYBE_LIST : "REM"
Q_REMEMBER :
Q_REMEMBER "WHILE" "IGNORING" IT : "QUA"

# ABSTAIN, REINSTATE
VERB "ABSTAIN" "FROM" ABSTAIN Q_ABSTAIN : Q_ABSTAIN ABSTAIN
ABSTAIN LABEL : "ABL" LABEL
ABSTAIN AGERUNDS : "ABG" !AGERUNDS AGERUNDS
GERUND "ABSTAINING"=2 "FROM" : "ABL" "ABG"
GERUND "ABSTAINING"=2 : "ABL" "ABG"
TEMPLATE "ABSTAIN" "FROM" "LABEL" : "ABL"
TEMPLATE "ABSTAIN" "FROM" "GERUND" MAYBE_LIST : "ABG"
Q_ABSTAIN :
Q_ABSTAIN "WHILE" "REINSTATING" IT : "QUA"
VERB "REINSTATE" REINSTATE Q_REINSTATE : Q_REINSTATE REINSTATE
REINSTATE LABEL : "REL" LABEL
REINSTATE AGERUNDS : "REG" !AGERUNDS AGERUNDS
GERUND "REINSTATING"=2 : "REL" "REG"
TEMPLATE "REINSTATE" "LABEL" : "REL"
TEMPLATE "REINSTATE" "GERUND" MAYBE_LIST : "REG"
GERUND TEMPLATE=1 : TEMPLATE
GERUNDS GERUND=* : GERUND
GERUNDS GERUND=* "+" GERUNDS=* : GERUND GERUNDS
AGERUNDS AGERUND=* : AGERUND
AGERUNDS AGERUND=* "+" AGERUNDS=* : AGERUND AGERUNDS
AGERUND GERUND=* : GERUND
AGERUND "EVOLUTION"=1 : 0
Q_REINSTATE :
Q_REINSTATE "WHILE" "ABSTAINING" "FROM" IT : "QUA"

# GIVE UP
VERB "GIVE" "UP" Q_GIVE_UP : Q_GIVE_UP "GUP"
GERUND "GIVING" "UP"=1 : "GUP"
GERUND "GIVING"=1 : "GUP"
TEMPLATE "GIVE" "UP" : "GUP"
Q_GIVE_UP :
Q_GIVE_UP "WHILE" "CONTINUING" "TO" "RUN" : "QUA"
# SNEAKING IN A MESSAGE FROM NAVALNY
STATEMENT MAYBE_STMT_LABEL "NAVALNY" : "STS" * MAYBE_STMT_LABEL "NOT" "GUP"

# INPUT
VERB "WRITE" "IN" E_LIST Q_WRITE_IN : Q_WRITE_IN "WIN" !E_LIST E_LIST
GERUND "WRITING" "IN"=1 : "WIN"
GERUND "WRITING"=1 : "WIN"
TEMPLATE "WRITE" "IN" REG_EXPR MAYBE_LIST : "WIN"
Q_WRITE_IN :
Q_WRITE_IN "WHILE" "NOT" "WRITING" IT MAYBE_IN : "QUA"
MAYBE_IN :
MAYBE_IN "IN" :

# OUTPUT
VERB "READ" "OUT" E_LIST : "ROU" !E_LIST E_LIST
GERUND "READING" "OUT"=1 : "ROU"
GERUND "READING"=1 : "ROU"
TEMPLATE "READ" "OUT" REG_EXPR MAYBE_LIST : "ROU"
!PLEASE NOTE: NO QUANTUM OUTPUT (YET)

# COME FROM
VERB "COME" "FROM" COME_FROM Q_COME_FROM : Q_COME_FROM COME_FROM
COME_FROM LABEL : "CFL" LABEL
COME_FROM GERUNDS : "CFG" !GERUNDS GERUNDS
GERUND "COMING" "FROM"=2 : "CFL" "CFG"
GERUND "COMING"=2 : "CFL" "CFG"
TEMPLATE "COME" "FROM" "LABEL" : "CFL"
TEMPLATE "COME" "FROM" "GERUND" MAYBE_LIST : "CFG"
Q_COME_FROM :
Q_COME_FROM "WHILE" "NOT" "COMING" "FROM" "THERE" : "QUA"

# MAKE BELONG
VERB "MAKE" RNAME "BELONG" "TO" RNAME Q_MAKE_BELONG : Q_MAKE_BELONG "MKB" RNAME=1 RNAME=2
GERUND "MAKING" "BELONG"=1 : "MKB"
TEMPLATE "MAKE" "REGISTER" "BELONG" "TO" "REGISTER" : "MKB"
Q_MAKE_BELONG :
Q_MAKE_BELONG "WHILE" "LEAVING" "IT" "NOT" "BELONGING" : "QUA"

# OLD SYNTAX FOR MAKE BELONG
VERB "ENSLAVE" RNAME "TO" RNAME Q_ENSLAVE : Q_ENSLAVE "MKB" RNAME=1 RNAME=2
GERUND "ENSLAVING"=1 : "MKB"
TEMPLATE "ENSLAVE" "REGISTER" "TO" "REGISTER" : "MKB"
Q_ENSLAVE :
Q_ENSLAVE "WHILE" "LEAVING" "IT" "FREE" : "QUA"

# NO LONGER BELONG
VERB "MAKE" RNAME "NO" "LONGER" "BELONG" "TO" RNAME Q_NLB : Q_NLB "NLB" RNAME=1 RNAME=2
GERUND "MAKING" "NOT" "BELONG"=1 : "NLB"
TEMPLATE "MAKE" "REGISTER" "NO" "LONGER" "BELONG" "TO" "REGISTER" : "NLB"
Q_NLB :
Q_NLB "WHILE" "LEAVING" "IT" "BELONGING" : "QUA"

# OLD SYNTAX FOR NO LONGER BELONG
VERB "FREE" RNAME "FROM" RNAME Q_FREE : Q_FREE "NLB" RNAME=1 RNAME=2
GERUND "FREEING"=1 : "NLB"
TEMPLATE "FREE" "REGISTER" "FROM" "REGISTER" : "NLB"
Q_FREE :
Q_FREE "WHILE" "LEAVING" "IT" "IN" "SLAVERY" : "QUA"

# STUDY
VERB "STUDY" EXPRESSION "AT" LABEL "IN" "CLASS" RNAME Q_STUDY : \
	Q_STUDY "STU" EXPRESSION LABEL RNAME
GERUND "STUDYING"=1 : "STU"
TEMPLATE "STUDY" EXPR_OR_SUBJECT "AT" "LABEL" "IN" "CLASS" "REGISTER" : "STU"
EXPR_OR_SUBJECT "EXPRESSION" :
EXPR_OR_SUBJECT "SUBJECT" :
Q_STUDY :
Q_STUDY "WHILE" "NOT" "STUDYING" "IT" : "QUA"

# ENROL
VERB "ENROL" RNAME "TO" "LEARN" E_LIST Q_ENROL : \
	Q_ENROL "ENR" !E_LIST E_LIST RNAME
GERUND "ENROLLING"=1 : "ENR"
TEMPLATE "ENROL" "REGISTER" "TO" "LEARN" EXPR_OR_SUBJECT MAYBE_LIST : "ENR"
Q_ENROL :
Q_ENROL "WHILE" "NOT" "ENROLLING" : "QUA"

# LEARNS OR GRADUATES
VERB RNAME LEARNS_GRADUATES : LEARNS_GRADUATES RNAME

# LEARNS
#VERB RNAME "LEARNS" EXPRESSION Q_LEARNS : Q_LEARNS "LEA" EXPRESSION RNAME
LEARNS_GRADUATES "LEARNS" EXPRESSION Q_LEARNS : Q_LEARNS "LEA" EXPRESSION
GERUND "LEARNING"=1 : "LEA"
TEMPLATE "REGISTER" "LEARNS" EXPR_OR_SUBJECT : "LEA"
Q_LEARNS :
Q_LEARNS "WHILE" "NOT" "LEARNING" "IT" : "QUA"

# FINISH LECTURE
VERB "FINISH" "LECTURE" Q_FINISH : Q_FINISH "FIN"
GERUND "FINISHING" "LECTURE"=1 : "FIN"
GERUND "FINISHING"=1 : "FIN"
TEMPLATE "FINISH" "LECTURE" : "FIN"
Q_FINISH :
Q_FINISH "WHILE" "CONTINUING" "IT" : "QUA"

# GRADUATES
#VERB RNAME "GRADUATES" Q_GRADUATES : Q_GRADUATES "GRA" RNAME
LEARNS_GRADUATES "GRADUATES" Q_GRADUATES : Q_GRADUATES "GRA"
GERUND "GRADUATING"=1 : "GRA"
TEMPLATE "REGISTER" "GRADUATES" : "GRA"
Q_GRADUATES :
Q_GRADUATES "WHILE" "REMAINING" "A" "STUDENT" : "QUA"

# NEXT FROM
VERB "NEXT" "FROM" NEXT_FROM Q_NEXT_FROM : Q_NEXT_FROM NEXT_FROM
NEXT_FROM LABEL : "NXL" LABEL
MEXT_FROM GERUNDS : "NXG" !GERUNDS GERUNDS
GERUND "NEXTING" "FROM"=2 : "NXL" "NXG"
TEMPLATE "NEXT" "FROM" "LABEL" : "NXL"
TEMPLATE "NEXT" "FROM" "GERUND" MAYBE_LIST : "NXG"
Q_NEXT_FROM :
Q_NEXT_FROM "WHILE" "NOT" "NEXTING" "FROM" "THERE" : "QUA"

# CONVERT
VERB "CONVERT" TEMPLATE "TO" TEMPLATE Q_CONVERT : \
	Q_CONVERT "CON" TEMPLATE=1 TEMPLATE=2
GERUND "CONVERTING"=3 : "CON"
TEMPLATE "CONVERT" "STATEMENT" "TO" "STATEMENT" : "CON"
Q_CONVERT :
Q_CONVERT "WHILE" "LEAVING" "IT" "UNCHANGED" : "QUA"

# SWAP
VERB "SWAP" TEMPLATE "AND" TEMPLATE Q_SWAP : \
	Q_SWAP "SWA" TEMPLATE=1 TEMPLATE=2
GERUND "SWAPPING"=2 : "SWA"
TEMPLATE "SWAP" "STATEMENT" "AND" "STATEMENT" : "SWA"
Q_SWAP :
Q_SWAP "WHILE" "LEAVING" "THEM" "UNCHANGED" : "QUA"

# CREATE
VERB "CREATE" GSYMBOL LEFT "AS" RIGHT Q_CREATE : \
	Q_CREATE "CRE" 1 GSYMBOL !LEFT LEFT !RIGHT RIGHT
GERUND "CREATING"=1 : "CRE"
GERUND "CREATION"=1 : "CRE"
TEMPLATE "CREATE" "SYMBOL" "LEFT" "AS" "RIGHT" : "CRE"
Q_CREATE :
Q_CREATE "WHILE" "NOT" "CREATING" "IT" : "QUA"

# DESTROY
VERB "DESTROY" GSYMBOL LEFT Q_DESTROY : \
	Q_DESTROY "DES" 1 GSYMBOL !LEFT LEFT
GERUND "DESTROYING"=1 : "DES"
GERUND "DESTRUCTION"=1 : "DES"
TEMPLATE "DESTROY" "SYMBOL" "EXPRESSION" "LEFT" : "DES"
Q_DESTROY :
Q_DESTROY "WHILE" "NOT" "DESTROYING" "IT" : "QUA"

# RESUME AND FORGET ARE NEEDED OTHERWISE NEXT FROM IS RATHER USELESS
VERB "RESUME" EXPRESSION Q_RESUME : Q_RESUME "RES" EXPRESSION
GERUND "RESUMING"=1 : "RES"
TEMPLATE "RESUME" "EXPRESSION" : "RES"
Q_RESUME :
Q_RESUME "WHILE" "NOT" "RESUMING" : "QUA"

VERB "FORGET" EXPRESSION Q_FORGET : Q_FORGET "FOR" EXPRESSION
GERUND "FORGETTING"=1 : "FOR"
TEMPLATE "FORGET" "EXPRESSION" : "FOR"
Q_FORGET :
Q_FORGET "WHILE" "NOT" "FORGETTING" : "QUA"
Q_FORGET "WHILE" "REMEMBERING" : "QUA"

# ROAD CLOSURES AND DIVERSIONS
VERB "CLOSE" "OFF" "BETWEEN" LABEL "AND" LABEL \
    "AND" "DIVERT" "VIA" LABEL "TO" LABEL Q_CLOSE : \
	Q_CLOSE "DIV" LABEL=1 LABEL=2 LABEL=3 LABEL=4
GERUND "CLOSING" "OFF"=1 : "DIV"
GERUND "DIVERTING"=1 : "DIV"
TEMPLATE "CLOSE" "OFF" "BETWEEN" "LABEL" "AND" "LABEL" \
    "AND" "DIVERT" "VIA" "LABEL" "TO" "LABEL" : "DIV"
Q_CLOSE :
Q_CLOSE "WHILE" "LEAVING" "IT" "OPEN" : "QUA"

# ROAD REOPENING
VERB "REOPEN" "BETWEEN" LABEL "AND" LABEL Q_REOPEN : \
	Q_REOPEN "REO" LABEL=1 LABEL=2
GERUND "REOPENING"=1 : "REO"
TEMPLATE "REOPEN" "BETWEEN" "LABEL" "AND" "LABEL" : "REO"
Q_REOPEN :
Q_REOPEN "WHILE" "LEAVING" "IT" "CLOSED" : "QUA"

# TRICKLE DOWN
VERB "TRICKLE" REGISTER "DOWN" "TO" NAMES "AFTER" EXPRESSION Q_TRICKLE : \
	Q_TRICKLE "TRD" REGISTER EXPRESSION !NAMES NAMES
GERUND "TRICKLING" "DOWN"=1 : "TRD"
TEMPLATE "TRICKLE" "REGISTER" "DOWN" "TO" "REGISTER" MAYBE_LIST \
	"AFTER" "EXPRESSION" : "TRD"
Q_TRICKLE : 
Q_TRICKLE "WHILE" "LEAVING" IT "TRUSSED" "UP" : "QUA"

# TRUSS UP
VERB "TRUSS" NAMES "UP" Q_TRUSS : Q_TRUSS "TRU" !NAMES NAMES
GERUND "TRUSSING" "UP"=1 : "TRU"
TEMPLATE "TRUSS" "REGISTER" MAYBE_LIST "UP" : "TRD"
Q_TRUSS : 
Q_TRUSS "WHILE" "LEAVING" IT "TRICKLING" "DOWN" : "QUA"

# NAMES
NAMES RNAME=1 : RNAME
NAMES RNAME=1 "+" NAMES=* : RNAME NAMES

# REGISTERS
RTYPE "." : "SPO"
RTYPE ":" : "TSP"
RTYPE "," : "TAI"
RTYPE ";" : "HYB"
RTYPE "@" : "WHP"
RTYPE "_" : "CHO"
RTYPE "+" REGISTER : "TYP" REGISTER
RNUMBER CONSTANT : CONSTANT
RNUMBER "-" REGISTER : "NUM" REGISTER
RNAME BELONGS RTYPE RNUMBER : BELONGS RTYPE RNUMBER
REGISTER BELONGS RTYPE UNARIES RNUMBER : UNARIES BELONGS RTYPE RNUMBER
REGISTER BELONGS "+" UNARIES REGISTER RNUMBER : \
	UNARIES BELONGS "TYP" REGISTER RNUMBER

# BELONGING PATH
BELONGS :
BELONGS BELONG BELONGS : BELONGS BELONG
BELONG "$" : "BLM" 1
BELONG "1" : "BLM" 1
BELONG "2" : "BLM" 2
BELONG "3" : "BLM" 3
BELONG "4" : "BLM" 4
BELONG "5" : "BLM" 5
BELONG "6" : "BLM" 6
BELONG "7" : "BLM" 7
BELONG "8" : "BLM" 8
BELONG "9" : "BLM" 9

# ARRAY ELEMENTS
ELEMENT BELONGS RTYPE UNARIES CONSTANT SUBSCRIPTS : \
	UNARIES SUBSCRIPTS BELONGS RTYPE CONSTANT
LELEMENT BELONGS RTYPE CONSTANT SUBSCRIPTS : \
	SUBSCRIPTS BELONGS RTYPE CONSTANT
SUBSCRIPTS "SUB" EXPRESSION MORE_SUBSCRIPTS : MORE_SUBSCRIPTS "SUB" EXPRESSION
MORE_SUBSCRIPTS :
MORE_SUBSCRIPTS "SUB" EXPRESSION MORE_SUBSCRIPTS : MORE_SUBSCRIPTS "SUB" EXPRESSION
MORE_SUBSCRIPTS EXPRESSION MORE_SUBSCRIPTS : MORE_SUBSCRIPTS "SUB" EXPRESSION

# EXPRESSIONS WITHOUT BINARY OPERATORS (EXCEPT IN GROUPS)
NONUNARIES REGISTER : REGISTER
NONUNARIES ELEMENT : ELEMENT
NONUNARIES "-" REGISTER : "NUM" REGISTER
NONUNARIES "#" UNARIES CONSTANT : UNARIES CONSTANT
NONUNARIES "'" UNARIES EXPRESSION "'" : UNARIES EXPRESSION
NONUNARIES '"' UNARIES EXPRESSION '"' : UNARIES EXPRESSION
NONUNARIES "*" : "SPL"

# SPECIAL TREATMENT FOR THE "!"
BANG RNUMBER : "SPO" RNUMBER
BANG_U UNARIES RNUMBER : UNARIES "SPO" RNUMBER
NONUNARIES BANG_U MAYBE_BINARY "'" : MAYBE_BINARY BANG_U
NONUNARIES BANG "/" EXPRESSION "'" : "OVR" EXPRESSION BANG
NONUNARIES BANG_U "\" EXPRESSION "'" : "OVM" EXPRESSION BANG_U
RABBIT_U '".' UNARIES CONSTANT : UNARIES "SPO" CONSTANT
RABBIT '".' CONSTANT : "SPO" CONSTANT
NONUNARIES RABBIT_U MAYBE_BINARY '"' : MAYBE_BINARY RABBIT_U
NONUNARIES RABBIT "/" EXPRESSION '"' : "OVR" EXPRESSION RABBIT
NONUNARIES RABBIT_U "\" EXPRESSION '"' : "OVM" EXPRESSION RABBIT_U

# EXPRESSIONS
EXPRESSION NONUNARIES MAYBE_BINARY : MAYBE_BINARY NONUNARIES
EXPRESSION OVERLOADABLE "/" EXPRESSION : "OVR" EXPRESSION OVERLOADABLE

# LISTS OF EXPRESSIONS
E_LIST EXPRESSION=1 : EXPRESSION
E_LIST EXPRESSION=1 "+" E_LIST=* : EXPRESSION E_LIST

# UNARY OPERATORS
UNARIES :
UNARIES UNARY UNARIES : UNARY UNARIES
UNARY "V" : "IOR"
UNARY "&" : "AND"
UNARY "V-" : "SWB"
UNARY "¥" : "SWB"
UNARY "?" : "BUT" 1
UNARY "1" "?" : "BUT" 1
UNARY "2" "?" : "BUT" 2
UNARY "3" "?" : "BUT" 3
UNARY "4" "?" : "BUT" 4
UNARY "5" "?" : "BUT" 5
UNARY "|" : "AWC"
UNARY "-" : "UDV"

# BINARY OPERATORS
MAYBE_BINARY :
MAYBE_BINARY BINARY EXPRESSION : BINARY EXPRESSION
BINARY "~" : "RSE"
BINARY "C/" : "RIN"
BINARY "C|" : "RIN"
BINARY "¢" : "RIN"
BINARY "\" : "OVM"

# OVERLOADABLES
OVERLOADABLE REGISTER : REGISTER
OVERLOADABLE LELEMENT : LELEMENT

# DIMENSIONS
EXPR_OR_DIM EXPRESSION : EXPRESSION
EXPR_OR_DIM DIMENSION : "MUL" !DIMENSION DIMENSION
DIMENSION EXPRESSION=1 "BY" EXPRESSION=1 MORE_DIMENSION=* : \
	EXPRESSION=1 EXPRESSION=2 MORE_DIMENSION
MORE_DIMENSION :
MORE_DIMENSION "BY" EXPRESSION=1 MORE_DIMENSION=* : EXPRESSION MORE_DIMENSION

# LABELS
LABEL "(" CONSTANT ")" : CONSTANT
LABEL "(" EXPRESSION  ")" : EXPRESSION
LABEL EXPRESSION : EXPRESSION

# IT, THEM - WE COUNT THEM AS EQUIVALENT
IT "IT" :
IT "THEM" :
THEM "THEM" :
THEM "IT" :

# GRAMMAR FOR "CREATE"
LEFT :
LEFT LP=1 MAYBE_COUNT LEFT=* : MAYBE_COUNT LP LEFT
LP GSYMBOL : 0 GSYMBOL
LP "," E_LIST "," : 1 "MUL" !E_LIST E_LIST
LP "," "," : 1 "STR" 0
LP "," SYMBOL "," : 1 SYMBOL
MAYBE_COUNT : 0
MAYBE_COUNT "=" CONSTANT : CONSTANT
##MAYBE_COUNT "=" EXPRESSION : EXPRESSION
MAYBE_COUNT "=" "*" : 65535

# CODE GENERATOR FOR "CREATE"
RIGHT :
RIGHT RIGHT_NONEMPTY=* : RIGHT_NONEMPTY
RIGHT_NONEMPTY RP=1 MORE_RIGHT=* : RP MORE_RIGHT
MORE_RIGHT :
MORE_RIGHT "+" RIGHT_NONEMPTY=* : RIGHT_NONEMPTY
RP GSYMBOL EXPRESSION : 0 EXPRESSION GSYMBOL
RP "," E_LIST "," EXPRESSION : 1 EXPRESSION "MUL" !E_LIST E_LIST
RP "," "," : 4 0
RP "," SYMBOL "," EXPRESSION : 1 EXPRESSION SYMBOL
RP BYTECODE : 4 !BYTECODE BYTECODE
RP "!" GSYMBOL EXPRESSION : 6 EXPRESSION GSYMBOL
RP "**" : 15

# EXTENSIONS TO BYTECODE DEFINITION
BYTECODE SPECIAL_REGISTER=* : SPECIAL_REGISTER
BYTECODE EXPRESSION=1 : EXPRESSION
BC_LIST BYTECODE=* OTHER_BC=* : BYTECODE OTHER_BC
OTHER_BC :
OTHER_BC "+" BC_LIST=* : BC_LIST

# MISC SYMBOLS USED IN TEMPLATES
REG_EXPR "REGISTER" :
REG_EXPR "EXPRESSION" :
MAYBE_LIST :
MAYBE_LIST "LIST" :

# INTERNAL SYMBOL TABLE
GSYMBOL "?" SYMBOL : SYMBOL

!
!PLEASE NOTE:  BYTECODE DEFINITION (FROM THE ASSEMBLER)
