Skip to content

Updated Input Modes

gibbonsja edited this page Jan 9, 2022 · 2 revisions

Changes to Input Mode

Classic Nial has two basic modes of input, interactive terminal input and file input (using loaddefs).

In the interactive terminal mode Nial reads and evaluates one line at a time from the standard input. In this mode it is not possible to enter a multi-line statement at the terminal or to write a simple shell application in Nial using the here doc approach..

In the loaddefs mode Nial reads lines from a file and groups them into blocks terminated by lines of whitespace characters and evaluates the blocks one at time.

Updated Interactive Mode

The standard interactive mode has been enhanced to allow for multi-line input.

Entering the bang character (!) on a line by itself switches the input mode into multi-line input which is terminated by a single blank line.

This mode can also be used to better integrate Nial into an existing IDE.

The collected lines are joined together and submitted to the interpreter for evaluation as though they were a single line.

Batch Input Mode

The batch input mode is a combination of the interactive and loaddefs approaches and is aimed at reading Nial from the standard input in a non-interactive mode.

The goals are

  1. Easily supporting the integration of Nial with Editors and IDEs.
  2. Allowing for simple executable Nial programs that reside in one file.

Batch input mode is started by using the command line option -b instead of -i. All other options behave as normal.

Examples

Simple Nial Script

The following shows a simple (but corny :-)) UNIX style multi-line Nial script in one file.

#!/bin/sh
nial -b -- $* <<EOF

# This is a simple Nial script. It can be extended with loaddefs or 
# library statements and use all of Nial's primitives, operators etc.

write 'Merry Christmas';
i := 0;
while i < 3 do
  write 'Ho';
  i := i + 1;
end
EOF

The script can be saved in a file, e.g. hohoho, made executable using chmod +x hohoho and run as a standalone program.

Clone this wiki locally