mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Build in functions.
This commit is contained in:
@@ -5,6 +5,4 @@ This scripting language tries to simplify Arma mod development and eliminate the
|
|||||||
|
|
||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
```
|
*coming soon*
|
||||||
coming soon
|
|
||||||
```
|
|
||||||
|
|||||||
28
in/complex.asl
Normal file
28
in/complex.asl
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
if isServer {
|
||||||
|
exitWith();
|
||||||
|
}
|
||||||
|
|
||||||
|
func ZeusGrpPlaced(_curators, _group) {
|
||||||
|
each allCurators-_curators {
|
||||||
|
$addCuratorEditableObjects<_x>(_group, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ZeusObjPlaced(_curators, _unit) {
|
||||||
|
each allCurators-_curators {
|
||||||
|
$addCuratorEditableObjects<_x>([_unit], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
each allCurators {
|
||||||
|
$addCuratorEditableObjects<_x>(allUnits, true);
|
||||||
|
$addCuratorEditableObjects<_x>(allMissionObjects("All"), false);
|
||||||
|
|
||||||
|
_curator = _x;
|
||||||
|
|
||||||
|
each allUnits {
|
||||||
|
if vehicle(_x) != _x {
|
||||||
|
$addCuratorEditableObjects<_curator>([vehicle(_x)], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
func somefunc() {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,28 @@
|
|||||||
while true {
|
if isServer {
|
||||||
|
exitWith();
|
||||||
|
}
|
||||||
|
|
||||||
|
func ZeusGrpPlaced(_curators, _group) {
|
||||||
|
each allCurators-_curators {
|
||||||
|
$addCuratorEditableObjects(_x)(_group, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ZeusObjPlaced(_curators, _unit) {
|
||||||
|
each allCurators-_curators {
|
||||||
|
$addCuratorEditableObjects(_x)([_unit], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
each allCurators {
|
||||||
|
$addCuratorEditableObjects(_x)(allUnits, true);
|
||||||
|
$addCuratorEditableObjects(_x)(allMissionObjects("All"), false);
|
||||||
|
|
||||||
|
_curator = _x;
|
||||||
|
|
||||||
|
each allUnits {
|
||||||
|
if vehicle(_x) != _x {
|
||||||
|
$addCuratorEditableObjects(_curator)([vehicle(_x)], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
func foo(_out) {
|
|
||||||
hint(_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
func bar(_out) {
|
|
||||||
hint(reverse(_out));
|
|
||||||
}
|
|
||||||
|
|
||||||
func inlineFunction(_multiple, _parameters, _should, _work) {
|
|
||||||
_a = "Not working yet...";
|
|
||||||
}
|
|
||||||
|
|
||||||
var _array;
|
|
||||||
|
|
||||||
each array {
|
|
||||||
if _x > 200 {
|
|
||||||
foo(_x);
|
|
||||||
} else {
|
|
||||||
bar("nope", _x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var _x = 123;
|
|
||||||
|
|
||||||
for var _i = 0; _i < 10; _i = _i+1; {
|
|
||||||
_x = _x+1;
|
|
||||||
_foo = "Foo";
|
|
||||||
_bar = "Bar";
|
|
||||||
fun(_foo, _bar);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch _x {
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
somefunc(2);
|
|
||||||
default:
|
|
||||||
somefunc(3);
|
|
||||||
_x = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
func myFunc(_x, _y) {
|
|
||||||
if _x < _y {
|
|
||||||
myFunc(_y, _x);
|
|
||||||
hint("Rekursiv");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _a < _b {
|
|
||||||
if _b < _a {
|
|
||||||
myFunc(_a, _b+9-(2/2));
|
|
||||||
myFunc(_a, _b);
|
|
||||||
myFunc(_a, _b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
myFunc(_a, _b);
|
|
||||||
myFunc(_a, _b);
|
|
||||||
26
in/zeus.asl
26
in/zeus.asl
@@ -1,26 +0,0 @@
|
|||||||
if isServer {
|
|
||||||
exitWith();
|
|
||||||
}
|
|
||||||
|
|
||||||
func ZeusGrpPlaced(_group) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func ZeusObjPlaced(_unit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach curator => allCurators {
|
|
||||||
addCuratorEditableObjects(curator, allUnits, true);
|
|
||||||
addCuratorEditableObjects(curator, allMissionObjects("All"), false);
|
|
||||||
|
|
||||||
foreach unit => allUnits {
|
|
||||||
var _vehicle = vehicle(unit);
|
|
||||||
|
|
||||||
if _vehicle != unit {
|
|
||||||
addCuratorEditableObjects(curator, _vehicle, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addEventHandler(curator, "CuratorGroupPlaced", BIS_fnc_MP());
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -31,9 +31,15 @@ func parseBlock() {
|
|||||||
parseForeach()
|
parseForeach()
|
||||||
} else if accept("func") {
|
} else if accept("func") {
|
||||||
parseFunction()
|
parseFunction()
|
||||||
|
} else if accept("return") {
|
||||||
|
parseReturn()
|
||||||
} else {
|
} else {
|
||||||
parseStatement()
|
parseStatement()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !end() && !accept("}") {
|
||||||
|
parseBlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseVar() {
|
func parseVar() {
|
||||||
@@ -192,6 +198,14 @@ func parseFunctionParameter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseReturn() {
|
||||||
|
expect("return")
|
||||||
|
appendOut("return ")
|
||||||
|
parseExpression(true)
|
||||||
|
expect(";")
|
||||||
|
appendOut(";\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Everything that does not start with a keyword.
|
// Everything that does not start with a keyword.
|
||||||
func parseStatement() {
|
func parseStatement() {
|
||||||
// empty block
|
// empty block
|
||||||
@@ -206,13 +220,17 @@ func parseStatement() {
|
|||||||
if accept("=") {
|
if accept("=") {
|
||||||
appendOut(name)
|
appendOut(name)
|
||||||
parseAssignment()
|
parseAssignment()
|
||||||
|
} else if name == "$" {
|
||||||
|
name = get().token
|
||||||
|
next()
|
||||||
|
parseBuildinFunctionCall(name);
|
||||||
} else {
|
} else {
|
||||||
parseFunctionCall()
|
parseFunctionCall()
|
||||||
appendOut(name+";\n")
|
appendOut(name+";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !end() {
|
if !end() {
|
||||||
parseStatement()
|
parseBlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +251,20 @@ func parseFunctionCall() {
|
|||||||
appendOut("] call ")
|
appendOut("] call ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseBuildinFunctionCall(name string) {
|
||||||
|
expect("(")
|
||||||
|
appendOut("[")
|
||||||
|
parseParameter()
|
||||||
|
expect(")")
|
||||||
|
appendOut("] ")
|
||||||
|
expect("(")
|
||||||
|
appendOut(name+" [")
|
||||||
|
parseParameter()
|
||||||
|
expect(")")
|
||||||
|
expect(";")
|
||||||
|
appendOut("];\n")
|
||||||
|
}
|
||||||
|
|
||||||
func parseParameter() {
|
func parseParameter() {
|
||||||
for !accept(")") {
|
for !accept(")") {
|
||||||
parseExpression(true)
|
parseExpression(true)
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ var delimiter = []byte{
|
|||||||
',',
|
',',
|
||||||
':',
|
':',
|
||||||
'&',
|
'&',
|
||||||
'|'}
|
'|',
|
||||||
|
'$'}
|
||||||
|
|
||||||
var keywords = []string{
|
var keywords = []string{
|
||||||
"var",
|
"var",
|
||||||
@@ -34,7 +35,8 @@ var keywords = []string{
|
|||||||
"true",
|
"true",
|
||||||
"false",
|
"false",
|
||||||
"case",
|
"case",
|
||||||
"default"}
|
"default",
|
||||||
|
"return"}
|
||||||
|
|
||||||
var whitespace = []byte{' ', '\n', '\t'}
|
var whitespace = []byte{' ', '\n', '\t'}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
// read test file
|
// read test file
|
||||||
code, _ := ioutil.ReadFile("in/statements.asl")
|
code, _ := ioutil.ReadFile("in/simple.asl")
|
||||||
token := asl.Tokenize(code)
|
token := asl.Tokenize(code)
|
||||||
out := asl.Parse(token)
|
out := asl.Parse(token)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user