JavaScript Compiler Logic Error:

a.b.c = a.b = a = {};

assignment precedence is right-to-left, name lookup is left-to-right?


A JavaScript Compiler Maker written in JavaScript, (class project)

Using a modified LR1 parser with segmented statements to produce a LR2 look ahead to resolve complex state tables.

These are Extensions I have added to JavaScript:

  • Block comment assignments (with user specified unique syntax)
    (a multi-line text assignment using the existing block comment syntax)

    A = /*  Hello World from everyone.
            There are many of us here */

    A = /*+anystring+ a block with */ inside the block comment +anystring+*/

    A = /*++  Again */ used ++*/;

    "anystring" simply needs to match

  • Dynamic Natural Language compiler extensions, these are language syntax descriptions attached to a function
    • list lookup ^color
    • strings *, numbers #, dates $, hex +, variables @name, text number (one, two...) #
    • proper names %
    • optional values {the}  (i.e. '{color} ^color'   an optional "color" word )
    • arrays [^color]
    • sub-expressions (style)
    • function calls ~parse_csv passing the token list
    • reset of the line &
    • up to |,|
    • value exists in statement \clif\
    • grab ()
    • store as name=  (i.e. color= ^color)
    • not !
    • OR, one condition from a list  (i.e.  ['red','blue'] either red or blue)
    • AND,  all words in a value satisfied (i.e. ['color ^color','^color'] word "color" and a valid color name or just a color name)
  • operator  ** (a,b) 
        Jane JavaScript is not case sensitive.
        Jane the precedence is **.  // compiler directives
        return math.pow(a,b);

    X = 4;

    A = 2 ** X ** 3;  // A = 2 ** (4 ** 3)


    operator_prefix where is (p1) { return p1.location; }

    alert(where is employees[0]);

    operator_suffix went (p1)
        Jane the syntax is went to the ^where, went ^where.
        Jane add list, name where, values home, store, and bank.

        p1.location = result.where;

    employee[0] when to the bank; clif went home;

    language_function style()
        Jane syntax name is style, format as html style, values color ^color, ^color, height #.


    alert(color red height 340);  

    assign equals(A) { return A; }

    C equals Math.random() * 200;

    assign inverted moved into (p1) { return p1 }

    C moved into B;

  • Remove the need to declare local variables
    • a slight change to the internal identifier lookup search path
    • can still declare, not but required
    • force declaration of global variables to the explicit
  • Added the "goto" statement
  • Sub-String and Sub-Array expressions

    B = "Hello World everyone";
    A = B[6:+5];  // A = "World"

    C = [0,1,2,3,4,5,6,7,8];
    A = C[3:6];    // A = [3,4,5,6];

  • Added the SQL select statement, (overly complex for the above natural language analyzer, but it could be done)

    A = {[{name:"Collins"},{name:"Simson"},{name:"Barney"},{name:"Smith"},{name:"Jones"},

    B = ['Collins','jones','smith'];

    C = select top 10 from A where name in (B) sort by name;

    E = world.IBM.employees;

    V = world.IBM.employees.vehicles;

    P = world.IBM.vehicles.pictures_urls;

    A = Select Z.*,P.picture_url,P.icon_url from
        (Select,V.age,V.boughtdate,V.vehicle_id,E.employee_id from
            E join V on E.employee_id = V.employee_id) where (name like A%) as Z)
        join P on Z where P.vehicle_id = Z.vehicle_id) order by employee_id;

    Jane display A;
    what isn't obvious, is my "Library Card" logic: values are not necessarily loaded but might be loaded later or not at all. "JANE" will determine when and where to execute the statement.

  • Added new global names
    • world, every machine
    • local, my machine
    • user, my stuff

These are some more modifications to JavaScript I plan on implement:

  • Compile to Assembler, run on any machine (will also run in emulation mode)
  • Remove Closure (use a more direct approach "bind")
  • Sub-Functions with parent's "this" object
  • Make more information available to functions
    • local variable names
    • call stack
    • caller
  • True asynchronous function calls with multiple return / entry points
  • Temporally release execution, (Process Messages)
  • Entry points
  • Remove statement functions
  • Qualified Function Names " function my.trim() { }" ; (default is "window") (or we change global: "global = my;")
  • Extend language
    • Binary statements for access to binary structures
    • Assembler Code in JavaScript,  R0 = 12;  SHL R0, 3; alert(R0);
  • Variable Length Binary for all values (strings, numbers, float, date, arrays, ...), no limits on numbers (i.e. date of any precision: "-15 trillion trillion years in Pico seconds")
  • Extend values list (bits, vectors, matrix, date, person, place, ...)
  • Make Strings, Numbers, Boolean ==> Objects, (All values are objects:  a = "clif"; a.type = 'person') (solves a lot of problems)
  • External Prototypes to Objects (person.print, speed.units)
  • Common Ground 3000 (CG3) transport, self defining variable length binary structures (no need to reformat binary to/from string, one format to use and to store)
  • Mutable Strings  (name[0] = name[0].toUpperCase())