Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 45180 / input.js
diff options
context:
space:
mode:
Commit97a58430a248b9ea89a7da0120cfceb0e6b11af5 (patch)
Author
 Dobromir Ivanov <dobromir0ivanov@gmail.com>
2018-11-07 15:06:45 +0200
Committer
 dtrendafilov <trendafilov.dn@gmail.com>
2018-11-07 15:06:45 +0200
Files71bc769a2c4848d0bd40850b6ad94ea9e4fab3d3 /homework/45180/input.js
IPL-97a58430a248b9ea89a7da0120cfceb0e6b11af5.tar
IPL-97a58430a248b9ea89a7da0120cfceb0e6b11af5.tar.gz
IPL-97a58430a248b9ea89a7da0120cfceb0e6b11af5.zip
Parent13f074686970cf037cbd8a4c492033bb7b14562d (diff)
A (naive) golang implementation of a JavaScript lexer. (#18)
Not that comments single line or multi line are not parsed. Numbers are parsed in the most naive way possible so don't expect miracles.
1 files changed, 51 insertions, 0 deletions
-rw-r--r--homework/45180/input.js51
diff --git a/homework/45180/input.js b/homework/45180/input.js
new file mode 100644
index 0000000..6974019
--- /dev/null
+++ b/homework/45180/input.js
@@ -0,0 +1,51 @@
+export default class Queue {
+ constructor() {
+ this._firstNode = null;
+ this._lastNode = null;
+ }
+
+ dequeue() {
+ if (!this._firstNode) {
+ return this._firstNode;
+ }
+
+ const payload = this._firstNode.payload;
+
+ this._firstNode = this._firstNode.next;
+
+ return payload;
+ }
+
+ enqueue(item) {
+ const newNode = {
+ payload: item,
+ next: null
+ };
+
+ if (this._firstNode === null) {
+ this._firstNode = newNode;
+ this._lastNode = newNode;
+
+ } else {
+ this._lastNode.next = newNode;
+ this._lastNode = newNode;
+ }
+ }
+
+ clear() {
+ this._firstNode = null;
+ this._lastNode = null;
+ }
+
+ top() {
+ if (!this._firstNode) {
+ return this._firstNode;
+ }
+
+ return this._firstNode.payload;
+ }
+
+ isEmpty() {
+ return !this._firstNode;
+ }
+}