nilac 0.0.4.3.4 → 0.0.4.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/libraries/Generated_files.xml +13 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/nila.iml +21 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/watcherTasks.xml +26 -0
- data/.idea/workspace.xml +495 -0
- data/bin/nilac +422 -64
- data/examples/decBin.js +48 -0
- data/examples/decBin.nila +65 -0
- data/lib/nilac/version.rb +1 -1
- data/shark/features/ruby_methods.feature +11 -0
- data/shark/test_files/array_string_indexing.nila +2 -2
- data/shark/test_files/correct_default_parameters.js +1 -1
- data/shark/test_files/correct_initialization.js +1 -7
- data/shark/test_files/correct_multiple_return.js +1 -1
- data/shark/test_files/correct_regular_if.js +0 -1
- data/shark/test_files/correct_regular_while.js +0 -2
- data/shark/test_files/correct_ruby_methods.js +45 -0
- data/shark/test_files/multiple_initialization.nila +0 -2
- data/shark/test_files/regular_if.nila +0 -2
- data/shark/test_files/regular_while.nila +0 -2
- data/shark/test_files/ruby_methods.nila +23 -1
- data/src/nilac.rb +540 -64
- metadata +17 -2
data/examples/decBin.js
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
|
+
(function() {
|
3
|
+
var _i,_j,decimalToBinary;
|
4
|
+
|
5
|
+
//This is Nila's decimal to Binary converter. It's awesome
|
6
|
+
|
7
|
+
decimalToBinary = function(input_num) {
|
8
|
+
var remainder, storage, numsplit, inputnum, decimalplaces, calc, decans;
|
9
|
+
remainder = "";
|
10
|
+
storage = [];
|
11
|
+
if (!((input_num.indexOf(".") === -1))) {
|
12
|
+
numsplit = input_num.split(".");
|
13
|
+
inputnum = Number(numsplit[0]);
|
14
|
+
decimalplaces = parseFloat("0." + numsplit[1]);
|
15
|
+
} else {
|
16
|
+
inputnum = Number(input_num);
|
17
|
+
decimalplaces = [];
|
18
|
+
}
|
19
|
+
while (inputnum >= 1) {
|
20
|
+
console.log("2 | " + (inputnum) + " " + (remainder));
|
21
|
+
remainder = inputnum%2;
|
22
|
+
inputnum = (inputnum-remainder)/2;
|
23
|
+
storage.push(remainder);
|
24
|
+
}
|
25
|
+
storage.reverse();
|
26
|
+
if (decimalplaces.toString().length > 0) {
|
27
|
+
storage.push(".");
|
28
|
+
}
|
29
|
+
calc = null;
|
30
|
+
decans = null;
|
31
|
+
for (_i = 0, _j = decimalplaces.toString().length-2; _i < _j; _i += 1) {
|
32
|
+
calc = decimalplaces * 2;
|
33
|
+
decans = calc.toString()[0];
|
34
|
+
decimalplaces = parseFloat("0." + (calc.toString().slice(2)));
|
35
|
+
storage.push(Number(decans));
|
36
|
+
};
|
37
|
+
return storage;
|
38
|
+
};
|
39
|
+
|
40
|
+
process.stdin.resume();
|
41
|
+
|
42
|
+
process.stdin.setEncoding('utf8');
|
43
|
+
|
44
|
+
process.stdin.on('data',function(chunk) {
|
45
|
+
process.stdout.write("Answer: " + (decimalToBinary(chunk).join("")) + " \n\n");
|
46
|
+
});
|
47
|
+
|
48
|
+
}).call(this);
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#This is Nila's decimal to Binary converter. It's awesome
|
2
|
+
|
3
|
+
def decimalToBinary(input_num)
|
4
|
+
|
5
|
+
remainder = ""
|
6
|
+
|
7
|
+
storage = []
|
8
|
+
|
9
|
+
unless (input_num.indexOf(".") == -1)
|
10
|
+
|
11
|
+
numsplit = input_num.split(".")
|
12
|
+
|
13
|
+
inputnum = Number(numsplit[0])
|
14
|
+
|
15
|
+
decimalplaces = parseFloat("0." + numsplit[1])
|
16
|
+
|
17
|
+
else
|
18
|
+
|
19
|
+
inputnum = Number(input_num)
|
20
|
+
|
21
|
+
decimalplaces = []
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
while inputnum >= 1
|
26
|
+
puts "2 | #{inputnum} #{remainder}"
|
27
|
+
remainder = inputnum%2
|
28
|
+
inputnum = (inputnum-remainder)/2
|
29
|
+
storage << remainder
|
30
|
+
end
|
31
|
+
|
32
|
+
storage.reverse
|
33
|
+
|
34
|
+
if decimalplaces.to_s.length > 0
|
35
|
+
|
36
|
+
storage << "."
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
calc = nil
|
41
|
+
|
42
|
+
decans = nil
|
43
|
+
|
44
|
+
(decimalplaces.to_s.length-2).times do
|
45
|
+
|
46
|
+
calc = decimalplaces * 2
|
47
|
+
|
48
|
+
decans = calc.to_s[0];
|
49
|
+
|
50
|
+
decimalplaces = parseFloat("0.#{calc.to_s[2..last]}")
|
51
|
+
|
52
|
+
storage << Number(decans)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
return storage
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
process.stdin.resume();
|
61
|
+
process.stdin.setEncoding('utf8');
|
62
|
+
process.stdin.on 'data', do |chunk|
|
63
|
+
print "Answer: #{decimalToBinary(chunk).join("")} \n\n"
|
64
|
+
end
|
65
|
+
|
data/lib/nilac/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: This feature brings Ruby's native String and Array methods to Nila.
|
2
|
+
Scenario: Input function with several native Ruby methods
|
3
|
+
Given the input file "ruby_methods.nila"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "ruby_methods.js"
|
6
|
+
The output file must equal "correct_ruby_methods.js"
|
7
|
+
|
8
|
+
Configurations:
|
9
|
+
|
10
|
+
~compiler => src/nilac.rb
|
11
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -4,7 +4,7 @@ start = numbers[0..2]
|
|
4
4
|
|
5
5
|
middle = numbers[3...6]
|
6
6
|
|
7
|
-
last = numbers[6..
|
7
|
+
last = numbers[6..last]
|
8
8
|
|
9
9
|
copy = numbers.dup
|
10
10
|
|
@@ -14,7 +14,7 @@ name = "Adhithya Rajasekaran"
|
|
14
14
|
|
15
15
|
first_name = name[0..7]
|
16
16
|
|
17
|
-
second_name = name[9..
|
17
|
+
second_name = name[9..last]
|
18
18
|
|
19
19
|
name_copy = name.dup
|
20
20
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
2
|
(function() {
|
3
|
-
var _ref1, count, current_val, first_name, last_name,
|
3
|
+
var _ref1, count, current_val, first_name, last_name, next_val, parse_name;
|
4
4
|
|
5
5
|
// This file demonstrates multiple variable initialization
|
6
6
|
|
@@ -26,10 +26,4 @@
|
|
26
26
|
|
27
27
|
count = _ref1[2];
|
28
28
|
|
29
|
-
_ref1 = ["Adhithya Rajasekaran".split((" "),1),"Adhithya Rajasekaran".split(" ",2)];
|
30
|
-
|
31
|
-
name_split1 = _ref1[0];
|
32
|
-
|
33
|
-
name_split2 = _ref1[1];
|
34
|
-
|
35
29
|
}).call(this);
|
@@ -1,7 +1,6 @@
|
|
1
1
|
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
2
|
(function() {
|
3
3
|
if (visitor_present) {
|
4
|
-
//This file is for demonstration purpose. It doesn't really achieve anything
|
5
4
|
if (active || happy) {
|
6
5
|
console.log("Hello Wonderful Visitor!");
|
7
6
|
} else if (idle && not_engaged) {
|
@@ -0,0 +1,45 @@
|
|
1
|
+
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
|
+
(function() {
|
3
|
+
var jsonp, jsonprint, name, parsejson;
|
4
|
+
|
5
|
+
name = "Adhithya Rajasekaran ".replace(/\s+$/g,"");
|
6
|
+
|
7
|
+
console.log(name);
|
8
|
+
|
9
|
+
name = " Adhithya Rajasekaran".replace(/^\s+/g,"");
|
10
|
+
|
11
|
+
console.log(name);
|
12
|
+
|
13
|
+
name = "Adhithya Rajasekaran".split(" ");
|
14
|
+
|
15
|
+
console.log(name);
|
16
|
+
|
17
|
+
name = " Adhithya Rajasekaran ".replace(/^\s+|\s+$/g,'');
|
18
|
+
|
19
|
+
console.log(name);
|
20
|
+
|
21
|
+
name = "Adhithya,Rajasekaran".split(",");
|
22
|
+
|
23
|
+
console.log(name);
|
24
|
+
|
25
|
+
name = ["Adhithya","Rajasekaran"].join();
|
26
|
+
|
27
|
+
console.log(name);
|
28
|
+
|
29
|
+
jsonprint = function(inputjson) {
|
30
|
+
return console.log(inputjson);
|
31
|
+
};
|
32
|
+
|
33
|
+
jsonp = function(inputjson) {
|
34
|
+
return console.log(inputjson);
|
35
|
+
};
|
36
|
+
|
37
|
+
parsejson = function(inputtext) {
|
38
|
+
return inputtext.split("{");
|
39
|
+
};
|
40
|
+
|
41
|
+
parsejson(jsonprint("{message:Hello World!}"));
|
42
|
+
|
43
|
+
jsonprint("{message:Hello World!}");
|
44
|
+
|
45
|
+
}).call(this);
|
@@ -21,4 +21,26 @@ puts name
|
|
21
21
|
|
22
22
|
name = ["Adhithya","Rajasekaran"].join
|
23
23
|
|
24
|
-
puts name
|
24
|
+
puts name
|
25
|
+
|
26
|
+
def jsonprint(inputjson)
|
27
|
+
|
28
|
+
puts inputjson
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def jsonp(inputjson)
|
33
|
+
|
34
|
+
puts inputjson
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def parsejson(inputtext)
|
39
|
+
|
40
|
+
inputtext.split("{")
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
parsejson jsonprint "{message:Hello World!}"
|
45
|
+
|
46
|
+
jsonprint "{message:Hello World!}"
|