ph4un00b / f_interpreter

๐Ÿ“š Learning Rust by Crafting Interpreters (Java) / Write Your Own Interpreter (Go)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

๐Ÿ• LOX - Crafting Interpreters (Java)

  • cd monkey_parser && cargo test --package monkey_parser --bin monkey_parser `

๐Ÿ• MONKEY - Write Your Own Interpreter (Go)

  • cd lox_parser && cargo test --package lox_parser --bin lox_parser

estructura โœจ

  • grammars: contiene poc's de PEG con la librerรญa pest

  • lox parser:

    • minimal parser for 1 - (2 * 3) < 4 == false
    • a more procedural / imperative code style
    • uses a top down parser
    • โœ… let variables
    • โœ… loops
    • โœ… block scope
    • โœ… functions
    • โœ… semantic analysis aka resolver pass
    • โœ… closures
    • โœ… classes
    • โœ… inheritance
  • monkey parser:

    • a more object oriented code style
    • uses a pratt parser
  • linked_list: since block scoping is similar to a linked-list, I will take tour on this

semantic analysis

  • Write a chunk of code that inspects the userโ€™s program, finds every variable mentioned, and figures out which declaration each refers to.
  • after parsing and before interpreting, any work that doesnโ€™t rely on state thatโ€™s only available at runtime can be done in this way.
  • Variable resolution touches each node once, so its performance is O(n) where n is the number of syntax tree nodes. More sophisticated analyses may have greater complexity, but most are carefully designed to be linear or not far from it. Itโ€™s an embarrassing faux pas if your compiler gets exponentially slower as the userโ€™s program grows.

tokens

  • stateful: literal value, line

parser

  • ast creation
  • error handling (logging them or accumulating then displaying them)
    • synchronization

statements

  • Functions return values.
  • Procedures cannot return values.
  • print statement evaluates an expression and displays the result to the user
    • BASIC and Python have dedicated print statements and they are real languages. Granted, Python did remove their print statement in 3.0โ€‰.โ€‰.โ€‰.
    • why it is bad?

evaluation

  • walking recursively the ast tree (slow)
  • conversion into bytecode (fast)
    • like ruby >1.9

data types

  • primitives: int, byte, short, char
  • references: compound data structures

About

๐Ÿ“š Learning Rust by Crafting Interpreters (Java) / Write Your Own Interpreter (Go)


Languages

Language:Rust 100.0%Language:Monkey 0.0%