Dynamic and static compiler (JavaScript)

I am currently writing a JavaScript compiler in ANTLR + Java.

I read here questions about the stack overflow on how to continue execution - and the answer always remains that it would be too difficult to make a static compilation (without JIT information) of a dynamic language, but why is this accurate? Of course, there is an obvious problem of "type resolution" in JavaScript, perhaps a problem with the function eval- but are there any other reasons? (because they don't seem too difficult to overcome pure statics (without JITS))

I rule out JIT-based compilation because I believe it will be too complicated for me.

I have experience writing static compilers with byte code execution.

UPDATE:

All your answers really help to understand the problem. To clarify, does this mean that JavaScript is harder to implement than other dynamic languages?

And it also means that they are better off using a tree-based interpreter than, for example. Bytecode (if we forget that JS is always sent to the source code, that is, it adds extra time to generate both IR and then executes it)? - or should they be equally easy / difficult?

(Im new for SOF; don't know if this is the preferred way to update the question?)

+5
source share
3 answers

, . . javascript , . , , . , .

:

var myObj = {};

function configureObject() {
    if (something in the environment) {
        myObj.myfunc = function () {alert("Hi");}
    } else {
        myObj.myfunc = function () {document.write("Hello");}
    }
}

, - , myObj.myfunc(); , myfunc myObj. .

:

var c = a + b;

, a b, .

a b - , , c .

a, b - , , c .

. , , ( ) , .

+6

JavaScript , , , . , JavaScript , , , . :

var functionName = RunTuringMachineAndReportOutputOnTape(myTM, myInput);
eval(functionName + "();");

, , myTM myInput, , , eval, , , ( ). , , , , , , . , , , .

, , , , , . , , ( - ), . , (, ..), .

+4

V8 . . JavaScript V8

EcmaScript 3 5 , . , , , .

.

function f(o, x, y) {
  with (o) { return x + y + z; }
}

o = {};
o = { z: 3 };
o = { x: 1, z: 2 };
Object.prototype.z = 3, o = {};

EcmaScript 3,

x = (function () { return toString(); })()

x = toString();

EcmaScript 3 .

+2

All Articles