Definition
for the programming language
ICPL


Note: For browsers that do not properly interpret this page correctly, the symbol "®" is intended to be a right arrow and the symbol "e" is intended to be an epsilon.  Nonterminal elements are printed in italic.  Terminal elements are printed in bold.  Symbol tokens are quoted.

mainprogram ® program identifier declarations begin stmt_seq end identifier '.'
        beginning and ending identifiers must be the same.

declarations ® type_declarations  subprogram_declarations

subprogram_declarations ®  procedure_declaration subprogram_declarations
subprogram_declarations  ® e

procedure_declaration  ®   type procedure identifier';' type_declarations begin stmt_seq end identifier '.'
        All variables declared within the procedure will be local.
        If the procedure returns the type void it is a procedure and will be called by a statement.
        If the procedure returns a type other than void it is to be considered a function and must be called
        within an expression.  Within a function, the keyword result  will be considered a write-only identifier.
        The value assigned to result will be the value returned by the  function.  Thus the data type of result
        is the return type of the function.  The keyword result may be used only within the body of a function.

type_declarations ® type id_list ';' { type id_list ';' }
type_declarations ® e
        all identifiers must be declared prior to their use.  The compiler must assign static
        addresses to all variables.

type ® integer | real | string | boolean | void
        all integers are to be 32 bit integers, reals will be the C++ float, boolean can take on the values 0 and -1.

id_list ® identifier { ',' id_list }

stmt_seq ® stmt { ';' stmt_seq }

stmt ® e | if_stmt | loop_stmt | exit_stmt | assignment_stmt | get_stmt | put_stmt | putln_stmt | procedure_call

if_stmt ® if expression then stmt_seq { elseif expression then stmt_seq } [ else stmt_seq ] end if
    The expressions will be considered true if non-zero and false if zero.  The block associated with the first true
    expression will be executed.  If no expression is true then the block associated with the else, if present,
    will be executed.  Otherwise, if no expression is true then the is statement is to have no effect.

loop_stmt ® loop stmt_seq end loop
    The statement sequence is to repeatedly execute until an included exit statement causes the loop to terminate.

exit_stmt ® when expression exit
    If the expression is true then the program is to branch to the end of the inner-most loop statement.  If the
    exit statement is not within a loop then an error occurs and the program should not compile.

assignment_stmt ® identifier ':=' expression
    The expression on the right is to be evaluated with the result stored at the address of the identifier on the left.

procedure_call ® identifier
    The identifier must be a declared procedure whose return type is void, not a function.
    This statement will result in the statements of the procedure being executed.  Upon completion of that execution
    the program will resume after the procedure call.

get_stmt ® get identifier
    The identifier will be obtained in character form from the standard input stream and stored at the address of the identifier.

put_stmt ® put expression
    The expression will be evaluated and the result transmitted to the standard output stream in character form.

put_stmt ® put str_const
    The value of the string constand will be transmitted to the standard output stream.

putln_stmt ® putln
    An end of line will be transmitted to the standard output stream.

expression ®  [ not ] rel_exp {bool_op rel_exp }
    The not will be applied to the first relational expression in the list.  The order of operation is left to right.
    The boolean operators will assume that 0 represents false and not zero represents true.  All boolean operators,
    including not, are to return 0 for false and -1 for true.

rel_exp ® add_exp {rel_op add_exp }
    The order of operation is left to right.  A relational operator will return the value 0 if the result is false
    and the value -1 if the result is true.  The order of operation is left to right.

add_exp ® [ add_op ] term { add_op term }
    The first (optional) addition operator is to be applied as a unary operator to the first term.
    The order of operation is left to right.

term ® factor { mult_op factor }
    The order of operation is left to right.

factor ® expfactor {exp_op expfactor }
    The order of operation is left to right.

expfactor ® identifier | int_const | '(' expression ')'
    The value of a variable identifier is the contents at its address.
    The value of a function identifier is the result returned by the execution of the
    The value of an integer constant is the normal evaluation of that constant.
        If the value is outside of the range -2147483648 to 2147483647 it is an error.
    The value of a string constant is that constant without the quotes.
    The value of a real constant is the normal evaluation of that constant.