What Is An Abstract Syntax Tree, With WealthFront Engineer Spencer Miskoviak

Поделиться
HTML-код
  • Опубликовано: 25 окт 2024

Комментарии • 9

  • @schmoris
    @schmoris 2 месяца назад +11

    Holy snack, the lady at the end gave me a heart attack! Nice video tho.

  • @about2mount
    @about2mount 8 месяцев назад +3

    Trees and Nodes honestly do not exists. They are only Imaginary scholarly taught schematics as a study to teach new programmers how to perform Logic of a programs syntax while developing a parser Engine.
    A syntax is Parsed from Left To Right within a Loop which moves from Top to Bottom thousands to millions of times per second. And as its being parsed, global, string and static variables are set for counting, for storing buffered short expression patterns and to store specific data into struct arrays for further processing.
    And we called this........."Logical Routines". You have a good presentation, a passion and are determined. Stay with it. Thanks.

    • @CELESTEisdead
      @CELESTEisdead 3 месяца назад

      "doesn't exist" maybe for you java plebs, try that in C

  • @BeRohan5
    @BeRohan5 Год назад +4

    Good simple straightforward explaintion.
    I would love to watch a detailed video about the same. It would be just great if you can turn it into a 10 part series.
    Thanks for the video and please keep the great work coming :)

    • @newlinedotco
      @newlinedotco  Год назад +1

      Awesome! More to come soon. You might enjoy the full course too! You can check it out here, www.newline.co/courses/practical-abstract-syntax-trees.

  • @darraghconnaughton5095
    @darraghconnaughton5095 10 месяцев назад

    Excellent video, feel I have a much better grasp of AST now. Thank you.

  • @danielcrompton7818
    @danielcrompton7818 Месяц назад

    I write it in Swift
    import Foundation
    import CoreGraphics
    protocol Number {
    static func + (lhs: Self, rhs: Self) -> Self
    static func - (lhs: Self, rhs: Self) -> Self
    static func / (lhs: Self, rhs: Self) -> Self
    static func * (lhs: Self, rhs: Self) -> Self
    }
    extension Int: Number { }
    extension Float: Number { }
    extension Double: Number { }
    extension CGFloat: Number { }
    struct Operation {
    /// Enum to represent **a node on an AST** (abstract syntax tree). The node can either be a number (with something numeric attached to it) or another operation (which is also associated with the case).
    indirect enum Term {
    case number(N)
    case operation(Operation)
    static var `default`: Term { Term.number(0 as! N) }
    }
    /// Store the left hand node
    let left: Term
    /// Store the right node
    let right: Term
    /// Store the calculation function to calculate an answer from 2 numbers (not Terms, these are handled later)
    let reduce: (N, N) -> N
    init(_ t1: Term = .default,
    _ t2: Term = .default,
    reduce: @escaping (N, N) -> N) {
    self.left = t1
    self.right = t2
    self.reduce = reduce
    }
    func calculate() -> N {
    // Return a value of the calculation function `calculate` on the terms. It traverses the tree first to find the last operation, return the result and continute up the tree until the current node
    /// Function to recursively traverse the tree, calculating the leaf operations first
    func evaluate(_ term: Term) -> N {
    return switch term {
    case .number(let num):
    num
    case .operation(let op):
    op.calculate()
    }
    }
    // Return the current operation's calculation on the 2 terms
    let t1 = evaluate(left)
    let t2 = evaluate(right)
    return reduce(t1, t2)
    }
    }
    let op = Operation(.number(2),
    .operation(Operation(.number(5.0), .number(10), reduce: *)),
    reduce: +)
    // Output 57
    print(op.calculate())