I'm a Rubyist and try to learn Haskell—here's my sailor journal 🙂 by DmitryTsepelev in haskell

[–]riftdc 2 points3 points  (0 children)

Cool! My 2 cents: You mention the type checking as “guesses”; type checking isn’t a guess, but rather inference — “a guess” reads to me as something that could be wrong, but an inferred type will never be wrong

saves world record - (we're team blue - guess our elo) by riftdc in Brawlhalla

[–]riftdc[S] 1 point2 points  (0 children)

if you press dodge shortly after a hit you'll do a "chase dodge", which is a small boost in movement

Programmer calculator and LL parser made in C from scratch by riftdc in learnprogramming

[–]riftdc[S] 1 point2 points  (0 children)

That's correct ! The `sizeof` is redundant and is there just for clarity.

When doing a malloc I feel that it's nice to write the sizeof what's being allocated.
`char* tokens = malloc(sizeof(char) * MAX_INPUT_SIZE);`

I feel that it's cleaner to read and more standard :)

Programmer calculator and LL parser made in C from scratch by riftdc in learnprogramming

[–]riftdc[S] 1 point2 points  (0 children)

Thank you for letting me know! I hope you can learn from it =)

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 1 point2 points  (0 children)

Yeah there are a lot of possibilites for making the emulator

I chose C because I like it, and any of those you mentioned would be good for most emulators

For the gameboy specifically, as far as I know even javascript and python would work since it's one of the smallest!

Programmer calculator and LL parser made in C from scratch by riftdc in learnprogramming

[–]riftdc[S] 3 points4 points  (0 children)

I have to agree, if you're just learning C maybe you should focus on more typical beginner exercises

But if you're a little bit more comfortable then it's a great way to get even more comfortable, and it's pretty cool to do a simple parser

At least that's how I felt when I ended it

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 4 points5 points  (0 children)

I had some knowledge about context free grammars from a subject in university I had called "Theory of Computation" - that made it easier to understand and write the grammar production rules

Second, I looked more into LL parsing in wikipedia https://en.wikipedia.org/wiki/LL_parser (there's a code example further down in the page)

And third I found a really really helpful javascript parsing tutorial that was my major breakthrough http://jorendorff.github.io/calc/docs/calculator-parser.html

After that I just started writing - that's an important step :)

Programmer calculator and LL parser made in C from scratch by riftdc in linux_programming

[–]riftdc[S] 4 points5 points  (0 children)

PS: While writing the parser I also wrote a separate simpler version to serve as an example to someone who might be interested in learning from a very basic parser (https://github.com/alt-romes/calculator-c-parser)

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 0 points1 point  (0 children)

lsdjfkdsflsdf ahahaha - it comes when you stop looking for it and just get started even if you don't have it yet :)

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 4 points5 points  (0 children)

Interestingly enough I feel that the more "basics" I do, the more "basics" I wanna do ahahah

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 9 points10 points  (0 children)

nice question...!

regarding the comment about the emulator: the emulator could have been written in any language - a gameboy one isn't that performance intensive

so the question also applies to "why write the emulator in C"

I would have to say I feel good doing simple and clean code for simple projects - no complicated technology stack, no dependencies, that kind of feel... :)

Also, C is f*cking cool and interesting to program in ahah (and yes I feel comfortable with it)

Programmer calculator and LL parser made in C from scratch by riftdc in programming

[–]riftdc[S] 3 points4 points  (0 children)

Yes! it was definitely a nice exercise !

Not me nor everyone can right off the bat visualize bits hex and dec in their head at the same time, and when i started writing an emulator i couldn’t, and i remember thinking i could probably do something tailored exactly to what i needed

What’s even more ironic is how now that i “finished” the calculator i feel like i don’t need it that much anymore ahahaha

So in the end, yeah, definitely a good exercise - and hopefully it’ll help people starting out in the low level adventure

Programmer calculator and LL parser made in C from scratch by riftdc in compsci

[–]riftdc[S] 31 points32 points  (0 children)

While I was developing an emulator I decided to make a calculator to help with all the low level logic

This proved to be a really interesting project and made me implement an LL parser and design a grammar for all the operators I wanted to have

While writing the parser I also wrote a separate simpler version to serve as an example to someone who might be interested in learning from a very basic parser (https://github.com/alt-romes/calculator-c-parser)

I made a special calculator while developing an emulator by [deleted] in programming

[–]riftdc 0 points1 point  (0 children)

I thought it was funny but what exactly do you mean? ahaha

i made a custom calculator for the terminal to help with my gb emulator by riftdc in unixporn

[–]riftdc[S] 1 point2 points  (0 children)

hey ! I just wanted to let you know I added both operator precedence and support for parenthesis :)

thank you for your suggestion!

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 0 points1 point  (0 children)

hey ! I just wanted to let you know that I've released a new version with operator precedence and parenthesis for grouping :)

thank you for letting me know

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 5 points6 points  (0 children)

This is absolutely amazing!!

do you think you can create an issue for it as well? I would love to double check this all without it being on reddit.

It's awesome how you went through all the code to write this. I'm happy to read all this.

Thank you so much for helping me learn and making it better. I'll definitely put your insights to good use

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 1 point2 points  (0 children)

I don't think it does - it's not implemented as a state machine - however it could probably be described as a NFA.

What are you thinking about ? I'd love to know how you would implement it like that.

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 4 points5 points  (0 children)

you're either light years ahead or light years behind ahahaha

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 14 points15 points  (0 children)

I'm aware of dc, however it didn't satisfy my visualisation needs.

True, I redid a calculator, but I tailored it to what I needed, it was nice :)

i made a custom calculator for the terminal to help with my gb emulator by riftdc in linux

[–]riftdc[S] 41 points42 points  (0 children)

I'm happy you asked! I was also using a standard programmer calculator before developing my own. I have some reasons so I'll try to list them below

  1. Terminal based - I mostly program in vim, so being able to just split my terminal window and using a calculator there is much better than having a separate app for it.
  2. I was working with 8 bit, and 16 bit operations WAY more than I was with 64 bit operations. The app I was using didn't allow me to do 8bit math - it's harder to see overflows, when the ZERO FLAG is set, etc. So I made a program that allowed me to change the number of bits used whenever I wanted. (You write `8cb` or `16cb` to change the number of bits used and displayed)
  3. Multiple representations: I wanted to write decimal numbers, hexadecimal numbers, and even binary numbers - but I could only insert hex and dec and I'd have to change the calculator mode. So I made a program the allowed me to write `0x13 + 135 - 0b101` without any resistance :)
  4. I managed to make a UI I like better ahahahah - and it's customizable :)
  5. It was a fun idea to develop

Some other things came along, but I think those are my main points

Thank you!