r/AskComputerScience • • Jul 11 '16

How do you program a programming language?

I.e. How do you get a computer to understand a language? How does it actually make the transition from that language into assembly language?

45 Upvotes

18 comments sorted by

View all comments

Show parent comments

1

u/lepriccon22 Jul 11 '16

What does that mean practically? How do I teach a computer to understand what naming a variable is? How do I teach it to understand what a for loop is, etc?

5

u/anamorphism Jul 11 '16 edited Jul 11 '16

you're not teaching the computer anything.

you're basically just writing a translation program.

you would write a program that takes in for (int i = 0; i < 10; ++i); and outputs assembly to represent what you want that line of code to do.

something like

  • allocate 32 bits of memory for i

  • write 0 to all of those bits

  • allocate 32 bits for 10

  • write 10 to those bits

  • declare label 1

  • compare i to 10

  • jump to label 2 if i is less than 10

  • add 1 to i

  • jump to label 1

  • declare label 2

6

u/[deleted] Jul 12 '16 edited Jun 18 '23

[removed] — view removed comment

2

u/anamorphism Jul 12 '16

sure, but you don't try and teach someone who doesn't know algebra multivariable calculus.