Compare commits
No commits in common. "2cceae4ba02e036229f0d5e327456d10b9b513da" and "9f20049747e9e619eddb594128ec035aa33095ea" have entirely different histories.
2cceae4ba0
...
9f20049747
|
|
@ -1,46 +0,0 @@
|
|||
<expression> ::= <my_identifier>
|
||||
| <literal>
|
||||
| <object_method_call>
|
||||
| "(" <expression> ")"
|
||||
| <lambda_expression>
|
||||
|
||||
<boolean_expression> ::= <boolean_literal>
|
||||
| "(" <boolean_expression> ")"
|
||||
| <my_identifier>.eq(<expression>)
|
||||
| <my_identifier>.is(<expression>)
|
||||
| <my_identifier>.not(<expression>)
|
||||
| <my_identifier>.gt(<expression>)
|
||||
| <my_identifier>.lt(<expression>)
|
||||
| <my_identifier>.gte(<expression>)
|
||||
| <my_identifier>.lte(<expression>)
|
||||
| Boolean.or(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.and(<boolean_expression>, <boolean_expression>)
|
||||
|
||||
|
||||
<object_method_call> ::= <my_identifier> "." <method_name> "(" <argument_list>? ")"
|
||||
| <my_identifier> ".sum()"
|
||||
|
||||
Note: "set" is available on all base objects.
|
||||
Methods listed after it are grouped by type:
|
||||
group 1 are String methods,
|
||||
group 2 are Integer/Decimal methods,
|
||||
group 3 are Array methods,
|
||||
group 4 are Integer Array methods
|
||||
<method_name> ::= "set"
|
||||
| "length" | "reverse" | "split" | "format" | "search" | "concat" | "replace"
|
||||
| "add" | "subtract" | "multiply" | "divide" | "mod" | "round"
|
||||
| "remove" | "first" | "last" | "find" | "glue" | "contains" | "add" | "each"
|
||||
| "sum"
|
||||
| <identifier>
|
||||
|
||||
<lambda_expression> ::= "fn" "(" <parameter_list>? ")" "->" "[" <type> "]" "{" <statement>* "}"
|
||||
|
||||
<literal> ::= <number_literal> | <string_literal> | <boolean_literal>
|
||||
|
||||
<number_literal> ::= <digit>+
|
||||
|
||||
<string_literal> ::= '"' [^"]* '"'
|
||||
|
||||
<boolean_literal> ::= "True" | "False"
|
||||
|
||||
<my_identifier> ::= "my." <identifier>
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<constructor_declaration> ::= <accessibility_modifier>"fn" "on_create" "(" <parameter_list>? ")" "->" "[Null]" "{" <statement>* "}"
|
||||
|
||||
<destructor_declaration> ::= <accessibility_modifier>"fn" "on_destroy" "(" <parameter_list>? ")" "->" "[Null]" "{" <statement>* "}"
|
||||
|
||||
<interface_declaration> ::= "@"<interface_identifier> "{" <interface_body> "}"
|
||||
|
||||
<interface_body> ::= <interface_method_declaration>*
|
||||
|
||||
<interface_method_declaration> ::= <accessibility_modifier>"fn" <identifier> <function_signature> ";"
|
||||
|
||||
<function_declaration> ::= <accessibility_modifier>"fn" <identifier> <function_signature> "{" <statement>* "}"
|
||||
|
||||
<function_signature> ::= "(" <parameter_list>? ")" "->" <return_type_list>
|
||||
|
||||
<accessibility_modifier> ::= "-" | "" | "+"
|
||||
|
||||
<return_type_list> ::= "[" <type> ("," <type>)* "]" | "Runnable"
|
||||
|
||||
<parameter_list> ::= <required_parameter> ("," <required_parameter>)* [("," <default_parameter>)*]
|
||||
|
||||
<required_parameter> ::= <identifier> ":" <parameter_type>
|
||||
|
||||
<default_parameter> ::= <identifier> ":" <parameter_type> "=" <expression>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<identifier> ::= <upper_letter> (<letter> | <digit>)*
|
||||
|
||||
<interface_identifier_list> ::= <interface_identifier> ("," <interface_identifier>)*
|
||||
|
||||
<interface_identifier> ::= <identifier>
|
||||
|
||||
<letter> ::= <upper_letter> | <lower_letter>
|
||||
|
||||
<upper_letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
|
||||
|
||||
<lower_letter> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
|
||||
|
||||
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<program> ::= <use_statement>* <declaration>*
|
||||
|
||||
<use_statement> ::= "use" <identifier> ("." <identifier>)* ";"
|
||||
|
||||
<declaration> ::= <type_declaration> | <interface_declaration>
|
||||
|
||||
import "types.bnf"
|
||||
import "statements.bnf"
|
||||
import "functions.bnf"
|
||||
import "expressions.bnf"
|
||||
import "identifiers.bnf"
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<statement> ::= <assignment_statement>
|
||||
| <if_statement>
|
||||
| <while_statement>
|
||||
| <function_call_statement>
|
||||
| <return_statement>
|
||||
| <using_statement>
|
||||
|
||||
<assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";"
|
||||
|
||||
<if_statement> ::= "if" "(" <boolean_expression> ")" "{" <statement>* "}" ["else" "{" <statement>* "}"]?
|
||||
|
||||
<while_statement> ::= "while" "(" <expression> ")" "{" <statement>* "}"
|
||||
|
||||
<function_call_statement> ::= <my_identifier> "(" <argument_list>? ")" ";"
|
||||
|
||||
<argument_list> ::= <expression> ("," <expression>)*
|
||||
|
||||
<return_statement> ::= "rtn" <expression> ";"
|
||||
|
||||
<using_statement> ::= "using" <type> <identifier> ".set(" <expression> ")" "{" <statement>* "}"
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<type_declaration> ::= <identifier> ["/" <identifier>] ["->" <interface_identifier_list>] "{" <class_body> "}"
|
||||
|
||||
<class_body> ::= (<variable_declaration> | <function_declaration> | <constructor_declaration> | <destructor_declaration>)*
|
||||
|
||||
<type> ::= "String" | "Integer" | "Decimal" | "Boolean" | <identifier> | <array_type>
|
||||
|
||||
<parameter_type> ::= <type> | "Runnable"
|
||||
|
||||
<variable_declaration> ::= <type> <identifier> [".set(" <expression> ")"] ";"
|
||||
|
||||
<function_declaration> ::= <accessibility_modifier> "fn" <identifier> <function_signature> "{" <statement>* "}"
|
||||
|
||||
<function_signature> ::= "(" <parameter_list>? ")" "->" <return_type_list>
|
||||
|
||||
<accessibility_modifier> ::= "-" | "" | "+"
|
||||
|
||||
<return_type_list> ::= "[" <type> ("," <type>)*] | "Runnable"
|
||||
|
||||
<parameter_list> ::= <required_parameter> ("," <required_parameter>)* [("," <default_parameter>)*]
|
||||
|
||||
<required_parameter> ::= <identifier> ":" <parameter_type>
|
||||
|
||||
<default_parameter> ::= <identifier> ":" <parameter_type> "=" <expression>
|
||||
|
||||
<array_type> ::= <type> "<>"
|
||||
|
||||
<constructor_declaration> ::= "fn" "on_create" "(" <parameter_list>? ")" "->" "[Null]" "{" <statement>* "}"
|
||||
|
||||
<destructor_declaration> ::= "fn" "on_destroy" "(" <parameter_list>? ")" "->" "[Null]" "{" <statement>* "}"
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
use Vehicle.Car;
|
||||
use Vehicle.Engine;
|
||||
|
||||
Car/Equinox -> hasEngine {
|
||||
String model;
|
||||
Integer year;
|
||||
Decimal fuelEfficiency;
|
||||
Boolean isRunning;
|
||||
Decimal fuelLevel;
|
||||
Decimal mileage;
|
||||
|
||||
fn on_create(String model, Integer year) -> [Null] {
|
||||
my.model.set(model);
|
||||
my.year.set(year);
|
||||
my.fuelEfficiency.set(28.5);
|
||||
my.isRunning.set(False);
|
||||
my.fuelLevel.set(100.0);
|
||||
my.mileage.set(0.0);
|
||||
rtn Null;
|
||||
}
|
||||
|
||||
fn startEngine() -> [Boolean] {
|
||||
Boolean engineStatus.set(Boolean.and(my.isRunning.not(True), my.fuelLevel.gt(0.0)));
|
||||
my.isRunning.set(engineStatus);
|
||||
rtn engineStatus;
|
||||
}
|
||||
|
||||
fn calculateFuelConsumption(Decimal distance) -> [Decimal] {
|
||||
Decimal consumption.set(distance.divide(my.fuelEfficiency));
|
||||
rtn consumption;
|
||||
}
|
||||
|
||||
fn checkMaintenance() -> [Boolean] {
|
||||
Boolean needsMaintenance.set(my.mileage.gte(50000.0));
|
||||
rtn needsMaintenance;
|
||||
}
|
||||
|
||||
+fn drive(Decimal miles) -> [Null] {
|
||||
my.mileage.add(miles);
|
||||
my.fuelLevel.subtract(my.calculateFuelConsumption(miles));
|
||||
rtn Null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
use Inventory.Base.InventoryInterface;
|
||||
use Inventory.Base.PartsInventory;
|
||||
|
||||
Inventory/PartsInventory -> InventoryInterface {
|
||||
String<> partNames.set(<>);
|
||||
Integer<> partQuantities.set(<>);
|
||||
Decimal<> partPrices.set(<>);
|
||||
|
||||
+fn on_create() -> [Null] {
|
||||
// inventory initialized
|
||||
}
|
||||
|
||||
+fn on_destroy() -> [Null] {
|
||||
my.partNames.set(<>);
|
||||
my.partQuantities.set(<>);
|
||||
my.partPrices.set(<>);
|
||||
}
|
||||
|
||||
-fn findPartIndex(partName:String) -> [Integer] {
|
||||
Integer idx.set(-1);
|
||||
my.partNames.each(name, i -> {
|
||||
if (name.eq(partName)) {
|
||||
idx.set(i);
|
||||
}
|
||||
});
|
||||
rtn idx;
|
||||
}
|
||||
|
||||
+fn addPart(partName:String, quantity:Integer, price:Decimal) -> [Boolean] {
|
||||
Integer i.set(my.findPartIndex(partName));
|
||||
if (i.gte(0)) {
|
||||
Integer current.set(my.partQuantities.get(i));
|
||||
my.partQuantities.remove(i);
|
||||
my.partQuantities.add(current.add(quantity));
|
||||
my.partPrices.remove(i);
|
||||
my.partPrices.add(price);
|
||||
rtn True;
|
||||
} else {
|
||||
my.partNames.add(partName);
|
||||
my.partQuantities.add(quantity);
|
||||
my.partPrices.add(price);
|
||||
rtn True;
|
||||
}
|
||||
}
|
||||
|
||||
+fn removePart(partName:String, quantity:Integer) -> [Boolean] {
|
||||
Integer i.set(my.findPartIndex(partName));
|
||||
if (i.lt(0)) { rtn False; }
|
||||
|
||||
Integer current.set(my.partQuantities.get(i));
|
||||
if (current.lt(quantity)) { rtn False; }
|
||||
|
||||
if (current.eq(quantity)) {
|
||||
my.partNames.remove(i);
|
||||
my.partQuantities.remove(i);
|
||||
my.partPrices.remove(i);
|
||||
} else {
|
||||
my.partQuantities.remove(i);
|
||||
my.partQuantities.add(current.subtract(quantity));
|
||||
}
|
||||
rtn True;
|
||||
}
|
||||
|
||||
+fn getPartPrice(partName:String) -> [Decimal] {
|
||||
Integer i.set(my.findPartIndex(partName));
|
||||
if (i.lt(0)) { rtn 0; }
|
||||
rtn my.partPrices.get(i);
|
||||
}
|
||||
|
||||
+fn getTotalInventoryValue() -> [Decimal] {
|
||||
Decimal total.set(0);
|
||||
my.partNames.each(name, i -> {
|
||||
Decimal value.set(my.partQuantities.get(i).multiply(my.partPrices.get(i)));
|
||||
total.set(total.add(value));
|
||||
});
|
||||
rtn total;
|
||||
}
|
||||
|
||||
+fn getPartDetails(partName:String) -> [String] {
|
||||
Integer i.set(my.findPartIndex(partName));
|
||||
if (i.lt(0)) { rtn ["Part not found"]; }
|
||||
String details.set(
|
||||
partName
|
||||
.concat(" — Qty: ")
|
||||
.concat(my.partQuantities.get(i).format())
|
||||
.concat(", Price: $")
|
||||
.concat(my.partPrices.get(i).format())
|
||||
);
|
||||
rtn [details];
|
||||
}
|
||||
|
||||
-fn ensureNonNegative(quantity:Integer) -> [Boolean] {
|
||||
if (quantity.lt(0)) { rtn False; }
|
||||
rtn True;
|
||||
}
|
||||
|
||||
fn audit_sample() {
|
||||
// protected (no prefix) example: internal audit routine callable within package
|
||||
String report.set("Inventory count: ".concat(my.partNames.length().format()));
|
||||
rtn report;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue