Shunting Yard Algorithm - Intro and Reverse Polish Notation

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

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

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

    10 years later and still the best explanation on the internet, thank you so much

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

    I'm in the middle of creating an expression parser. I struggled for weeks trying to implement my own method but in the end gave up and just used reverse polish notation and it works like a charm.

  • @FabioUtzig
    @FabioUtzig 8 ปีที่แล้ว +12

    "good stuff"

  • @fred-ho2yf
    @fred-ho2yf 2 ปีที่แล้ว

    thank you for your clear explanations

  • @ulasturker
    @ulasturker 11 ปีที่แล้ว

    Man u are a hero ! If only our professor could teach like you !

  • @researchandbuild1751
    @researchandbuild1751 4 ปีที่แล้ว

    Best video on the topic. Even talks about error conditions

  • @leopoldslikk3121
    @leopoldslikk3121 10 ปีที่แล้ว

    I just helped a noob on SO writing a mathematical expression parser. Figured it out by myself immediately but I thought there had to be a video describing this topic, and it had to be you lol. First noticed your channel by the floating point videos. I'm happy to know there are people actively asserting our knowledge.

  • @shubhamranjan9495
    @shubhamranjan9495 6 ปีที่แล้ว

    Hi, I absolutely loved your way of teaching. you were very chilled out :)

  • @ramlahaziz6106
    @ramlahaziz6106 6 ปีที่แล้ว

    30 seconds into the video, and I'm subscribing

  • @dboozer4
    @dboozer4 5 ปีที่แล้ว

    Thanks for the great explanation! I'm looking forward to implementing this.

  • @AndyIvan74
    @AndyIvan74 9 ปีที่แล้ว

    Thank you very much, this was very helpful. I need to write this algorithm in C to run on a STM32F407VG microcontroller with touchscreen input and I didn’t know where to being.

  • @VoltzLiveYT
    @VoltzLiveYT 9 ปีที่แล้ว +8

    Edsgar Dijkstra didn't invent Reverse Polish, That prize goes to Jan Łukasiewicz.

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

      en.wikipedia.org/wiki/Polish_notation He invented normal polish notation. en.wikipedia.org/wiki/Reverse_Polish_notation

  • @user-gp6ln5eh3n
    @user-gp6ln5eh3n 11 ปีที่แล้ว

    Who'd dislike this, who would? Just bring them to me, I'll slay them!

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    It seems easy but it's deceptively difficult!
    Thanks for watching

  • @WahranRai
    @WahranRai 8 ปีที่แล้ว

    RIP Mr. Edsger Dijkstra !

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

    Perfect!

  • @voodas
    @voodas 10 ปีที่แล้ว

    Hello Creel, nice lesson! It's parenthesis instead of bracket because of the Greek word παρένθεσης, παρένθεση on modern Greek:-) Also left bracket = αριστερή παρένθεση or ανοίγω παρένθεση and right bracket = δεξιά παρένθεση or κλείνω παρένθεση :)

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

      That's extremely cool, I don't remember seeing Greek writing ever in my life! It really lives up to the old English idiom!
      So they're definitely parentheses :)
      I'll still call them brackets for no reason at random times, old habits die hard.
      Thanks for the info, you're a legend!

  • @austinmurphy9074
    @austinmurphy9074 5 ปีที่แล้ว

    i like ur pencil pointer.

  • @executioner1939
    @executioner1939 9 ปีที่แล้ว

    Thank you so much for a very thorough and informative video :).

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

    There's an error in the pseudo-code:
    In the while statement after the "If it's an operator" line, it ought to say:
    While there's an operator on the stack, with greater or equal precedence, and the token is leftasociative...
    The greater or equal part was explained in a comment before mine.
    Without the leftasociative part, you get incorrect output for 1* 1^2^3 because the second ^ goes to the queue instead of the stack.

    • @creelsmusic5814
      @creelsmusic5814 8 ปีที่แล้ว

      +Christoph Schneider Cheers! I think I added an annotation a while back. The next vid, with the code, is correct I believe. Could be wrong, this is pretty fiddly stuff! Thanks for watching, have a good one!

  • @becooool010
    @becooool010 11 ปีที่แล้ว

    your channel is my favorite

  • @erikawwad7653
    @erikawwad7653 3 ปีที่แล้ว

    thanks

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    I'm not sure what it's called, I've not seen it before. It looks like a great algorithm though, thanks for pointing it out!
    There's some pseudo code at stackoverflow if you Google the topic:
    how-to-evaluate-an-infix-expression-in-just-one-scan-using-stacks

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    Right you are, nice spying! Thanks for pointing this out. I'll add an annotation to the vid with the correction :)

  • @sakcee
    @sakcee 5 ปีที่แล้ว

    Cool

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

    Link to his follow up video: th-cam.com/video/nj0AZW9UCYM/w-d-xo.html
    As he said below its apart of his C# calculator playlist.

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    Cheers, you're a legend!

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    Thank you, that's very thoughtful :)

  • @user-yx5oe1ly6k
    @user-yx5oe1ly6k 4 ปีที่แล้ว

    hi..
    great video Thanks.
    where do i find the next example video with unary operator?

    • @WhatsACreel
      @WhatsACreel  4 ปีที่แล้ว

      Ok, so I coded it in a C# calculator series. I really should have put them all together. Sorry about that. Anywho, the video where we started to code the token class is:
      th-cam.com/video/MYtTyFC3ZhY/w-d-xo.html
      I am not sure when we did unary operators, but it's either that vid or one of the following ones. Cheers for watching, I hope you can find the info you're after :)

  • @Peter-bg1ku
    @Peter-bg1ku 7 ปีที่แล้ว +1

    Good stuff

  • @malharjajoo6237
    @malharjajoo6237 7 ปีที่แล้ว

    this is actually a form of Operator precedence Parsing !

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

      Yes, and it's a very clever one as it has a linear run time!

  • @malpathekoxato
    @malpathekoxato 2 ปีที่แล้ว

    What with 89411/32/7/5?

  • @void_presence
    @void_presence 11 ปีที่แล้ว

    when are you gonna do the programming tutorial part of this algorithm?

  • @vitalamegamacho4645
    @vitalamegamacho4645 11 ปีที่แล้ว

    And the mistake is in this part of algo: "While there is an operator on top of the stack with greater precedence.. ". What is wrong with this step can be understood adressing to "Order of operations and RPN" by Greg Vanderbeek. It is said there that "if the stack's operator is greater or EQUAL to the current one, the pop operator is from the stack is popped and added to the postfix string". And there are some other extra things to be taken into account. So, the algo in this video is incorrect!

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

    What happened to the demo video for the shunting yard algorithm? I looked through your videos but could not find it.

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

      +cyberdaniboy I put it into another series I was making on a C# calculator. There's a playlist for the C# calculator, and I tried to link this vid to it, probably didn't work out. Look for the C# calculator playlist on the channel, you should find the follow-up vid to this one.
      Thanks for watching, have a great day!

    • @NinaHProductions1
      @NinaHProductions1 7 ปีที่แล้ว

      It would be really great if you could do the follow up video for this one - I have also been looking in your playlist. You were laughing so much in this video, I just thought that it was funny.

  • @dvorak2676
    @dvorak2676 5 ปีที่แล้ว

    thanks !

  • @vitalamegamacho4645
    @vitalamegamacho4645 11 ปีที่แล้ว

    Just registered here to say that there is a mistake in this algorithm. It produces incorrect RPN (reverse polish notation) either for this combination "(a+b)/(c-d)*f" or for this "a+((b+c)*d)-f" depending on the way how the last step is done. Anyway both formulas in RPN won't be correct simultaneously.

  • @forfengeligfaen
    @forfengeligfaen 9 ปีที่แล้ว

    Should the stack be called "operator stack" because it also has the "(" and ")" tokens that are not operators in it?

    • @WhatsACreel
      @WhatsACreel  9 ปีที่แล้ว

      forfengeligfaen Good point! It's primarily for operators but it also deals with the braces. I didn't invent the name, and now that you point it out, I reckon it's not exactly right!

  • @forfengeligfaen
    @forfengeligfaen 9 ปีที่แล้ว

    Did you ever code this?

  • @wnekuu
    @wnekuu 5 ปีที่แล้ว

    is there that second video? can't find it

    • @WhatsACreel
      @WhatsACreel  5 ปีที่แล้ว

      I think I switched it to a C# calculator vid series. Video is called "C# Windows 8 Tutorial 4: A Token Class". It's C#, but maybe generic enough to follow in other languages... Err, you are looking for implementing an expression parser, right? I hope this helps, have a good one :)

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

      Thanks, gonna look for it :)
      I'm learning c# and was looking for general info on this algorithm, found your video and if you have c# implementation then it's perfect for me :D

    • @WhatsACreel
      @WhatsACreel  5 ปีที่แล้ว

      @@wnekuu Welcome brus! Good luck mate

    • @wnekuu
      @wnekuu 5 ปีที่แล้ว

      :)

    • @wnekuu
      @wnekuu 5 ปีที่แล้ว

      It's alive! :D good to have a lot of free time at work :D for now I'm following book only on console apps so want to first master that and only then move to gui so only console for now :) github.com/SebaWnek/ConsoleCalculator

  •  5 ปีที่แล้ว

    Yeah. Good video. Yeah.

  • @Elderofwaukeen
    @Elderofwaukeen 11 ปีที่แล้ว

    Are you a Tafe teacher?

  • @dejankomocar2
    @dejankomocar2 11 ปีที่แล้ว

    I've got lost at the intro. To complicated.

  • @WhatsACreel
    @WhatsACreel  11 ปีที่แล้ว

    Nope, why do you ask?

  • @jabakado
    @jabakado 7 ปีที่แล้ว

    This was extremely helpful. Thanks! (I am coding something[1] that parses expressions like "cats #like you ##because you #like them" into a knowledge graph.)
    [1] github.com/JeffreyBenjaminBrown/digraphs-with-text/tree/master/Hash

  • @user-gp6ln5eh3n
    @user-gp6ln5eh3n 11 ปีที่แล้ว

    Who'd dislike this, who would? Just bring them to me, I'll slay them!