notes

Initial implementations of jq

The initial commit of jq is a Haskell implementation, before it was converted to C a month later. This reviews the language in those two commits.

Features

Notably, it only supported integers, not floating point, and the syntax of filter calls was different. It was not Turing-complete.

Stack annotations with a, b, c, d, e, and f have not been analyzed to be named. I am not sure of the precise operation of the unlabeled operations (find, LOADK, LOADV, and STOREV) and most control-flow operations (YIELD, EACH, FORK, JUMP, and BACKTRACK).

Haskell implementation grammar

Lexer:

IDENT ::= [a-z A-Z _] [a-z A-Z 0-9 _]*

STRING ::= "\"" CHAR* "\""
CHAR ::=
    | PRINTABLE -- [\"\\]
    | "\\" ["\\/]
    | "\\" [nrt]
    | "\\u" [0-9 a-f A-F]{4}

INT ::= [0-9]+

WHITESPACE ::= …

RESERVED ::=
    | "." | "[" | "]" | "," | ":" | "(" | ")" | "{" | "}" | "|" | "==" | "+"

Parser:

Exp ::=
    | Exp "|" Exp   # left associativity
    | Exp "," Exp   # left associativity
    | Exp "==" Exp  # no associativity
    | Exp "+" Exp   # left associativity
    | Term

ExpD ::=
    | ExpD "|" ExpD
    | ExpD "==" ExpD
    | Term

Term ::=
    | "."
    | Term "." IDENT
    | "." IDENT
    | STRING
    | Term "[" Exp "]"
    | Term "[" "]"
    | "(" Exp ")"
    | "[" Exp "]"
    | INT
    | "{" MkDict "}"
    | IDENT "(" Exp ")"
    | IDENT

MkDict ::=
    | MkDictPair
    | MkDictPair "," MkDict  # left associativity

MkDictPair ::=
    | IDENT ":" ExpD
    | IDENT
    | STRING ":" ExpD
    | "(" Exp ")" ":" ExpD

C implementation grammar

Lexer:

Number ::= [0-9]+

IDENT ::= [a-z A-Z 0-9]+

WHITESPACE ::= [ \n\t]+

RESERVED ::=
    | "." | "=" | ";" | "[" | "]" | "," | ":" | "(" | ")" | "{" | "}"
    | "|" | "+" | "$" | "==" | "as"

Parser:

Exp ::=
    | Term "as" "$" IDENT "|" Exp  ; "|" is left associative
    | Exp "|" Exp                  ; left associativity
    | Exp "," Exp                  ; left associativity
    | Term

ExpD ::=
    | ExpD "|" ExpD
    | Term

Term ::=
    | "."
    | Term "." IDENT
    | "." IDENT
    | Term "[" Exp "]"
    | Term "[" "]"
    | NUMBER
    | "(" Exp ")"
    | "[" Exp "]"
    | "[" "]"
    | "{" MkDict "}"
    | IDENT
    | "$" IDENT

MkDict ::=
    |
    | MkDictPair
    | MkDictPair ',' MkDict

MkDictPair ::=
    | IDENT ':' ExpD
    | IDENT
    | '(' Exp ')' ':' ExpD