Did you know ... | Search Documentation: |
Pack transpiler -- prolog/simplified translator/input.txt |
function distance(x1,y1,x2,y2)
{
return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2))
;
}
index_in_array(the_arr,to_find)
{
var i = 0;
while(i < the_arr.length)
{
if(the_arr[i]+0 === to_find){
return the_arr[i];
}
else{
i++;
}
}
}
matches_pattern(arr,pattern)
{
if(pattern.length !== arr.length){
return false;
}
else{
var i = 0;
while(i<arr.length)
{
if((last_char(pattern[i]) !== '_') && (pattern[i] !== arr[i])){
return false;
}
else{
i++;
}
}
}
return true;
}
function last_char(the_string)
{
return the_string.charAt(the_string.length - 1)
;
}
var z = string_matches_pattern("hello stuff","hello 1_")
;
function string_matches_pattern(str1,pattern)
{
return matches_pattern(str1.split(" "),pattern.split(" "))
;
}
while_loop(lang,a,b)
{
if(["javascript","java","c","c++"].indexOf(lang)
!== -1){
return "while("+a+")
{"+ b +"}";
}
else{
return "undefined";
}
}
if_statement(lang,a,b)
{
if(["javascript","java","c","c++"].indexOf(lang)
!== -1){
return "if("+a+")
{"+ b +"}";
}
else{
return "undefined";
}
}
elif_statement(lang,a,b)
{
if([("java"+"script"),"java","c","c++"].indexOf(lang)
!== -1){
return "else if("+a+")
{"+ b +"}";
}
else{
return "undefined";
}
}
function infix_arithetic_langs(lang)
{
return (["javascript","perl","python","java","java","c","c++","perl"].indexOf(lang)
!== -1);
}
add(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " + " + b;
}
else{
return "(+ "+a+" "+b+")";
}
}
subtract(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " - " + b;
}
else{
return "(- "+a+" "+b+")";
}
}
multiply(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " * " + b;
}
else{
return "(* "+a+" "+b+")";
}
}
divide(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " / " + b;
}
else{
return "(/ "+a+" "+b+")";
}
}
less_than(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " < " + b;
}
else{
return "(< "+a+" "+b+")";
}
}
greater_than(lang,a,b)
{
if(infix_arithmetic_langs(lang))
{
return a + " > " + b;
}
else{
return "(> "+a+" "+b+")";
}
}
indent_line(line,number_of_indents)
{
var i = 0;
while(i < number_of_indents)
{
line = " "+line;
i++;
}
return line;
}