Jump to content

How exactly do you write a computer language?


Baby Astronaut
 Share

Recommended Posts

Do you have to create a mathematical base for it separately?

 

Or is that handled by machine code? And is machine code a type of "pre-language" that enables a computer to interact with ("understand") a higher level language?

 

In other words, does each new language have to teach a computer about general math and how to perform every type of basic calculation, or does the language assume the computer is outfitted with such capabilities, and the language only specifies in what order to perform calculations and how to react when text or any other kinds of input occur?

 

Also, is there a variety of machine code languages, the way there is a huge variety of higher level languages? And finally, if there's only a single or very few number of machine code languages, is it optimal, can it be improved or revamped to be more efficient?

Link to comment
Share on other sites

machine code comes down to specific instructions to a processor given in binary, but I believe it sufficient to write your compiler to turn whatever language into something like a lower level language like Assembly (which is already in great shape to be interpreted directly by a machine). For example, python is compiled directly into C code.

 

A language can be designed with a specific mathematical theory behind it, which can ease (or complicate) implementation or design. For example, OCaml is a functional programming language that's based on lambda calculus

Link to comment
Share on other sites

machine code comes down to specific instructions to a processor given in binary, but I believe it sufficient to write your compiler to turn whatever language into something like a lower level language like Assembly (which is already in great shape to be interpreted directly by a machine). For example, python is compiled directly into C code.

No, Python isn't compiled into C. There's a C program that reads Python source files and directly interprets them.

 

There is also PyPy, which is a Python interpreter written in Python.

 

There are entire books on how to create computer programming languages. It's a very difficult subject. The famous Structure and Interpretation of Computer Programs teaches programming while having you build an interpreter for Scheme, for example.

Link to comment
Share on other sites

Hi Baby Astronaut :)

 

Basically, We already have one defined computer language that is wired in processor, namely Assembler. Assembler has enough commands to program just anything we can imagine.

 

When we want to program a new computer language, firstly we have to define it in our mind (on paper). Once we know how our new language behaves, the rest is easy: we just have to translate that behaviour to assembler, maybe even indirectly by using higher order language like c, or whatever. We just have to shape up assembler (c, ...) commands to do the stuff we have imagined. That easy.

 

Right now two basic paradigms of programming language behaviour people managed to shape up:

  • imperative - line by line executing of commands of mostly copying or modifying and copying one memory cell to another. Examples are c, Java and all major stuff used in classic business world. The great thing happen here is object oriented approach, a real cutie, if U ask me.
  • functional - something like ms excel, change one variable, all related variables change accordingly automaticly. Examples are Haskell and other adventureous crew. Relatively new stuff, they are fighting through heavily rooted imperative paradigm.

I can't wait for something new to pop up. There are also some aspects of technical realization like choosing interpreter/compiler behaviour, but these are just finesses. The major thing is to manage to come up with something new on the paper, other is peace of cake, as we use already invented technologies to describe what we imagined.

Link to comment
Share on other sites

I think ecoli and ivanv have given you answers in the correct vein. I think you're looking for a compiler, which is software that converts commands that are in a computer programming language (that's easy for us to understand) into machine code (that's easy for the microprocessor to understand).

 

Machine code is the the actual language of a microprocessor, which works in binary. I have programmed in machine code, and it is very tedious (like micromanaging how a person completes a task). Think of it this way — instead of, say, commanding someone to go into the kitchen and make a peanut butter and jelly sandwich, the machine code would command every muscle and neuron of the person's body to perform in a precise and synchronized manner to produce the same act.

 

So, when a computer programming language (ie, C++, VB, etc) commands that A=20, the computer needs a compiler to translate this command into the processor's machine language to dedicate a memory location, make an entry into what I think is called the "memory allocation table" that associates the name "A" (which is written in binary in the table) with this memory location address (also in binary), and storing the binary value of 20 (ie, 10100) in this memory location. Same thing when you command A=A+1; the processor's machine code must look up "A" in the table, retrieve the associated memory location address from the table, retrieve the value from this address in memory, store it in the computer's working space so the computer can work on it, increment the value by 1, and then store this value back into the memory location (thus writing over the previous value of A).

 

So, I think the answer you're looking for is that you need a compiler.

Link to comment
Share on other sites

@ivanv

We already have one defined computer language that is wired in processor

Assembler is not "defined" and wired into the processor. That would be something like microcode. Most modern processors don't have reprogrammable microcode architectures.

Edited by Ben Bowen
Link to comment
Share on other sites

@ivanv

 

Assembler is not "defined" and wired into the processor. That would be something like microcode. Most modern processors don't have reprogrammable microcode architectures.

 

microcode being the sets of logic gates that cluster in massive arrays?

 

Im not sure if you can make assembly any quicker, as ewmon mentions your taking a step by step procedure to the very extreme, theres no cutting corners here(as there is with higher level algorithms); HOWEVER on the microprocessing side of it (computer architecture) you can create more efficient logic circuits, its not totally defined by the amount the amount of transistors. There isnt different forms of machine code, but machine code will differ from architecture to architecture (which is why lots of older programs arent compatible with say x64 architecture.

 

This is the type of thing your CPU or more specifically ALU's will be using: http://www.cise.ufl.edu/~mssz/CompOrg/CDA-arith.html

 

Now im not too sure about compilers persay but i am aware lots of higher level languages are built from each other and generally starting from C (which has lots of lower level programming functionality such as pointers and memory addressing), for example im studying SCALA for distributed and concurrent systems and its built largely from java which allows similar functionality and similarly java was created from C (i think? java isnt compiled its interpreted by the JVM which makes it cross platform, but i *think* the JVM's built from C).

YOU can create your own language if your so wish and not from the bottom up, you must conceptualise what exactly you want and then hard code it from i would recommend C

 

A string is a simple example, in C string dont exist, they are an array of chars, therefor when you interpret (or compile) the new language you can let the user declare a string and when you compile it, it simply becomes an array of strings, and down and down until its a set of ascii binaries.

 

Hope this helped :D

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.