icalc.icn: Program to simulate infix desk calculator

January 3, 1994; Stephen B. Wampler
This file is in the public domain.
This is a simple infix calculator with control structures and
  compound statements.  It illustrates a technique that can be
  easily used in Icon to greatly reduce the performance cost
  associated with recursive-descent parsing with backtracking.
  There are numerous improvements and enhancements that can be
  made.

Features include:

      - integer and real value arithmetic
      - variables
      - function calls to Icon functions
      - strings allowed as function arguments
      - unary operators:
            + (absolute value), - (negation)
      - assignment:
            :=
      - binary operators:
            +,-,*,/,%,^,
      - relational operators:
            =, !=, <, <=, >, >=
               (all return 1 for true and 0 for false)
      - compound statements in curly braces with semicolon separators
      - if-then and if-then-else
      - while-do
      - limited form of multiline input

The grammar at the start of the 'parser' proper provides more
  details.

Normally, the input is processed one line at a time, in calculator
  fashion.  However, compound statements can be continued across
  line boundaries.

Examples:

  Here is a simple input:

      {
      a := 10;
      while a >= 0 do {
         write(a);
         a := a - 1
         };
      write("Blastoff")
      }

   (execution is delayed until entire compound statement is entered)

  Another one:

  write(pi := 3.14159)
  write(sin(pi/2))

   (execution done as each line is entered)

Source code | Program Library Page | Icon Home Page