Section Under Construction
Introduction
The HistoryCal program has a built-in script language called HistoryCal Script. This is different from the input that has been described at the beginning of this manual, which is called a HistoryCal Date Expression. The Date Expression is similar to the script but is simplified and designed for easier input. The Date Expression is converted into a HistoryCal Script to be evaluated.
The script is designed to serve two main purposes.
- Define the calendar schemes and their associated grammar.
- Calculate and output complex calendar expressions.
The scripts for the default calendar definitions are shown in the calendar definitions section.
Hello World
A script consists of one or more statements. As is obligatory in these circumstances, we present a hello world script.
Hello Script |
---|
// Hello world script. writeln "Hello world!"; |
Using a text editor, copy the script and save as "hello.hcs". Run the HistoryCal Script by starting the HistoryCal program. Under the menu option "File > Run Script ..." find the file and select it. This should then result in the message shown.
Comments and White Space
The first line in the above script is a single line comment. Every thing from the "//" token to the end of the line taken to be a comment.
Multi-line comments can be included by placing them between the "/*" and "*/" tokens. Multi-line comments cannot be nested.
// A single line comment /* This is a multi-line comment. */ |
Tabs, spaces, newlines and comments can appear anywhere within a script without affecting its meaning. They are required only when necessary to separate tokens.
Expressions and Variables
Values in the HistoryCal Script can exist as one of a number of types:-
- String - A sequence of unicode (UTF-8) characters.
- Field - An integer number, a date or part of a date.
- Range - One or more consecutive dates.
- RList - A well-ordered list of dates.
- Record - A scheme code and sequence of Fields which describe a date.
- Boolean - The value true or false.
Variables are defined by using the let
statement,
but their type is determined by their context.
There are a number of operators which are used in expressions and
the values in these expressions are automatically converted, wherever possible.
Statements
A script consists of one or more of the following Statements:-
Statement List | ||
---|---|---|
Statement | Use | Example |
clear | Delete all variables. | clear; |
do | Run script until a condition is met. | do while y <= 2015 writeln "1 Jan " + y; y += 1; loop |
end | Stop running the script. | end; |
format | Define a Format for a grammar | format j:ydm, "(Year)| (Day)| (Month:m)"; |
grammar | Define a Grammar for a calendar. | grammar J { inherit j; format ydm, "(Year)| (Day)| (Month:m)"; } |
if | Run code depending on condition. | if value = today write "<b>" + str value + "</b>"; else write str value; endif |
let | Initialise or change a variable. | let d = 1; |
mark | Set a named mark in the script. | mark "test1"; |
scheme | Define a calendar Scheme. | scheme j { name "Julian"; base julian; } |
set | Set a global default setting. | set output g:iso; |
vocab | Define a Vocabulary for a calendar field. | vocab ce { name "Historic Era"; tokens { 0, "Before Christ", "BC"; 1, "anno Domini", "AD"; } } |
write | Create output. | write value + ", "; |
writeln | Create output, followed by a new line. | writeln "Today is " + str today; |