!PLEASE NOTE: IACC FILE TO GENERATE A COMPILER COMPATIBLE WITH C-INTERCAL
!                                              (HOPEFULLY)
!Copyright (c) 2006-2008, 2023 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/ick.src 1.-94.-2.4"
!
# INITIALISATIONS
%BA <- 2
%RT <- ?TRADITIONAL
%WT <- 0
%CR <- ?ASCII
%CW <- ?ASCII
%IO <- ?C
%CF <- 0
%RM <- 0
%SM <- 0
%GU <- 1
?TYPE <- ?COMPILER

# THE WHOLE PROGRAM
PROGRAM STATEMENT : STATEMENT

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

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

# STATEMENTS
STATEMENT MAYBE_LABEL DO_PLEASE QUALIFIERS VERB MAYBE_ONCE : \
	"STS" * MAYBE_LABEL DO_PLEASE QUALIFIERS MAYBE_ONCE VERB
# COMMENTS WITH A LABEL NEED TO STILL PARSE THE LABEL
STATEMENT STMT_LABEL : "STS" * "LAB" STMT_LABEL
MAYBE_LABEL :
MAYBE_LABEL STMT_LABEL : "LAB" STMT_LABEL
DO_PLEASE "DO" :
DO_PLEASE "PLEASE" MAYBE_DO : "BIT" 5
MAYBE_DO :
MAYBE_DO "DO" :
QUALIFIERS :
QUALIFIERS "%" CONSTANT QUALIFIERS : "DSX" CONSTANT QUALIFIERS
QUALIFIERS "NOT" QUALIFIERS : "NOT" QUALIFIERS
QUALIFIERS "N" "'" "T" QUALIFIERS : "NOT" QUALIFIERS
MAYBE_ONCE :
MAYBE_ONCE "ONCE" : "BIT" 3
MAYBE_ONCE "AGAIN" : "BIT" 4

# COMMENTS
VERB "NOT" JUNK : "NOT" "MSP" *COMMENT 1 JUNK
VERB "N" "'" "T" JUNK : "NOT" "MSP" *COMMENT 1 JUNK

# CALCULATE
CALCULATION LVALUE "<" "-" EXPRESSION : "STO" EXPRESSION LVALUE
CALCULATION ARRAY "<" "-" DIMENSION : "STO" "MUL" !DIMENSION DIMENSION ARRAY
VERB CALCULATION : CALCULATION
GERUND "CALCULATING"=1 : "STO"

# NEXT, RESUME, FORGET
VERB ICK_LABEL "NEXT" : "NXT" ICK_LABEL
GERUND "NEXTING"=1 : "NXT"
VERB "RESUME" EXPRESSION  : "RES" EXPRESSION
GERUND "RESUMING"=1 : "RES"
VERB "FORGET" EXPRESSION  : "FOR" EXPRESSION
GERUND "FORGETTING"=1 : "FOR"

# STASH, RETRIEVE
VERB "STASH" STASHNAMES : "STA" !STASHNAMES STASHNAMES
GERUND "STASHING"=1 : "STA"
VERB "RETRIEVE" NAMES : "RET" !NAMES NAMES
GERUND "RETRIEVING"=1 : "RET"

# IGNORE, REMEMBER
VERB "IGNORE" NAMES : "IGN" !NAMES NAMES
GERUND "IGNORING"=1 : "IGN"
VERB "REMEMBER" NAMES : "REM" !NAMES NAMES
GERUND "REMEMBERING"=1 : "REM"

# ABSTAIN, REINSTATE
VERB "ABSTAIN" "FROM" ABSTAIN : ABSTAIN
ABSTAIN ICK_LABEL : "ABL" ICK_LABEL
ABSTAIN GERUNDS : "ABG" !GERUNDS GERUNDS
GERUND "ABSTAINING"=2 : "ABL" "ABG"
VERB "REINSTATE" REINSTATE : REINSTATE
REINSTATE ICK_LABEL : "REL" ICK_LABEL
REINSTATE GERUNDS : "REG" !GERUNDS GERUNDS
GERUND "REINSTATING"=2 : "REL" "REG"
GERUNDS GERUND=* : GERUND
GERUNDS GERUND=* "+" GERUNDS=* : GERUND GERUNDS

# GIVE UP
VERB "GIVE" "UP" : "GUP"
# NO GERUND

# INPUT
VERB "WRITE" "IN" WVALUES : "WIN" !WVALUES WVALUES
GERUND "WRITING" "IN"=1 : "WIN"

# OUTPUT
VERB "READ" "OUT" RVALUES : "ROU" !RVALUES RVALUES
GERUND "READING" "OUT"=1 : "ROU"

# COME FROM
VERB "COME" "FROM" ICK_LABEL : "CFL" ICK_LABEL
GERUND "COMING" "FROM"=1 : "CFL"

# NAMES
NAME RNAME : RNAME
NAME ARRAY : ARRAY
NAMES NAME=1 : NAME
NAMES NAME=1 "+" NAMES=* : NAME NAMES
STASHNAMES NAME=1 : NAME
STASHNAMES NAME=1 "+" STASHNAMES=* : NAME STASHNAMES

# LVALUES
LVALUE RNAME : RNAME
LVALUE LELEMENT : LELEMENT

# RVALUES
RVALUE EXPRESSION : EXPRESSION
RVALUE ARRAY : ARRAY
RVALUES RVALUE=1 : RVALUE
RVALUES RVALUE=1 "+" RVALUES=* : RVALUE RVALUES

# WVALUES
WVALUE RNAME : RNAME
WVALUE LELEMENT : LELEMENT
WVALUE ARRAY : ARRAY
WVALUES WVALUE=1 : WVALUE
WVALUES WVALUE=1 "+" WVALUES=* : WVALUE WVALUES

# REGISTERS
REGISTER "." UNARIES CONSTANT : UNARIES "SPO" CONSTANT
REGISTER ":" UNARIES CONSTANT : UNARIES "TSP" CONSTANT
RNAME "." CONSTANT : "SPO" CONSTANT
RNAME ":" CONSTANT : "TSP" CONSTANT

# ARRAYS
ARRAY "," CONSTANT : "TAI" CONSTANT
ARRAY ";" CONSTANT : "HYB" CONSTANT

# ARRAY ELEMENTS
ELEMENT "," UNARIES CONSTANT SUBSCRIPTS : UNARIES SUBSCRIPTS "TAI" CONSTANT
ELEMENT ";" UNARIES CONSTANT SUBSCRIPTS : UNARIES SUBSCRIPTS "HYB" CONSTANT
LELEMENT "," CONSTANT SUBSCRIPTS : SUBSCRIPTS "TAI" CONSTANT
LELEMENT ";" CONSTANT SUBSCRIPTS : SUBSCRIPTS "HYB" CONSTANT
SUBSCRIPTS "SUB" EXPRESSION MORE_SUBSCRIPTS : MORE_SUBSCRIPTS "SUB" EXPRESSION
MORE_SUBSCRIPTS :
MORE_SUBSCRIPTS EXPRESSION MORE_SUBSCRIPTS : MORE_SUBSCRIPTS "SUB" EXPRESSION

# EXPRESSIONS WITHOUT BINARY OPERATORS (EXCEPT GROUPING)
NONUNARIES REGISTER : REGISTER
NONUNARIES ELEMENT : ELEMENT
NONUNARIES "#" UNARIES CONSTANT : UNARIES CONSTANT
NONUNARIES "'" UNARIES EXPRESSION "'" : UNARIES EXPRESSION
NONUNARIES '"' UNARIES EXPRESSION '"' : UNARIES EXPRESSION

# SPECIAL TREATMENT FOR THE "!"
BANG "!" UNARIES CONSTANT : UNARIES "SPO" CONSTANT
NONUNARIES BANG MAYBE_BINARY "'" : MAYBE_BINARY BANG
RABBIT '".' UNARIES CONSTANT : UNARIES "SPO" CONSTANT
NONUNARIES RABBIT MAYBE_BINARY '"' : MAYBE_BINARY RABBIT

# EXPRESSIONS
EXPRESSION NONUNARIES MAYBE_BINARY : MAYBE_BINARY NONUNARIES

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

# BINARY OPERATORS
MAYBE_BINARY :
MAYBE_BINARY BINARY EXPRESSION : BINARY EXPRESSION
BINARY "~" : "RSE"
BINARY "C/" : "RIN"
BINARY "C|" : "RIN"
BINARY "¢" : "RIN"
BINARY "$" : "RIN"
BINARY "¥" : "RIN"
BINARY "£" : "RIN"

# DIMENSIONS
DIMENSION EXPRESSION=1 : EXPRESSION
DIMENSION EXPRESSION=1 "BY" DIMENSION=* : EXPRESSION DIMENSION

# LABELS
STMT_LABEL "(" CONSTANT ")" : CONSTANT
ICK_LABEL "(" CONSTANT ")" : CONSTANT

