1. 12
  1.  

  2. 2

    State transition tables are awesome for building parsers. The J word formation algorithm is defined as a state transition table that translates closely to static C arrays.

    I took influence from that in my own work-in-progress toy language where I represented the lexical state transition as an array of strings in Rust:

    /*
    Word formation proceeds by interpreting the lex class data with a small tokenizing state machine.
    
    | Code | State      | Description           |
    |------+------------+-----------------------|
    | '^'  | Start      | Start of input        |
    | '#'  | Ignore     | Comment delimiter     |
    | '/'  | Comment    | Body of comment       |
    | '@'  | Atom       | Numeric array value   |
    | '_'  | Space      | Array spacing         |
    | '+'  | Symbol     | Symbolic token        |
    | 'x'  | Name       | Alphanumeric name     |
    | '&'  | Conjuction | Punctuation delimiter |
    | ','  | Text       | Literal characters    |
    | ';'  | Quote      | Escape literal text   |
    | '$'  | Accept     | End of input          |
    */
    /// State transition rules
    //    ^$-0.:+a;#
    pub const STD_TRANSITIONS: [&str; 12] = [
        "^^$^@&&+x,#", // Start
        "!^!!!!!!!!!", // Error
        "#^$#///////", // Ignore
        "/^$////////", // Comment
        "@^$_@@&+@,#", // Atom
        "_^$_@&&+x,#", // Space
        "+^$^@&&+x,#", // Symbol
        "x^$^x&&+x,#", // Name
        "&^$&@&&+x,#", // Conjunction
        ",^!,,,,,,;,", // Text
        ";^$^@&&+x,#", // Quote
        "$^!!!!!!!!!", // Accept
    ];
    
    1. 2

      static C arrays

      It’s somehow comforting that the C source code of J is approximately as readable as J code itself.