#!/bin/bash

# Several declaration and initialisation variants for test of Analyser, Executor, and Generators 
# (generated by Structorizer 3.32-33) 

# Copyright (C) 2017-09-18 Kay Gürtzig 
# License: GPLv3-link 
# GNU General Public License (V 3) 
# https://www.gnu.org/licenses/gpl.html 
# http://www.gnu.de/documents/gpl.de.html 

# Detects whether the given year is a leap year in the Gregorian calendar 
# (extrapolated backwards beyonds its inauguration) 
function isLeapYear() {
    local year=$1

    # TODO: Check and revise the syntax of all expressions! 

    # Most years aren't leap years... 
    isLeapYear <- false

    if (year mod 4 = 0) and (year mod 100 <> 0)
    then
        # This is a standard leap year 
        isLeapYear <- true
    elif year mod 400 = 0
    then
        # One of the rare leap years 
        # occurring every 400 years 
        isLeapYear <- true
    fi

}

# Computes the number of days the given month (1..12) 
# has in the the given year 
function daysInMonth423() {
    declare -n aDate=$1

    # TODO: Check and revise the syntax of all expressions! 

    # select the case where illegal values are also considered 
    case aDate.month in

        1|3|5|7|8|10|12)
            days <- 31
        ;;

        4|6|9|11)
            days <- 30
        ;;

        2)
            # Default value for February 
            days <- 28
            # To make the call work it has to be done in 
            # a separate element (cannot be performed 
            # as part of the condition of an Alternative) 
            isLeap <- isLeapYear(aDate.year)

            if isLeap
            then
                days <- 29
            fi

        ;;

        *)
            # This is the return value for illegal months. 
            # It is easy to check 
            days <- 0
        ;;
    esac

    return  days
}
# = = = = 8< = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

# TODO: Check and revise the syntax of all expressions! 

Date someDay <- Date{day: 24, month: 2, year: 2017}
nDays <- daysInMonth423(someDay)
today <- Date{2018, 7, 20}
type Person = record { name: string; birth: Date; test: array[3] of int;}
var me: Person <- Person{"roger", Date{1985, 3, 6}, {0, 8, 15}}
var declArray: array of double <- {9.0, 7.5, -6.4, 1.7, 0.0}
var explArray: double[3] <- {7.1, 0.5, -1.5}
double doof[3] <- {0.4}
double[2] dull <- {-12.7, 96.03}
values <- {47, 11}
