// Generated by Haxe 4.3.6 (function ($global) { "use strict"; var $estr = function() { return js_Boot.__string_rec(this,''); },$hxEnums = $hxEnums || {},$_; Math.__name__ = true; 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]; var Parser = function() { }; Parser.__name__ = true; Parser.main = function() { var button = window.document.querySelector(".runButton"); button.onclick = function(event) { Parser.runButton(); }; }; Parser.runButton = function() { var inputArea = window.document.querySelector(".source"); var res = Parser.run(Parser.parse(inputArea.value)); var outputDisplay = window.document.querySelector(".output"); outputDisplay.innerHTML = "Output:
" + res.join(", ") + "
"; }; Parser.parse = function(input) { 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; }; Parser.run = function(array) { 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; }; 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 ""; 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; Parser.main(); })({});