Environments & Variable Storage - Programming Language From Scratch

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 40

  • @hindihits9260
    @hindihits9260 ปีที่แล้ว +3

    thank you for this great series! you did an amazing job :) I was wondering if we are also going to implement custom grammar for this language or not since I've followed 4 videos.

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว +1

      No custom grammar like using BNF. For this the grammar is just pulled out of thin air lol. Glad you enjoy it though.
      If you neee any further assistance please feel free to reach out to me at my discord.

  • @hamzaalsorkhy4399
    @hamzaalsorkhy4399 ปีที่แล้ว +1

    thank you for this great series! i love how you explain things and how u respond to the comments LOL! are there plans to do conditionals in the future?

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว

      No plans currently to resume THIS series. However I will gladly hop on a discord call with you or anyone interested.

  • @NootNooter
    @NootNooter ปีที่แล้ว +1

    I don't understand why you are removing the declaration around the null literal? You are still using it inside macro MK_NULL

  • @tsurumaruwordpress
    @tsurumaruwordpress 2 ปีที่แล้ว +3

    Really enjoying this series! At this point it looks like in this interpreter we will be able to reassign true, false and null. Is that correct?

    • @tylerlaceby
      @tylerlaceby  2 ปีที่แล้ว +1

      Yes that's a great observation. However when we define the declare function we can pass a third argument whether the value is constant.
      Then we will store not only the records but also a Set to store records.
      In the next video we will go over the VarDeclarationStmt and AssignmentExpr which should shed some light on it more.
      However in the meantime if you would like to see a example you can look here: github.com/tylerlaceby/emu/blob/main/src/interpreter/values/environment.h as well as here:
      github.com/tylerlaceby/emu/blob/main/src/interpreter/std/global/env.cpp

    • @tsurumaruwordpress
      @tsurumaruwordpress 2 ปีที่แล้ว +1

      @@tylerlaceby thanks for taking the time to reply and share further details. I'm glad you're doing this series in TS as it's a lot easier for me to follow that C++ :). Out of interest, roughly how many more videos are planned? Are you going to go as far as building in File System integration, as you did with Emu? I read earlier that you've written 10(?) interpreters before - did you ever do one for a strongly-typed language? I have often wondered if it's a small degree or an order of magnitude more complicated. Anyway, thanks again, truly appreciate the work so far :)

  • @rezarg
    @rezarg 2 หลายเดือนก่อน +2

    Why are you using interfaces and "macros" (as you call them) to declare things like NumberVals? From the start, I thought the interface approach didn't make sense, so I made all of mine Classes, so I could call "new NumberVal(100)".

    • @tylerlaceby
      @tylerlaceby  หลายเดือนก่อน +1

      Yea that honestly makes more sense for Typescript. I was originally planning on doing the series in Go or C but last minute changed it to Typescript and sadly didn't put as much thought into the types as I wish I had.
      In the second series which was done in Go there was much more consideration and forethought put in. Hopefully you still found it still useful.

  • @hamidhamri5384
    @hamidhamri5384 ปีที่แล้ว +2

    I have a question , is this how languages are made? For example, JavaScript is executed with the JavaScript engine v8, which is written in C++, what I want to know is if I create a variable or an object in JavaScript, does the engine create an object in C++ and stores it in a hashmap ?

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว

      No it does not. This is a very high level implementation with slot of room for improvement. The vm JavaScript uses wood be parsed and compiler into a IR language called bytecode. This bytecode is thin executed by V8. V8 will also add optimizations and JIT if possible.
      So no the way languages like python, ruby, lua, JavaScript, Java, C#, etc do this is a step lower called bytecode interpretation.
      JS will use a Tagged union under the hood for each of its values. This tagged union allows everything to be stored as a pointer for the RuntimeValue but adds a level of indirection.

    • @chris0617
      @chris0617 ปีที่แล้ว

      @@tylerlaceby what a chad

  • @marcelijankowski9593
    @marcelijankowski9593 ปีที่แล้ว +2

    I have a question, maybe it's silly but ever since I started watching this series I've been wondering, why did you use "frontend" as a name for parser/lexer directory?

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว +3

      Not silly at all. In my mind I like to separate a language into multiple stages. The front end and backend will be it for ours. The frontend contains the code for validating user input and grammar. This would be where we could also run analysis on our code to ensure type safety or check for unused code/variables or unreachable code. The code in the frontend is code that can happen at compile time before any code is executed or compiled.
      The backend is the runtime or compiler depending on what were building. In this case were simply walking the tree after building it so the difference is minimal. In a more complex language the backend would be things like IR and code optimization's. Compiling it to machine or bytecode could also be a more backend role as we leave the land of fancy grammar and traverse into more optimized and less human readable code.
      For this series it does not matter much. Good question. If you have any others or want extra help/assistance feel free to message me on Discord. Cheers.

    • @marcelijankowski9593
      @marcelijankowski9593 ปีที่แล้ว

      @@tylerlaceby Thx you're very helpful!

  • @arcticyeti1
    @arcticyeti1 ปีที่แล้ว +2

    Great stuff! Personally I'm starting to branch out by making booleans and nulls literals, since then they can't really be overridden

  • @Voltra_
    @Voltra_ 8 หลายเดือนก่อน +1

    Null, true and false being re-assignable? This will be troublesome somewhere

    • @tylerlaceby
      @tylerlaceby  8 หลายเดือนก่อน

      Yep. I’m pretty sure that’s addressed in future video. All you have to do it make it constant xD

  • @TheBusinessDude
    @TheBusinessDude 2 ปีที่แล้ว +1

    Where's part 6?

  • @Zooiest
    @Zooiest ปีที่แล้ว +2

    Can you make a video about compiling languages down to bytecode?

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว +2

      Probably not. But if you would like to message me on discord I would love to hop on a call and show you how you can approach it and maybe do an example with math operations for a stack vm.

    • @Zooiest
      @Zooiest ปีที่แล้ว

      @@tylerlaceby ah, I wish I could, but I'm still battling with my social anxiety about calls

  • @bighair471
    @bighair471 2 ปีที่แล้ว +2

    My Guy!

  • @alexanderjarfjall4244
    @alexanderjarfjall4244 ปีที่แล้ว

    I have a question: How do I make it assign a variable instead of throwing an error?
    In assignVar
    And what VsCode Theme do you use?

  • @mumk
    @mumk 8 หลายเดือนก่อน +1

    thank you very much...

  • @lacrador_idiota
    @lacrador_idiota 2 ปีที่แล้ว +1

    Please, continue

  • @logangraham2956
    @logangraham2956 ปีที่แล้ว

    "as it does not exist" is kind of a lie though.
    this resolve function can only check backwards in the chain of enviroments so if there is this variable ahead or beside then the variable exist however it can't be found.

    • @tylerlaceby
      @tylerlaceby  ปีที่แล้ว

      Not a lie lol but for the context of finding a variable at runtime it’s true. If it’s not found it does not exist. There’s no way a scope could be parallel to what you said if the scope has not yet been created.
      Furthermore if it exists but is not traversable then it’s an issue with garbage collection not scope traversal.
      However in this example when a scope does not exist it truly does not exist. It does not matter that it could exist in the future at that moment it does not exist and as this language is single threaded there’s no way two variables of the same name exist at the same time.
      If you are not sure then ask but don’t say it’s kinda a lie as it not lol. You just don’t understand the concept of scope traversal in an ast interpretated language.
      I don’t lie lol. If I did I would correct it as done before in other videos 😃

    • @logangraham2956
      @logangraham2956 ปีที่แล้ว

      @@tylerlaceby
      say we create an enviroment and it's a child of the root enviroment.
      then we create another enviroment which is also a child of the root enviroment
      we'll call them b and a
      in b we create a test variable
      and in a we look for a test variable
      a will not be able to find this test variable but it does exist.
      furthermore if the root enviroment looks for this variable it will also not find it even though it very much does exist.

    • @shadyturnip-gw9eu
      @shadyturnip-gw9eu ปีที่แล้ว

      @@logangraham2956 This is a peculiar comment. Are you suggesting that the resolver should be able to find the test variable even though the test variable exists in a scope that hasn’t been analyzed yet? I’m not sure if that’s even possible in a language like JavaScript (at least not without some strange, expensive traversal). And even if it were, that would make for a very confusing language. If a and b exist in two different scopes, I absolutely do not want them seeing each other. The whole point of scoping is to make sure bindings don’t exist at particular points of execution. I.e., physically seeing the binding != existence.

    • @logangraham2956
      @logangraham2956 ปีที่แล้ว

      @@shadyturnip-gw9eu not that is should be able to be found, that simple it exist even if it cannot be found by traversing to each parent.
      the discoverability and the existence of a variable are not strictly bound to each other.

    • @shadyturnip-gw9eu
      @shadyturnip-gw9eu ปีที่แล้ว +1

      @@logangraham2956 I see now where you're going wrong. In programming languages, discoverability (i.e., variable resolution) is a prerequisite for "existence." In mathematics or philosophy, sure, discoverability and existence aren't strictly bound. But this isn't mathematics or philosophy. This is CS.

  • @sterlydolce
    @sterlydolce 6 หลายเดือนก่อน +1

    I don't know why I want to make a scripting language from scratch but I do wanna make one for my game engine😅

    • @tylerlaceby
      @tylerlaceby  6 หลายเดือนก่อน

      Go for it. It's a great thing to build even if it's not necessarily a fast or practical language, writing one can be a great way to truly get better at programming

  • @Llamaful
    @Llamaful 2 ปีที่แล้ว +3

    🎉

  • @mehmetemin1999
    @mehmetemin1999 2 ปีที่แล้ว +2

  • @fedordostoevskiy4209
    @fedordostoevskiy4209 ปีที่แล้ว +1

    👀👀👀👍👍👍