Page 289 of 392

Re: Ask a Question, Get Deep!

Posted: Sun Dec 02, 2012 5:51 am
by Chozon1
Mmm...sometime, I'd like you to sit me on your knee and explain how compilers were created. It's sort of dark magic to me how they were invented, since I can't imagine how to code something when you have no way to translate it into machine language. Are you needing to fabricate one from scratch or sommat?

But yeah, finals. I have three on one day, I believe. I know I have at least two.

Next week is fun times?

Re: Ask a Question, Get Deep!

Posted: Sun Dec 02, 2012 7:50 am
by Deepfreeze32
Heh. Compilers....they are complicated. I'll spoiler a general overview for ya. :P
Spoiler:
So there's a few major portions to a compiler: A scanner/tokenizer, a parser, a type checker, and a code generator.

The scanner/tokenizer essentially takes code and attempts to break it into meaningful chunks (called tokens). For example, a program that was "print("hello "+name);" would be tokenized like so:
token: print
token: (
token: string. value: "hello "
token: +
token: identifier. value: <Whatever we set it to>
token: )
token: ;

This is to simplify parsing, which is where the meaning of the tokens is determined. A parser would grab tokens to make sure that a given expression or statement makes sense. With the above example, it would grab "print", which it knows needs to be followed by an opening parenthesis, followed by a string expression (Not just a string, for reasons that shall be explained later), followed by a closing parenthesis. So if instead of an opening parenthesis, it got a string, it would return an error.

Different parsers do different things with this "output" from the parser. Some (Like the one we're building in class) generate a structure referred to as an Abstract Syntax Tree, or AST. In this tree structure, nodes are different types of token combinations (Example: a + b would be considered a binary expression because it contains an operator which takes two operands, while neg a [convert negative number to positive, and vice versa] is a unary expression as it has an operator which takes one operand). This structure makes the following processes easier.

Type checking uses this generated AST to make sure that the program uses proper types for things (For example: Having a function which returns a boolean value [true/false] return a number like 42 is bad). This is usually done by referencing a "Symbol Table" which is generated during scanning to accommodate for the complexity of interacting variables.

Now that we know that the code actually is valid (According to compiler rules), we have to generate machine code. This can be done in a few ways. Either generate assembly code and assemble it, or directly write the code an assembler would generate. This is where things get super hard. Dealing directly with a CPU is a horribly dangerous operation, and can cause some problems. Incorrectly dealing with the stack or the registers can lead to, as my professor calls it, 'badness'. :P

Once all that is done, you should have an executable file that can now be run on the target system.
As for next week....goodness no. I have two projects due on Thursday. :/

Re: Ask a Question, Get Deep!

Posted: Sun Dec 09, 2012 8:29 pm
by baconisgood23
Do you like chinese food?

Re: Ask a Question, Get Deep!

Posted: Sun Dec 09, 2012 8:49 pm
by Deepfreeze32
Oh, I love it. I eat way too much of it though...curse the little Chinese Shop down the street with their cheap lunch deals. :P

Re: Ask a Question, Get Deep!

Posted: Mon Dec 17, 2012 9:20 am
by Chozon1
Interesting...I do remember reading something about modern CPU's using a buffer of sorts between the programs and the hardware.

Point is, do you feel like you actually need to know how to write a compiler, or just use premade ones?

Mostly just curious. To me, it seems like making paint yourself.

Re: Ask a Question, Get Deep!

Posted: Mon Dec 17, 2012 7:48 pm
by Deepfreeze32
The point of the class is twofold: Learn compiler theory, and gain practical experience with the elements of a compiler.

Theory is a good thing because the theory of compiler design can often let you design programs more efficiently, and theory is a blast. :P

Practical experience lets you see just what is going on with all this theory that you learn. It's a good experience, if not difficult.


The whole point of a compilers course is this: Learning how compilers operate will help you become a better programmer. I've learned enough about how compiler theory can be applied to write a book, and I only took an undergraduate level course in it.


Though for most programmers, simply knowing how to use existing compilers will suffice. As an inquisitive Computer Science student though, I want more than cursory knowledge. :P

Re: Ask a Question, Get Deep!

Posted: Tue Dec 18, 2012 7:55 am
by Chozon1
You give me a headache sometimes. Stop breaking the curve. XD

Trains?

Re: Ask a Question, Get Deep!

Posted: Tue Dec 18, 2012 2:57 pm
by Deepfreeze32
Hey, it's what I do best. :P

I like trains.


Re: Ask a Question, Get Deep!

Posted: Sun Jan 06, 2013 7:28 am
by Orodrist


?

I can't decide if that's a boy band pretending to be metal or a really good song.

Re: Ask a Question, Get Deep!

Posted: Sun Jan 06, 2013 9:18 am
by Chozon1
August Burns Red?

Re: Ask a Question, Get Deep!

Posted: Tue Jan 08, 2013 6:30 am
by Deepfreeze32
Orodrist wrote:I can't decide if that's a boy band pretending to be metal or a really good song.
That was really good. It seems like some of the lighter metal as far as Progressive Acts go, but I don't think that's a bad thing.
Chozon1 wrote:August Burns Red?
I hate to say it, but I've not actually listened to them. I know the story behind their name though, and it's kinda sad. :/

Re: Ask a Question, Get Deep!

Posted: Wed Jan 09, 2013 12:52 am
by Orodrist


?

Re: Ask a Question, Get Deep!

Posted: Wed Jan 09, 2013 2:08 am
by Deepfreeze32
That's got a nice riff to it. I like it. Only have one song by The 69 Eyes from a sampler collection, and I like it.

Re: Ask a Question, Get Deep!

Posted: Wed Jan 09, 2013 2:13 am
by Orodrist


?

Who's idea was that?

Re: Ask a Question, Get Deep!

Posted: Wed Jan 09, 2013 2:46 pm
by Deepfreeze32
That was a pretty decent cover. I think I like the original better, but it's Soundgarden. :P

I am a little confused as to why he chose to cover a Soundgarden song (Let alone that one) though...