I tried to read the Tiger Book with examples. I tried to learn Bison. I tried to learn Lemon Parser. I could not write the grammar for a for-loop. I don't know if that's because if stupid, if it wasn't well explained or if it's difficult.
What I could learn from was to take the instruction sheet for MIPS assembly and find out how statements in C can translate to assembly. That was easy to learn. What a real compiler will generate is always 5 times more than what the instruction manual says it should translate to. I tried with GCC and a MIPS compiler, looked at the generated assembly which was very different from what I could run directly from e.g. the MARS MIPS environment by writing it by hand. I'm out on deep water but this was my experience with trying to learn. I found that TCC is very good for learning and trying ideas. /Niklas Den tors 27 jan. 2022 20:50 <[email protected]> skrev: > 26 Ιαν 2022, 22:55 Από [email protected]: > > > I'm not an expert C programmer. I could find my way, read and learn from > the TCC source code. It reminded me of reading the source of SASH (the > stand-alone shell) which is readable compared to DASH for example. > > > > 2. What I would do to learn more but it's not guaranteed to work > > > > a) I would try and learn how statements (in C) translate to assembly for > a target platform. Maybe start with ARM or MIPS that is supposed to be > easier than x86 asm. > > > > b) I would try and write a disassembler because I heard it's a good > exercise. > > > > My experience is that compilers or how to write an interpreter is not a > learn-by-doing ability. I would need to read and practice a lot before > trying to do it. > > > > /Niklas > > > > Thanks you! Yeah, trying to test things yourself is a way to learn but > apart from been very very hard, inappropriate and annoying to do, this is > another way. You see, let's say that you want to see how a statement > translates to assembly from C ok? Now, let's say that you use GCC for that > (which produces more bloated code than TCC hence why I picked it for the > example) to see how it translates C code to assembly. Now the problem with > this is that, why should we take the way it does it as "the right way?" > Maybe the way GCC does it is not the best possible way or maybe there are > better practices that have been found through the years. So I think I will > ultimately waste my time and challenge my patience doing it this way. >
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
