How to write an interpreter for this in javascript?

I want to write an interpreter for a scripting language in javascript. Something that could run this script:

set myVariable to "Hello World"
repeat 5 times with x
begin
    set myVariable to myVariable plus " " plus x
end
popup "myVariable is: " plus myVariable

Equivalent javascript above:

var myVariable = "Hello World";
for (var x=1; x<=5; x++) {
    myVariable += " " + x;
}
alert("myVariable is: " + myVariable);

I do not want to translate from one to another, I want to write a javascript program to interpret and execute the script directly. How can I do that?

Update:

I am looking for a tutorial (preferably in javascript, but C will do) that will guide me through this. I think I'm looking for one that doesn't use any external tools, since the tools seem to be my problem. I do not want to use something that calls libraries and a bunch of ready-made code. I want to see everything that has been done from scratch.

+5
source share
3

, ... , , .

-, / , . , "" , , Javascript ( Javascript).

: http://en.wikipedia.org/wiki/Compiler

:

1.) ( ) - ( - AST), , .

2.) , (Javascript, ).

1 - grammar, . , ? , BNF ( , , (E) BNF ). - , , , . , .

LALR # - , , , . , , , , , , , - . , , , , AST . , . , , Javascript:

http://www.google.com/search?q=javascript+parser+generator

PEG.js - Parser JavaScript

Parser JS/CC

2. - - . , , AST, "" (Javascript). , "" , . , , . , plus x, , x? ? x - ? . , - - . - . - . - "" . , "", " ", .. , , ///etc ( ).

. .

+8

, , -, , . , :

  • , .
  • JS/CC (, Javascript), SableCC (, Java) antlr (, ), .
  • ( , ) , .

SableCC, , , , , .

, .

+2

Many of the answers you get are focused on the analytic part of creating an appraiser. See Programming Languages: An Application and Interpretation for Processing Writing Semantics for a Language.

0
source

All Articles