From b46bfb1eba89c007f956fd56ea857a854c6c4c40 Mon Sep 17 00:00:00 2001 From: Igor Mozharovsky Date: Sat, 3 Dec 2016 19:38:17 +0200 Subject: [PATCH 1/2] Fix infinite loop Fixes infinite loop in case when number or letter appears outside of parentheses. For example: `(add 1 2)5` or `(add 2 3)abs` --- super-tiny-compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/super-tiny-compiler.js b/super-tiny-compiler.js index e4e214d..1757a80 100755 --- a/super-tiny-compiler.js +++ b/super-tiny-compiler.js @@ -423,7 +423,7 @@ function tokenizer(input) { // Then we're going to loop through each character in the sequence until // we encounter a character that is not a number, pushing each character // that is a number to our `value` and incrementing `current` as we go. - while (NUMBERS.test(char)) { + while (char && NUMBERS.test(char)) { value += char; char = input[++current]; } @@ -447,7 +447,7 @@ function tokenizer(input) { // Name token // var LETTERS = /[a-z]/i; - if (LETTERS.test(char)) { + if (char && LETTERS.test(char)) { var value = ''; // Again we're just going to loop through all the letters pushing them to From 69e95c9932a6310453a2b8ce0bda7701de3f8f0e Mon Sep 17 00:00:00 2001 From: Igor Mozharovsky Date: Thu, 8 Dec 2016 23:17:21 +0200 Subject: [PATCH 2/2] Check current length parsing letters or numbers --- super-tiny-compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/super-tiny-compiler.js b/super-tiny-compiler.js index 1757a80..9953c4c 100755 --- a/super-tiny-compiler.js +++ b/super-tiny-compiler.js @@ -423,7 +423,7 @@ function tokenizer(input) { // Then we're going to loop through each character in the sequence until // we encounter a character that is not a number, pushing each character // that is a number to our `value` and incrementing `current` as we go. - while (char && NUMBERS.test(char)) { + while (current < input.length && NUMBERS.test(char)) { value += char; char = input[++current]; } @@ -447,7 +447,7 @@ function tokenizer(input) { // Name token // var LETTERS = /[a-z]/i; - if (char && LETTERS.test(char)) { + if (current < input.length && LETTERS.test(char)) { var value = ''; // Again we're just going to loop through all the letters pushing them to