Program The rantings of a lunatic Scientist

Parsing begins!

L2Program Language

The PEG.js parser is now complete!!! Now all that is left to do is write the functions for the evaluator and control flow. For now I have locked the parser to only testing commands against MathExp as the root node. The function eval_math(tree) accepts a syntax tree with a root node marked as num for a plain numerical value, var for a reference to a variable, math for a simple add/sub/mult/div between two other math trees, or function which represents a call to a math function (built into the language). Below is an overview of the parse tree for a math expression (MathExp).

Math::Number

{ tag: "num", val: 0 }

Math::Variable

{
    tag: "var", 
    val: {
        id: "a",
        index: {
            // Another Math Expression
        }
    } 
}

Math::Math

{
    tag: "math", 
    val: {
        op: "+",
        left: {
            // Another Math Expression
        },
        right: {
            // Another Math Expression
        }
    } 
}

Math::Function

{
    tag: "function", 
    val: {
        func: "sqrt",
        param: {
            // Another Math Expression
        }
    } 
}

Math::Function (multiple params)

{
    tag: "function", 
    val: {
        func: "min",
        param: [
            {}, // Another Math Expression
            {}, // Another Math Expression
            {}  // Another Math Expression
        ]
    } 
}