diff --git a/README.md b/README.md index 201bb25..29927de 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ A ULM [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) might look somet ```yaml type: MultiplicationOperation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 4 denominator: 1 - - type: NumericLiteral + - type: RationalNumber numerator: 7 denominator: 1 ``` @@ -38,10 +38,10 @@ type: MultiplicationOperation presentation: style: dot operands: - - type: NumericLiteral + - type: RationalNumber numerator: 4 denominator: 1 - - type: NumericLiteral + - type: RationalNumber numerator: 7 denominator: 1 ``` @@ -75,3 +75,14 @@ It might even be presented graphically: πŸ¦„πŸ¦„πŸ¦„πŸ¦„ πŸ¦„πŸ¦„πŸ¦„πŸ¦„ ``` + +## ULMScript + +``` +// 2 β€’ 1 + β–― +*(2, +(1, ?()), { + presentation: { + multiplicationSymbol: dot + } +}) +``` diff --git a/ulm-spec/ARITHMETIC.md b/ulm-spec/ARITHMETIC.md index 46c00b2..6c84d31 100644 --- a/ulm-spec/ARITHMETIC.md +++ b/ulm-spec/ARITHMETIC.md @@ -2,13 +2,11 @@ ## [NumericExpression](./NumericExpression/README.md) -## [NumericLiteral](./NumericLiteral/README.md) - ## [NumericOperation](./NumericOperation/README.md) -## [AdditionOperation](./AdditionOperation/README.md) +## [NumericAdditionOperation](./NumericAdditionOperation/README.md) -## [MultiplicationOperation](./MultiplicationOperation/README.md) +## [NumericMultiplicationOperation](./NumericMultiplicationOperation/README.md) ## [NumericRelation](./NumericRelation/README.md) diff --git a/ulm-spec/Expression/README.md b/ulm-spec/Expression/README.md index 8b3a9e6..d846654 100644 --- a/ulm-spec/Expression/README.md +++ b/ulm-spec/Expression/README.md @@ -4,6 +4,8 @@ The most generic type that represents any other type. ## Definition +TypeScript: + ```ts type Expression = NumericExpression | NumericRelation; ``` diff --git a/ulm-spec/IntegerNumber/README.md b/ulm-spec/IntegerNumber/README.md new file mode 100644 index 0000000..9612f38 --- /dev/null +++ b/ulm-spec/IntegerNumber/README.md @@ -0,0 +1,21 @@ +# IntegerNumber + +IntegerNumber :: + - Sign? 0 i + - Sign? LeadingDigit Digit* i + +## Definition + +TypeScript: + +```ts +type IntegerNumber = bigint; +``` + +## Examples + +### ULMScript + +``` +1i +``` diff --git a/ulm-spec/LANGUAGE.md b/ulm-spec/LANGUAGE.md new file mode 100644 index 0000000..ce85fbc --- /dev/null +++ b/ulm-spec/LANGUAGE.md @@ -0,0 +1,9 @@ +# Language + +LeadingDigit :: one of 1 2 3 4 5 6 7 8 9 + +TrueDigit :: one of 0 1 2 3 4 5 6 7 8 9 + +Digit :: one of 0 1 2 3 4 5 6 7 8 9 _ + +Sign :: one of - + diff --git a/ulm-spec/NaturalNumber/README.md b/ulm-spec/NaturalNumber/README.md new file mode 100644 index 0000000..c8fb51e --- /dev/null +++ b/ulm-spec/NaturalNumber/README.md @@ -0,0 +1,21 @@ +# NaturalNumber + +NaturalNumber :: LeadingDigit Digit* n + +A positive integer (not including zero). `{ 1, 2, 3, … }` + +## Definition + +TypeScript: + +```ts +type NaturalNumber = bigint; +``` + +## Examples + +### ULMScript + +``` +34n +``` diff --git a/ulm-spec/AdditionOperation/README.md b/ulm-spec/NumericAdditionOperation/README.md similarity index 54% rename from ulm-spec/AdditionOperation/README.md rename to ulm-spec/NumericAdditionOperation/README.md index 06c50ba..88b425f 100644 --- a/ulm-spec/AdditionOperation/README.md +++ b/ulm-spec/NumericAdditionOperation/README.md @@ -1,12 +1,14 @@ -# AdditionOperation +# NumericAdditionOperation A binary operation that adds two numeric values together. ## Definition +TypeScript: + ```ts -interface AdditionOperation { - type: "AdditionOperation"; +interface NumericAdditionOperation { + type: "NumericAdditionOperation"; operands: [NumericExpression, NumericExpression]; presentation?: { layout?: "vertical" | "inline"; // default = "inline" @@ -16,26 +18,38 @@ interface AdditionOperation { ## Examples +### AST + ```yaml # 1 + 2 -type: AdditionOperation +type: NumericAdditionOperation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 1 - - type: NumericLiteral + - type: RationalNumber numerator: 2 ``` ```yaml # 0.1 # + 5.0 -type: AdditionOperation +type: NumericAdditionOperation presentation: layout: vertical operands: - - type: NumericLiteral + - type: RationalNumber numerator: 1 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 5 ``` + +### ULMScript + +``` ++(1, 3) +``` + +``` +NumericAdditionOperation(10, 456) +``` diff --git a/ulm-spec/NumericEqualRelation/README.md b/ulm-spec/NumericEqualRelation/README.md index 01b06b6..02b8899 100644 --- a/ulm-spec/NumericEqualRelation/README.md +++ b/ulm-spec/NumericEqualRelation/README.md @@ -4,6 +4,8 @@ Equal. ## Definition +TypeScript: + ```ts interface NumericEqualRelation = { type: "NumericEqualRelation"; @@ -17,9 +19,9 @@ interface NumericEqualRelation = { # 4 = 4 type: NumericEqualRelation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 4 - - type: NumericLiteral + - type: RationalNumber numerator: 4 ``` @@ -27,15 +29,15 @@ operands: # 0.1 + 0.2 = 0.3 type: NumericEqualRelation operands: - - type: AdditionOperation + - type: NumericAdditionOperation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 1 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 2 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 3 denominator: 10 ``` diff --git a/ulm-spec/NumericExpression/README.md b/ulm-spec/NumericExpression/README.md index 3cfe702..dd89ad6 100644 --- a/ulm-spec/NumericExpression/README.md +++ b/ulm-spec/NumericExpression/README.md @@ -4,6 +4,8 @@ An expression that, if evaluated, returns a numeric value. ## Definition +TypeScript: + ```ts -type NumericExpression = NumericLiteral | NumericOperation; +type NumericExpression = RationalNumber | NumericOperation; ``` diff --git a/ulm-spec/NumericLiteral/README.md b/ulm-spec/NumericLiteral/README.md deleted file mode 100644 index 7eb2ba6..0000000 --- a/ulm-spec/NumericLiteral/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# NumericLiteral - -A number. - -TODO: Discreet types for natural, whole, integer, rational etc and unions to represent sets? Are there use cases where it's important? - -TODO: How should negative numbers be handled? - -TODO: Handle truncating or rounding in presentation? - -## Definition - -```ts -interface NumericLiteral { - type: "NumericLiteral"; - numerator: wholeNumber; - denominator?: naturalNumber; // default = 1 - presentation?: { - style?: "number" | "fraction"; // default = "number" - base?: naturalNumber; // default = 10 - precision?: wholeNumber | null; // default = null - }; -} -``` - -## Examples - -```yaml -# 10 -type: NumericLiteral -numerator: 10 -``` - -```yaml -# 0.5 -type: NumericLiteral -numerator: 1 -denominator: 2 -``` - -```yaml -# 0xff -type: NumericLiteral -numerator: 255 -denominator: 1 -presentation: - base: 16 -``` - -```yaml -# 0.33 -type: NumericLiteral -numerator: 1 -denominator: 3 -presentation: - precision: 2 -``` - -```yaml -# ΒΌ -type: NumericLiteral -numerator: 1 -denominator: 4 -presentation: - style: fraction -``` diff --git a/ulm-spec/MultiplicationOperation/README.md b/ulm-spec/NumericMultiplicationOperation/README.md similarity index 60% rename from ulm-spec/MultiplicationOperation/README.md rename to ulm-spec/NumericMultiplicationOperation/README.md index 2afd203..85f4312 100644 --- a/ulm-spec/MultiplicationOperation/README.md +++ b/ulm-spec/NumericMultiplicationOperation/README.md @@ -1,12 +1,14 @@ -# MultiplicationOperation +# NumericMultiplicationOperation A binary operation that multiplies two numeric values together. ## Definition +TypeScript: + ```ts -interface MultiplicationOperation { - type: "MultiplicationOperation"; +interface NumericMultiplicationOperation { + type: "NumericMultiplicationOperation"; operands: [NumericExpression, NumericExpression]; presentation?: { style?: "dot" | "times"; // default = "times" @@ -19,36 +21,36 @@ interface MultiplicationOperation { ```yaml # 4 Γ— 7 -type: MultiplicationOperation +type: NumericMultiplicationOperation presentation: style: dot operands: - - type: NumericLiteral + - type: RationalNumber numerator: 4 - - type: NumericLiteral + - type: RationalNumber numerator: 7 ``` ```yaml # 4 Γ— 7 -type: MultiplicationOperation +type: NumericMultiplicationOperation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 9999 denominator: 100 - - type: NumericLiteral + - type: RationalNumber numerator: 7 ``` ```yaml # 0.1 β€’ 5 -type: MultiplicationOperation +type: NumericMultiplicationOperation presentation: style: dot operands: - - type: NumericLiteral + - type: RationalNumber numerator: 1 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 5 ``` diff --git a/ulm-spec/NumericNotEqualRelation/README.md b/ulm-spec/NumericNotEqualRelation/README.md index c289c1f..57ec916 100644 --- a/ulm-spec/NumericNotEqualRelation/README.md +++ b/ulm-spec/NumericNotEqualRelation/README.md @@ -4,6 +4,8 @@ Not equal. ## Definition +TypeScript: + ```ts interface NumericNotEqualRelation { type: "NumericNotEqualRelation"; @@ -17,9 +19,9 @@ interface NumericNotEqualRelation { # 4 β‰  25 type: NumericNotEqualRelation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 4 - - type: NumericLiteral + - type: RationalNumber numerator: 25 ``` @@ -29,15 +31,15 @@ type: NumericNotEqualRelation presentation: style: angleBrackets operands: - - type: AdditionOperation + - type: NumericAdditionOperation operands: - - type: NumericLiteral + - type: RationalNumber numerator: 1 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 2 denominator: 10 - - type: NumericLiteral + - type: RationalNumber numerator: 30_000_000_000_000_004 denominator: 100_000_000_000_000_000 ``` diff --git a/ulm-spec/NumericOperation/README.md b/ulm-spec/NumericOperation/README.md index 7922cfa..e98bb0f 100644 --- a/ulm-spec/NumericOperation/README.md +++ b/ulm-spec/NumericOperation/README.md @@ -4,6 +4,8 @@ An operation that, if evaluated, returns in a numeric value. ## Definition +TypeScript: + ```ts -type NumericOperation = AdditionOperation | MultiplicationOperation; +type NumericOperation = NumericAdditionOperation | NumericMultiplicationOperation; ``` diff --git a/ulm-spec/NumericRelation/README.md b/ulm-spec/NumericRelation/README.md index 4fcb34d..8048266 100644 --- a/ulm-spec/NumericRelation/README.md +++ b/ulm-spec/NumericRelation/README.md @@ -4,6 +4,8 @@ Describes a relationship between numeric values. ## Definition +TypeScript: + ```ts type NumericRelation = NumericEqualRelation | NumericNotEqualRelation; ``` diff --git a/ulm-spec/PRIMITIVES.md b/ulm-spec/PRIMITIVES.md index 2130324..f10a405 100644 --- a/ulm-spec/PRIMITIVES.md +++ b/ulm-spec/PRIMITIVES.md @@ -1,7 +1,11 @@ # Primitives -## [naturalNumber](./naturalNumber/README.md) +## [NaturalNumber](./NaturalNumber/README.md) -## [wholeNumber](./wholeNumber/README.md) +## [WholeNumber](./WholeNumber/README.md) -## [integer](./integer/README.md) +## [IntegerNumber](./IntegerNumber/README.md) + +## [RationalNumber](./RationalNumber/README.md) + +## [Expression](./Expression/README.md) diff --git a/ulm-spec/README.md b/ulm-spec/README.md index cb34df4..07de60a 100644 --- a/ulm-spec/README.md +++ b/ulm-spec/README.md @@ -5,10 +5,10 @@ Universal Language for Mathematics (ULM) # Overview -ULM is a language for describing mathematical expressions. +ULM is a language for describing both the semantics and presentation of mathematical expressions. -# [Primitives](./PRIMITIVES.md) +# [Language](./LANGUAGE.md) -# [Universal](./UNIVERSAL.md) +# [Primitives](./PRIMITIVES.md) # [Arithmetic](./ARITHMETIC.md) diff --git a/ulm-spec/RationalNumber/README.md b/ulm-spec/RationalNumber/README.md new file mode 100644 index 0000000..970e36a --- /dev/null +++ b/ulm-spec/RationalNumber/README.md @@ -0,0 +1,9 @@ +# RationalNumber + +RationalNumber :: + - Sign? 0 + - Sign? LeadingDigit Digit* + - Sign? 0 . TrueDigit Digit* + - Sign? LeadingDigit Digit* . TrueDigit Digit* + - Sign? 0 `/` LeadingDigit Digit* + - Sign? LeadingDigit Digit* `/` LeadingDigit Digit* diff --git a/ulm-spec/UNIVERSAL.md b/ulm-spec/UNIVERSAL.md deleted file mode 100644 index 921bf9b..0000000 --- a/ulm-spec/UNIVERSAL.md +++ /dev/null @@ -1,3 +0,0 @@ -# Universal - -## [Expression](./Expression/README.md) diff --git a/ulm-spec/WholeNumber/README.md b/ulm-spec/WholeNumber/README.md new file mode 100644 index 0000000..876a202 --- /dev/null +++ b/ulm-spec/WholeNumber/README.md @@ -0,0 +1,23 @@ +# WholeNumber + +WholeNumber :: + - 0 w + - LeadingDigit Digit* w + +A positive integer or zero. `{ 0, 1, 2, … }` + +## Definition + +TypeScript: + +```ts +type WholeNumber = bigint; +``` + +## Examples + +### ULMScript + +``` +1w +``` diff --git a/ulm-spec/integer/README.md b/ulm-spec/integer/README.md deleted file mode 100644 index c5d7819..0000000 --- a/ulm-spec/integer/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# integer - -A positive or negative whole number (including zero). - -```ts -type integer = number; -``` diff --git a/ulm-spec/naturalNumber/README.md b/ulm-spec/naturalNumber/README.md deleted file mode 100644 index 51a1a22..0000000 --- a/ulm-spec/naturalNumber/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# naturalNumber - -A positive integer (not including zero). - -```ts -type naturalNumber = number; -``` diff --git a/ulm-spec/wholeNumber/README.md b/ulm-spec/wholeNumber/README.md deleted file mode 100644 index c3a5215..0000000 --- a/ulm-spec/wholeNumber/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# wholeNumber - -A positive integer or zero. - -```ts -type wholeNumber = number; -```