hexat/script.js

230 lines
5.4 KiB
JavaScript
Raw Normal View History

2025-01-05 02:43:36 +00:00
// Generated by Haxe 4.3.6
(function ($global) { "use strict";
var $estr = function() { return js_Boot.__string_rec(this,''); },$hxEnums = $hxEnums || {},$_;
var Token = $hxEnums["Token"] = { __ename__:true,__constructs__:null
,Operation: ($_=function(op) { return {_hx_index:0,op:op,__enum__:"Token",toString:$estr}; },$_._hx_name="Operation",$_.__params__ = ["op"],$_)
,Number: ($_=function(num) { return {_hx_index:1,num:num,__enum__:"Token",toString:$estr}; },$_._hx_name="Number",$_.__params__ = ["num"],$_)
};
Token.__constructs__ = [Token.Operation,Token.Number];
2025-01-05 02:45:56 +00:00
var Hexat = function() { };
Hexat.__name__ = true;
Hexat.main = function() {
2025-01-05 02:43:36 +00:00
var button = window.document.querySelector(".runButton");
button.onclick = function(event) {
2025-01-05 02:45:56 +00:00
Hexat.runButton();
2025-01-05 02:43:36 +00:00
};
};
2025-01-05 02:45:56 +00:00
Hexat.runButton = function() {
2025-01-05 02:43:36 +00:00
var inputArea = window.document.querySelector(".source");
2025-01-05 02:45:56 +00:00
var res = Hexat.run(Hexat.parse(inputArea.value));
2025-01-05 02:43:36 +00:00
var outputDisplay = window.document.querySelector(".output");
outputDisplay.innerHTML = "Output: <pre>" + res.join(", ") + "</pre>";
};
2025-01-05 02:45:56 +00:00
Hexat.parse = function(input) {
2025-01-05 02:43:36 +00:00
var array = [];
var i = 0;
var splits = input.split(" ");
while(i < splits.length) {
var split = splits[i];
if(split != " " && split != "\n" && split != "\r") {
if(Std.parseInt(split) != null) {
var num = Std.parseInt(split);
array.push(Token.Number(num));
} else if(["+","-","*","/","@"].indexOf(split) != -1) {
array.push(Token.Operation(split));
}
}
++i;
}
return array;
};
2025-01-05 02:45:56 +00:00
Hexat.run = function(array) {
2025-01-05 02:43:36 +00:00
var stack = [];
var i = 0;
while(i < array.length) {
var e = array[i];
if($hxEnums[e.__enum__].__constructs__[e._hx_index]._hx_name == "Number") {
stack.push(Type.enumParameters(array[i])[0]);
} else {
var e1 = array[i];
if($hxEnums[e1.__enum__].__constructs__[e1._hx_index]._hx_name == "Operation") {
var op = Type.enumParameters(array[i])[0];
switch(op) {
case "*":
var right = stack.pop();
var left = stack.pop();
var res = left * right;
stack.push(res);
break;
case "+":
var right1 = stack.pop();
var left1 = stack.pop();
var res1 = left1 + right1;
stack.push(res1);
break;
case "-":
var right2 = stack.pop();
var left2 = stack.pop();
var res2 = left2 - right2;
stack.push(res2);
break;
case "/":
var right3 = stack.pop();
var left3 = stack.pop();
var res3 = left3 / right3;
stack.push(Math.round(res3));
break;
case "@":
var right4 = stack.pop();
var left4 = stack.pop();
stack.push(right4);
stack.push(left4);
break;
}
}
}
++i;
}
return stack;
};
2025-01-05 02:45:56 +00:00
Math.__name__ = true;
2025-01-05 02:43:36 +00:00
var Std = function() { };
Std.__name__ = true;
Std.parseInt = function(x) {
var v = parseInt(x);
if(isNaN(v)) {
return null;
}
return v;
};
var Type = function() { };
Type.__name__ = true;
Type.enumParameters = function(e) {
var enm = $hxEnums[e.__enum__];
var params = enm.__constructs__[e._hx_index].__params__;
if(params != null) {
var _g = [];
var _g1 = 0;
while(_g1 < params.length) {
var p = params[_g1];
++_g1;
_g.push(e[p]);
}
return _g;
} else {
return [];
}
};
var haxe_iterators_ArrayIterator = function(array) {
this.current = 0;
this.array = array;
};
haxe_iterators_ArrayIterator.__name__ = true;
haxe_iterators_ArrayIterator.prototype = {
hasNext: function() {
return this.current < this.array.length;
}
,next: function() {
return this.array[this.current++];
}
};
var js_Boot = function() { };
js_Boot.__name__ = true;
js_Boot.__string_rec = function(o,s) {
if(o == null) {
return "null";
}
if(s.length >= 5) {
return "<...>";
}
var t = typeof(o);
if(t == "function" && (o.__name__ || o.__ename__)) {
t = "object";
}
switch(t) {
case "function":
return "<function>";
case "object":
if(o.__enum__) {
var e = $hxEnums[o.__enum__];
var con = e.__constructs__[o._hx_index];
var n = con._hx_name;
if(con.__params__) {
s = s + "\t";
return n + "(" + ((function($this) {
var $r;
var _g = [];
{
var _g1 = 0;
var _g2 = con.__params__;
while(true) {
if(!(_g1 < _g2.length)) {
break;
}
var p = _g2[_g1];
_g1 = _g1 + 1;
_g.push(js_Boot.__string_rec(o[p],s));
}
}
$r = _g;
return $r;
}(this))).join(",") + ")";
} else {
return n;
}
}
if(((o) instanceof Array)) {
var str = "[";
s += "\t";
var _g = 0;
var _g1 = o.length;
while(_g < _g1) {
var i = _g++;
str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s);
}
str += "]";
return str;
}
var tostr;
try {
tostr = o.toString;
} catch( _g ) {
return "???";
}
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
var s2 = o.toString();
if(s2 != "[object Object]") {
return s2;
}
}
var str = "{\n";
s += "\t";
var hasp = o.hasOwnProperty != null;
var k = null;
for( k in o ) {
if(hasp && !o.hasOwnProperty(k)) {
continue;
}
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
continue;
}
if(str.length != 2) {
str += ", \n";
}
str += s + k + " : " + js_Boot.__string_rec(o[k],s);
}
s = s.substring(1);
str += "\n" + s + "}";
return str;
case "string":
return o;
default:
return String(o);
}
};
String.__name__ = true;
Array.__name__ = true;
js_Boot.__toStr = ({ }).toString;
2025-01-05 02:45:56 +00:00
Hexat.main();
2025-01-05 02:43:36 +00:00
})({});