I need help converting the fallowing code to vb.net, or if any one knows where i can download LISP Interpreter (VB.NET)
Thanks - <html>
-
<head>
-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
-
<script type="text/javascript">
-
-
var DEBUG = 1;
-
var TEST = [
-
"(cons 1 nil)",
-
"(+ 1 2 (* 3 4))"
-
][0]
-
var _text = null;
-
var _balanced = 0;
-
var _env = null;
-
var b = 0;
-
function init()
-
{
-
//(defun fact (x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 3)
-
document.getElementById("demo").innerHTML= read("(defun fact (x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 3)");
-
}
-
-
function read(text)
-
{
-
try
-
{
-
_balanced = 0;
-
_text = $.trim(text);
-
-
var code = ["list"];
-
while (_text.length)
-
{
-
var s = parser();
-
//alert(s.length)
-
code = code.concat(s);
-
//alert(code)
-
}
-
-
if (_balanced > 0)
-
throw "The expression is not balanced. Add "+_balanced+" parentheses.";
-
else if (_balanced < 0)
-
throw "The expression is not balanced. Remove "+_balanced+" parentheses.";
-
// trace(code);
-
if (!_env) _env = {};
-
return (eval_(code, _env)).pop();
-
}
-
catch (e)
-
{
-
return "Error: "+e;
-
}
-
}
-
-
function eval_(expr, env)
-
{
-
//alert(b+": "+expr+" : env: "+env);
-
-
// atoms
-
b +=1
-
if (!isNaN(expr))
-
{
-
return Number(expr);
-
}
-
else if (expr == "nil")
-
{
-
return null;
-
}
-
else if (expr[0] == '"')
-
{
-
return expr.slice(1);
-
-
// list
-
}
-
else if (expr[0] == "list")
-
{
-
return $.map(expr.slice(1),
-
function(x)
-
{
-
//alert(x)
-
var v = eval_(x, env);
-
-
if ($.isArray(v))
-
return Array(v);
-
-
return v;
-
});
-
-
// variables
-
}
-
else if (getenv(expr, env))
-
{
-
return getenv(expr, env);
-
}
-
else if (expr[0] == "setq" || expr[0] == "set!")
-
{
-
env[expr[1]] = eval_(expr[2], env);
-
return env[expr[1]];
-
-
// conditional
-
}
-
else if (expr[0] == "if")
-
{
-
if (eval_(expr[1], env))
-
return eval_(expr[2], env);
-
$.each(expr.slice(2, expr[expr.length - 2]),
-
function(i, x) { eval_(x, env); });
-
return eval_(expr[expr.length - 1], env);
-
-
// procedures
-
}
-
else if (expr in operators)
-
{
-
var z = operators[expr];
-
-
return z; //operators[expr];
-
}
-
else if (expr[0] == "lambda")
-
{
-
return makeproc(expr[1], expr.slice(2), env);
-
}
-
else if (expr[0] == "defun")
-
{
-
alert(expr)
-
env[expr[1]] = makeproc(expr[2], expr.slice(3), env);
-
-
return env[expr[1]];
-
}
-
else if (expr[0] == "js")
-
{
-
// call a javascript function
-
return eval(expr[1]);
-
-
// apply
-
}
-
else if ($.isArray(expr))
-
{
-
return apply_(
-
eval_(expr[0], env),
-
$.map(expr.slice(1), function(x, i)
-
{
-
var v = eval_(x, env);
-
if ($.isArray(v))
-
return Array(v);
-
return v;
-
})
-
);
-
-
// error
-
}
-
else
-
{
-
throw expr+" is not defined"
-
}
-
}
-
-
function apply_(proc, args)
-
{
-
if ($.isFunction(proc)) {
-
return proc.apply(this, args);
-
}
-
throw "Procedure "+proc+" is not defined";
-
}
-
-
function makeproc(args, body, env) {
-
return function() {
-
// extend the env
-
//alert(arguments)
-
var arguments_ = arguments;
-
var newenv = {};
-
newenv["__up__"] = env;
-
$.each(args, function(i, x) { newenv[x] = arguments_[i]; });
-
$.each(body.slice(0, body.length - 1),
-
function(i, x) { eval_(x, newenv); });
-
return eval_(body[body.length - 1], newenv);
-
};
-
}
-
-
function getenv(expr, env)
-
{
-
if (typeof expr != "string") return false;
-
if (expr in env) return env[expr];
-
if ("__up__" in env) return getenv(expr, env["__up__"]);
-
return false;
-
};
-
-
////////////////
-
// primitives //
-
////////////////
-
-
var operators = {
-
// list
-
"car":function() {
-
var l = arguments[0];
-
if (!l || !l.length) return null;
-
return l[0];
-
},
-
"cdr":function() {
-
var l = arguments[0];
-
if (!l || !l.length) return [];
-
return l.slice(1);
-
},
-
"cons":function() {
-
var a = arguments[1];
-
if (a == null) return [arguments[0]];
-
a.unshift(arguments[0])
-
return a;
-
},
-
-
// logical
-
"not":function() {
-
return !arguments[0];
-
},
-
"and":function() {
-
for (var i = 0; i < arguments.length; i++) {
-
if (!arguments[i]) return false;
-
}
-
return true;
-
},
-
"or":function() {
-
for (var i = 0; i < arguments.length; i++) {
-
if (arguments[i]) return true;
-
}
-
return false;
-
},
-
-
// comparison
-
"<=":function(x, y) { return x <= y; },
-
"<":function(x, y) { return x < y; },
-
">=":function(x, y) { return x >= y; },
-
">":function(x, y) { return x > y; },
-
"=":function(x, y) { return x == y; },
-
"eq":function(x, y) { return x === y; },
-
-
// arithmetic
-
"+":function() {
-
var res = 0;
-
$.each(arguments, function(i, x) { res += x; });
-
return res;
-
},
-
"-":function() {
-
var res = arguments[0] * 2;
-
$.each(arguments, function(i, x) { res -= x; });
-
return res;
-
},
-
"*":function() {
-
var res = 1;
-
$.each(arguments, function(i, x) { res *= x; });
-
return res;
-
},
-
"/":function() {
-
var res = arguments[0] * arguments[0];
-
$.each(arguments, function(i, x) { res /= x; });
-
return res;
-
}
-
};
-
-
///////////////////////////
-
// convert text to lists //
-
///////////////////////////
-
-
function scanner()
-
{
-
if (!_text.length) return "";
-
var start = 0, index = 1;
-
if (_text.charAt(0) == "(" || _text.charAt(0) == ")")
-
{
-
index = 1;
-
// check the text is balanced
-
_balanced += _text.charAt(0) == "(" ? 1 : -1;
-
}
-
else if (_text.charAt(0) == '"')
-
{
-
index = _text.search(/[^\\]"/) + 1;
-
}
-
else
-
{
-
index = _text.search(/[ \n)]/);
-
}
-
//alert(index)
-
if (index < 1) index = _text.length;
-
-
var t = _text.substring(start, index);
-
_text = $.trim(_text.substring(index));
-
return t;
-
}
-
-
function parser()
-
{
-
var result = [];
-
var token = scanner();
-
while (token != ")" && token != "")
-
{
-
var expr = null;
-
if (token == "(")
-
expr = parser();
-
else
-
expr = token;
-
-
result.push(expr);
-
token = scanner();
-
}
-
return result;
-
}
-
</script>
-
</head>
-
<body>
-
-
<h1>My First Web Page</h1>
-
<p id="demo">This is a paragraph.</p>
-
-
<button type="button" onclick="init()">Display Date</button>
-
-
</body>
-
</html>
2 11122
Hi,
post the question in the .net framework section you might get help there?
regards,
Omer Aslam
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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>
|
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...
|
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"}
}
|
by: sathyan8294 |
last post by:
what is websites for convert javascript to vbscript?
| |
by: maria80e |
last post by:
Is it possible to convert javascript(.js) file as exe or dll?
Regards,
Maria prabudass E
|
by: deepthi230 |
last post by:
how can i convert a javascript string to xml string?
|
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()
{...
|
by: murugavelmsc |
last post by:
Hi,
i have a javascript code. I want to convert into VBscript.
pls
help me
Javascript Code:
|
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 ?
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |