Files
compiler-the-translators/tests/carl/NoErrors/functionValue.alpha.asc
Scarlett c091927fe7 carl
2025-04-15 14:46:00 -04:00

76 lines
1.6 KiB
Plaintext

alpha parser, version 0.2 (2023-03-04) - Annotated Source Code for file functionValue.alpha
001: (* Type definitions *)
002:
003: (* mapping type *)
004: type string2int: string -> integer
005:
006: (* array of functions *)
007: type funArray: 1 -> string2int
008:
009: (* record of functions *)
010: type funRec: [ string2int: f; string2int: g ]
011:
012: (* function returning function *)
013: type integer_2_string2int: integer -> string2int
014:
015: (* function returning function *)
016: type string2int_2_integer: string2int -> integer
017:
018:
019: type iXiXc: [integer: a; integer: b; character: c]
020:
021: type iic2b: iXiXc -> Boolean
022:
023: (* Function declarations using the above type definitions *)
024: function a: string2int
025: function b: integer_2_string2int
026: function c: string2int_2_integer
027:
028: function d: iic2b
029:
030: d(x,y,z) := {
031: return (x < y & z < 'm');
032: }
033:
034: function entry: string2int
035:
036: a(x) := {
037: [string : s]
038: s := x;
039: return 0;
040: }
041:
042: b(x) := {
043: [integer: i]
044: i := x;
045: return a;
046: }
047:
048: c(x) := {
049: [string: s]
050: s := "Hi!";
051: return x(s);
052: }
053:
054:
055: (* Function definition
056: entry is the first function called
057: *)
058: entry(arg) := {
059: [integer: result; string2int: f; integer: temp]
060: temp := a("Hello");
061: f := b(temp);
062: result := c(f);
063: if (d(1,2,'c'))
064: then {
065: result := 0;
066: }
067: else {
068: [ Boolean : b]
069: result := entry("hello");
070: }
071: result := c(f);
072: return result;
073: }
074: