Skip to content

This is a compiler for the Egg language that is mentioned in Chapter 12 of Eloquent Javascript

License

syildizz/EggLang-Compiler-Extended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EggLang Compiler Extended

This is a compiler for the Egg language that is mentioned in Chapter 12 of Eloquent Javascript. The compiler compiles the Egg language into javascript as defined in the original specification. It also adds some new features to the Egg language that did not exist in the original specification.

The code features here is built upon the original code by Marijn Haverbeke.

The javascript code which is generated by the EggLang Compiler is correctly indented and has semicolons inserted in the correct places for readability sake.

Extensions

The compiler includes the extensions that are given in the exercises. Such as:

  • Array support
  • Comment support
  • Set statement support

For statement

The compiler supports for statements in the form of

for(arg1, arg2, arg3, body)

which corresponds to the typical for loop in other languages where

for (arg1; arg2; arg3) {
    body;
}

Native statement

The compiler supports a native statement. The native statement is used for writing inline javascript. It passed the expressions inside of it directly into the compiled code.

native(body)

becomes

body

Extern statement

The compiler supports an extern statement. The extern statement is used to define a label to the compiler that is outside of it's scope.

Normally, the compiler would throw an error when accessing a label that it does not recognize. The extern statement adds the label to the compiler so that it can properly recognize it. This statement is usually used to access global variables from javascript or from native statements.

extern(label)

becomes

// External label: label

No code is generated since this statement is for the compiler only.

Push statement

The compiler supports a push statement. The push statement is the Array.prototype.push method implemented for Egg language.

push(array, val)

becomes

array.push(val);

Incompatibility

For the most part, the compiler is compatible with the original Egg language interpreter mentioned in Eloquent Javascript. However, due to implementation details, there are some incompatibilities between the compiler here and the interpreter.

In the interpreter, the expressions if and while return the value 0. However, in the compiler, the compiler compiles them into if and while statements. Because of this, they do not return any value when compiled.

About

This is a compiler for the Egg language that is mentioned in Chapter 12 of Eloquent Javascript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published