From 4dd046bbb61aa354c171eb4dc23133609efd2c7a Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Sun, 5 Jan 2025 02:43:36 +0000 Subject: [PATCH] add shtuff?! --- Parser.hx | 96 ++++++++++++++++++++++ index.html | 15 ++-- script.js | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 19 +++++ 4 files changed, 349 insertions(+), 10 deletions(-) create mode 100644 Parser.hx create mode 100644 script.js diff --git a/Parser.hx b/Parser.hx new file mode 100644 index 0000000..bf9881b --- /dev/null +++ b/Parser.hx @@ -0,0 +1,96 @@ +import js.Browser.document; +import js.html.TextAreaElement; + +enum Token { + Operation(op:String); + Number(num:Int); +} + +class Parser { + static public function main() { + var button = document.querySelector(".runButton"); + button.onclick = (event) -> runButton(); + } + + static public function runButton() { + var inputArea:TextAreaElement = cast document.querySelector(".source"); + + var res = run(parse(inputArea.value)); + var outputDisplay = document.querySelector(".output"); + + outputDisplay.innerHTML = "Output:
"+res.join(", ")+"
"; + } + + static function parse(input:String) { + var array: 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(Number(num)); + } else if (["+", "-", "*", "/", "@"].contains(split)) { + array.push(Operation(split)); + } + } + i++; + } + + return array; + } + + static function run(array:Array) { + var stack: Array = []; + var i = 0; + + while (i < array.length) { + if(array[i].getName() == "Number") { + stack.push(array[i].getParameters()[0]); + } else if (array[i].getName() == "Operation") { + + var op = array[i].getParameters()[0]; + + switch (op) { + + case "+": + var right = stack.pop(); + var left = stack.pop(); + var res = left + right; + stack.push(res); + + case "-": + var right = stack.pop(); + var left = stack.pop(); + var res = left - right; + stack.push(res); + + case "*": + var right = stack.pop(); + var left = stack.pop(); + var res = left * right; + stack.push(res); + + case "/": + var right = stack.pop(); + var left = stack.pop(); + var res = left / right; + stack.push(Math.round(res)); + + case "@": + var right = stack.pop(); + var left = stack.pop(); + stack.push(right); + stack.push(left); + } + } + + i++; + } + + return stack; + } +} diff --git a/index.html b/index.html index 8e43d73..6631655 100644 --- a/index.html +++ b/index.html @@ -7,15 +7,10 @@ -

Hello, world!

-

Lorem ipsum odor amet, consectetuer adipiscing elit. Aptent efficitur dapibus lectus ultricies ullamcorper parturient. Sagittis dis ut aptent dapibus facilisi ut eu malesuada. Auctor risus mollis rhoncus curabitur porta. Magna leo dictum cubilia blandit; efficitur ultrices sapien. Sollicitudin arcu volutpat elementum quisque turpis adipiscing pharetra conubia taciti. Sapien laoreet id nec himenaeos sed.

- -

Pharetra vestibulum tellus donec vestibulum congue volutpat vitae lectus. Odio accumsan egestas a eu phasellus proin duis nec phasellus. Afeugiat suscipit tristique tortor feugiat vivamus quisque vel praesent. Enim sem quam posuere dictum ad dolor. Maximus parturient metus ornare venenatis mollis quam. Quisque ornare pellentesque suspendisse sapien vel gravida proin lacinia. Torquent hac luctus ac mollis ut consequat bibendum parturient.

- -

Proin vehicula turpis efficitur purus sapien tincidunt sagittis. Maecenas sodales tempus nam hac urna massa urna euismod. Turpis urna eu conubia tincidunt donec ridiculus tortor nibh. At donec eros duis tellus dis elit odio. Consequat at hac felis turpis urna. Ac pulvinar curabitur erat blandit finibus platea. Tempor lacus a sociosqu, sociosqu viverra vitae mauris! Urna vestibulum maecenas iaculis rutrum phasellus; elementum mus. Cras pellentesque sociosqu erat lectus torquent dis libero; orci amet.

- -

Interdum conubia dictum luctus eleifend torquent aenean. Imperdiet erat velit phasellus finibus est elementum? Amet praesent rhoncus imperdiet efficitur consectetur cras lacus nullam. Metus consequat condimentum ornare tortor volutpat; amet dignissim quam. Risus sed habitant dictum donec a duis. Sed accumsan auctor, nam sit cras lacinia suspendisse erat urna. Odio sollicitudin aliquet mollis mattis neque rhoncus. Netus nisl dignissim mattis varius nisi commodo.

- -

Parturient ut malesuada ultricies finibus tincidunt lacinia. Himenaeos ad tristique lectus vivamus sed suscipit lacinia finibus. Lacinia efficitur ligula et; ex semper feugiat sed nibh. Ipsum montes pretium velit potenti suspendisse sagittis ultricies nulla inceptos. Leo cursus ultrices mollis inceptos pretium hendrerit lorem. Purus gravida ad interdum, nullam pellentesque egestas. Phasellus nostra fermentum potenti nulla blandit pellentesque ad.

+

hxcalc

+ +

+
Output:
+ diff --git a/script.js b/script.js new file mode 100644 index 0000000..a98cd1b --- /dev/null +++ b/script.js @@ -0,0 +1,229 @@ +// 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(); +})({}); diff --git a/style.css b/style.css index 92cede1..e13381f 100644 --- a/style.css +++ b/style.css @@ -3,3 +3,22 @@ body { color: #efefef; font-family: sans-serif; } + +.source { + background: #444444; + color: #efefef; + min-height: 50vh; + min-width: 50vw; + font-size: 300%; +} + +button { + background: #444444; + color: #efefef; + font-size: 300%; + margin-left: 10px; +} + +pre { + font-size: 300%; +}