473,503 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert From JavaScript to Vb.net

1 New Member
I need help converting the fallowing code to vb.net, or if any one knows where i can download LISP Interpreter (VB.NET)
Thanks


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  4. <script type="text/javascript">
  5.  
  6. var DEBUG = 1;
  7. var TEST = [
  8.   "(cons 1 nil)",
  9.   "(+ 1 2 (* 3 4))"
  10. ][0]
  11. var _text = null;
  12. var _balanced = 0;
  13. var _env = null;
  14. var b = 0;
  15. function init() 
  16. {
  17.     //(defun fact (x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 3)
  18.   document.getElementById("demo").innerHTML= read("(defun fact (x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 3)");
  19. }
  20.  
  21. function read(text) 
  22. {
  23.     try 
  24.     {
  25.         _balanced = 0;
  26.         _text = $.trim(text);
  27.  
  28.         var code = ["list"];
  29.         while (_text.length)
  30.         {
  31.             var s = parser();
  32.             //alert(s.length)
  33.             code = code.concat(s);
  34.             //alert(code)
  35.           }
  36.  
  37.         if (_balanced > 0)
  38.           throw "The expression is not balanced. Add "+_balanced+" parentheses.";
  39.         else if (_balanced < 0)
  40.           throw "The expression is not balanced. Remove "+_balanced+" parentheses.";
  41.         // trace(code);
  42.         if (!_env) _env = {};
  43.         return (eval_(code, _env)).pop();
  44.       } 
  45.       catch (e) 
  46.       {
  47.         return "Error: "+e;
  48.     }
  49. }
  50.  
  51. function eval_(expr, env) 
  52. {
  53.         //alert(b+": "+expr+" : env: "+env);
  54.  
  55.         // atoms
  56.         b +=1
  57.         if (!isNaN(expr)) 
  58.         {
  59.             return Number(expr);
  60.         } 
  61.         else if (expr == "nil") 
  62.         {
  63.             return null;
  64.         } 
  65.         else if (expr[0] == '"') 
  66.         {
  67.             return expr.slice(1);
  68.  
  69.         // list
  70.         } 
  71.         else if (expr[0] == "list") 
  72.         {
  73.             return $.map(expr.slice(1),
  74.                  function(x) 
  75.                  {
  76.                 //alert(x)
  77.                    var v = eval_(x, env);
  78.  
  79.                    if ($.isArray(v))
  80.                      return Array(v);
  81.  
  82.                    return v;
  83.                  });
  84.  
  85.         // variables
  86.         } 
  87.         else if (getenv(expr, env)) 
  88.         {
  89.             return getenv(expr, env);
  90.         } 
  91.         else if (expr[0] == "setq" || expr[0] == "set!") 
  92.         {
  93.             env[expr[1]] = eval_(expr[2], env);
  94.             return env[expr[1]];
  95.  
  96.         // conditional
  97.         } 
  98.         else if (expr[0] == "if") 
  99.         {
  100.             if (eval_(expr[1], env))
  101.                 return eval_(expr[2], env);
  102.             $.each(expr.slice(2, expr[expr.length - 2]),
  103.                 function(i, x) { eval_(x, env); });
  104.                 return eval_(expr[expr.length - 1], env);
  105.  
  106.         // procedures
  107.         } 
  108.         else if (expr in operators) 
  109.         {
  110.             var z = operators[expr];
  111.  
  112.             return z; //operators[expr];
  113.         } 
  114.         else if (expr[0] == "lambda") 
  115.         {
  116.             return makeproc(expr[1], expr.slice(2), env);
  117.         } 
  118.         else if (expr[0] == "defun") 
  119.         {
  120.             alert(expr)
  121.             env[expr[1]] = makeproc(expr[2], expr.slice(3), env);
  122.  
  123.             return env[expr[1]];
  124.         } 
  125.         else if (expr[0] == "js") 
  126.         { 
  127.             // call a javascript function
  128.             return eval(expr[1]);
  129.  
  130.         // apply
  131.         } 
  132.         else if ($.isArray(expr)) 
  133.         {      
  134.             return apply_(
  135.                 eval_(expr[0], env),
  136.                   $.map(expr.slice(1), function(x, i) 
  137.                   {
  138.                     var v = eval_(x, env);
  139.                     if ($.isArray(v))
  140.                       return Array(v);
  141.                     return v;
  142.                   })
  143.                 );
  144.  
  145.         // error
  146.         } 
  147.         else 
  148.         {
  149.             throw expr+" is not defined"
  150.         }
  151. }
  152.  
  153. function apply_(proc, args) 
  154. {
  155.   if ($.isFunction(proc)) {
  156.     return proc.apply(this, args);
  157.   }
  158.   throw "Procedure "+proc+" is not defined";
  159. }
  160.  
  161. function makeproc(args, body, env) {
  162.   return function() {
  163.     // extend the env
  164.     //alert(arguments)
  165.     var arguments_ = arguments;
  166.     var newenv = {};
  167.     newenv["__up__"] = env;
  168.     $.each(args, function(i, x) { newenv[x] = arguments_[i]; });
  169.     $.each(body.slice(0, body.length - 1),
  170.            function(i, x) { eval_(x, newenv); });
  171.     return eval_(body[body.length - 1], newenv);
  172.   };
  173. }
  174.  
  175. function getenv(expr, env) 
  176. {
  177.   if (typeof expr != "string") return false;
  178.   if (expr in env) return env[expr];
  179.   if ("__up__" in env) return getenv(expr, env["__up__"]);
  180.   return false;
  181. };
  182.  
  183. ////////////////
  184. // primitives //
  185. ////////////////
  186.  
  187. var operators = {
  188.   // list
  189.   "car":function() {
  190.     var l = arguments[0];
  191.     if (!l || !l.length) return null;
  192.     return l[0];
  193.   },
  194.   "cdr":function() {
  195.     var l = arguments[0];
  196.     if (!l || !l.length) return [];
  197.     return l.slice(1);
  198.   },
  199.   "cons":function() {
  200.     var a = arguments[1];
  201.     if (a == null) return [arguments[0]];
  202.     a.unshift(arguments[0])
  203.     return a;
  204.   },
  205.  
  206.   // logical
  207.   "not":function() {
  208.     return !arguments[0];
  209.   },
  210.   "and":function() {
  211.     for (var i = 0; i < arguments.length; i++) {
  212.       if (!arguments[i]) return false;
  213.     }
  214.     return true;
  215.   },
  216.   "or":function() {
  217.     for (var i = 0; i < arguments.length; i++) {
  218.       if (arguments[i]) return true;
  219.     }
  220.     return false;
  221.   },
  222.  
  223.   // comparison
  224.   "<=":function(x, y) { return x <= y; },
  225.   "<":function(x, y) { return x < y; },
  226.   ">=":function(x, y) { return x >= y; },
  227.   ">":function(x, y) { return x > y; },
  228.   "=":function(x, y) { return x == y; },
  229.   "eq":function(x, y) { return x === y; },
  230.  
  231.   // arithmetic
  232.   "+":function() {
  233.     var res = 0;
  234.     $.each(arguments, function(i, x) { res += x; });
  235.     return res;
  236.   },
  237.   "-":function() {
  238.     var res = arguments[0] * 2;
  239.     $.each(arguments, function(i, x) { res -= x; });
  240.     return res;
  241.   },
  242.   "*":function() {
  243.     var res = 1;
  244.     $.each(arguments, function(i, x) { res *= x; });
  245.     return res;
  246.   },
  247.   "/":function() {
  248.     var res = arguments[0] * arguments[0];
  249.     $.each(arguments, function(i, x) { res /= x; });
  250.     return res;
  251.   }
  252. };
  253.  
  254. ///////////////////////////
  255. // convert text to lists //
  256. ///////////////////////////
  257.  
  258. function scanner() 
  259. {
  260.     if (!_text.length) return "";
  261.     var start = 0, index = 1;
  262.     if (_text.charAt(0) == "(" || _text.charAt(0) == ")") 
  263.     {
  264.         index = 1;
  265.         // check the text is balanced
  266.         _balanced += _text.charAt(0) == "(" ? 1 : -1;
  267.     } 
  268.     else if (_text.charAt(0) == '"') 
  269.     {
  270.         index = _text.search(/[^\\]"/) + 1;
  271.     } 
  272.     else
  273.     {
  274.         index = _text.search(/[ \n)]/);
  275.     }
  276.     //alert(index)    
  277.     if (index < 1) index = _text.length;
  278.  
  279.     var t = _text.substring(start, index);
  280.     _text = $.trim(_text.substring(index));
  281.     return t;
  282. }
  283.  
  284. function parser() 
  285. {
  286.     var result = [];
  287.     var token = scanner();
  288.     while (token != ")" && token != "") 
  289.     {
  290.         var expr = null;
  291.         if (token == "(")
  292.           expr = parser();
  293.         else
  294.           expr = token;
  295.  
  296.         result.push(expr);
  297.         token = scanner();
  298.     }
  299.     return result;
  300. }
  301. </script>
  302. </head>
  303. <body>
  304.  
  305. <h1>My First Web Page</h1>
  306. <p id="demo">This is a paragraph.</p>
  307.  
  308. <button type="button" onclick="init()">Display Date</button>
  309.  
  310. </body>
  311. </html>
Dec 6 '11 #1
2 11099
omerbutt
638 Contributor
Hi,
post the question in the .net framework section you might get help there?
regards,
Omer Aslam
Dec 6 '11 #2
johny10151981
1,059 Top Contributor
Javascript and .net run in two different platform,

Javascript run on Clinet Site on the other hand .Net Run on server Side(Arguably, If you develop a plugin with .Net to run on Clint site, like Java, Its another story).

So far, its an ambiguous conversion
Dec 7 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
14609
by: Danny | last post by:
I am new to java/javascript. I wrote javascript to proces a cookie. I don't like that fact that the code is visible to all. Can I create a java application that resides on the server and call it...
4
9645
by: D Newsham | last post by:
Hi, This javascript creates a table that has a header and side column that do not move while scrolling through the table. I need to convert this to vb script. Can anybody help, or do you have...
5
5594
by: Robin Johnson | last post by:
Hi, I've written an engine in Javascript for running text adventure games on a web page: http://www.robinjohnson.f9.co.uk/adventure/hamlet.html (That's the only game I've written with it so...
3
4325
by: geotso | last post by:
Hi I use the following script in order to show/hide a section, and at the same time to change a companion .gif with another: function doExpand(paraNum,arrowNum){ if...
1
2479
by: sathyan8294 | last post by:
what is websites for convert javascript to vbscript?
7
17276
by: maria80e | last post by:
Is it possible to convert javascript(.js) file as exe or dll? Regards, Maria prabudass E
7
4210
by: deepthi230 | last post by:
how can i convert a javascript string to xml string?
2
4481
by: David | last post by:
Hey can anyone help me convert a javascript array into a ruby array. Ive been struggling with this since friday to no avail. This is the function with the ajax.request call that is supposed to...
2
7720
by: murugavelmsc | last post by:
Hi, i have a javascript code. I want to convert into VBscript. pls help me Javascript Code:
5
4457
by: rmartine28 | last post by:
i am looking to post something in myspace profile that is java but their system doesn't allow java script, can any one tell me how to convert a java script into htlm ?
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.