473,568 Members | 2,850 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 11122
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
14614
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 this way the code will be hidden? How can a prepare it? It is an apache unix server. Thanks in advance
4
9657
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 code in vb (asp) that would do the same thing? <html> <head> <title>Scrolling Grid Demo</title>
5
5604
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 far, and a version of the engine that is slightly less sophisticated than my development copy, which has cleaner code and a more authentic...
3
4337
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 (paraNum.style.display=="none"){paraNum.style.display="";arrowNum.src="../../images/arrOn.gif"} else {paraNum.style.display="none";arrowNum.src="../../images/arrOff.gif"} }
1
2494
by: sathyan8294 | last post by:
what is websites for convert javascript to vbscript?
7
17305
by: maria80e | last post by:
Is it possible to convert javascript(.js) file as exe or dll? Regards, Maria prabudass E
7
4222
by: deepthi230 | last post by:
how can i convert a javascript string to xml string?
2
4485
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 convert the array using JSON, but I keep getting a 422(Unprocessable Entity) error. Im not sure what is wrong. function test() {...
2
7732
by: murugavelmsc | last post by:
Hi, i have a javascript code. I want to convert into VBscript. pls help me Javascript Code:
5
4459
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
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.