Monday, February 8, 2016

Compiler Theory

Monday, February 6th 2016

Compiler Theory
This theory is basically just a reference to compiler construction, which is the underlying mechanics of how a programming language operates. For JS, there are 3 main processes that the code goes through before executing:
  1. Tokenizing/Lexing: The engine first breaks the code into parts/chunks, and not the way you would think it would. For example, var a = 2 is broken up into 2 parts. The first part is 'var a' (LHS) and the second part is '= 2' (RHS). 
  2. Parsing: The parts of code are then converted into a tree like structure (Abstract Syntax Tree) that is grammatically representative of the structure of the overall code. 
  3. Turns the AST into executable code, which is dependent on the platform
The thing about JS that leads people to think it's mainly dynamic language, when it is in fact it is in its roots a complied language, is that the code is not compiled in advance to executing. That is, it's compiled right before its executed, which apparently make it less optimal than other languages, though I guess this depends on the author's source code.

References:
http://stackoverflow.com/questions/tagged/compiler-theory
http://www.cse.msu.edu/rgroups/sens/Software/Telelogic-3.5/locale/english/help/htmlhlp/comptheory.html
http://www.diku.dk/~torbenm/Basics/basics_lulu2.pdf

No comments:

Post a Comment