• 13
• 18
• 19
• 27
• 10

my programming language

This topic is 3815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm making a programming language (untitled so far). I already have the basic idea of what the syntax will be like (at least for the code segment). Here's an example line of code (Fahrenheit to Celsius formula):
F 32 SUB 5 9 DIV MUL
Here's how it works: The code segment of the language is just values (variables, constants, integers, etc.) and functions (or operands depending on how you look at it) separated by whitespace (could be one space, twenty tabs, a thousand line breaks, etc.) The first function is found, and ran. A function has access to all preceding values. After the function has run, the values used by the function and the function call are replaced by the function's output values (yes, can be more than one). The next function is found, and ran. The next function is found, and ran... This is repeated until there are no more functions. For example, back to the Fahrenheit to Celsius formula:
F 32 SUB 5 9 DIV MUL
Here's how this code would run:
212 32 SUB 5 9 DIV MUL          (the actual code)

180 5 9 DIV MUL                       (212 - 32 = 180)
180 0.55555555 MUL                    (5 / 9 = 0.55555555...)

100                             (return)
Another example:
1 2 3 4 5 ADD ADD ADD ADD      (the actual code)

15                              (return)
So do you think that I'm on to something here? I kind of consider this reinventing the programming language (Actually I believe that there was a similar language). I'm going to build a small program that inputs from the user a code segment with the five basic math operators (don't forget mod) and then outputs the leftover values.

Share on other sites
RPN

Looks like an RPN stack machine. I think they used this on HP-48 calculators. They are pretty fun to make simple programs out of, but if you want to do anything fairly complex they become really hard to read.

Share on other sites
Yeah, you're right, that is alot like that, if not exactly like that.

You were saying that it'd be hard to read for complicated programs. That would be true if and entire program was all on one line of code (which it could be). But if there's line breaks, tabs, and comments in between parts of the code then it might not be too complicated.

I was looking on Wikipedia and found the language Forth, and it looks ALOT like this. Also, I had an idea one time for an IDE/compiler that uses color for different syntax, and I saw a link on Wikipedia to something called colorForth, and it turns out to be the same thing! I guess I stole both of Chuck Moore's ideas without realizing it!

Share on other sites
One of the elementary tests to determine the expressiveness of a language is to implement the McCarthy 91 function in that language. Below are three examples in increasing order of complexity

// O'Camllet rec mcCarthy n =  if n > 100   then n - 10  else mcCarthy (mcCarthy (n + 11))// C languageint McCarthy(int n) {  if (n > 100) {    return n - 10;  }  return McCarthy(McCarthy(n + 11));}// C++ metaprogrammingtemplate<int t>struct rec {};template<int n>struct term{  enum { t = (n > 100) ? 0 : 1 };};template<int n>struct mcCarthy{  typedef typename rec<term<n>::t>::template get<n> get;  enum { val = get::val };};template<>struct rec<0>{  template<int n>  struct get  {    enum { val = n - 10 };  };};template<>struct rec<1>{  template<int n>  struct get  {    enum { val = mcCarthy<mcCarthy<n + 11>::val>::val };  };};

What's it like, in yours?

Share on other sites
I'm not sure how my language is going to define functions yet. It might be someting like:

MCCARTHY: N STOR N 100 GRE STOR BN 10 SUB B GRTRN 11 ADD MCCARTHY MCCARTHY B LESS

Share on other sites
If you like designing languages (not necessarily with the purpose of usefullness), then Esolangs may just be something for you.

Your concept has been done a lot of times there already, a stack makes it very convenient to use just that notation.

Share on other sites
To me it looks like you are slowly re-inventing FORTH.

Share on other sites
Quote:
 Original post by andrew1123I'm not sure how my language is going to define functions yet.

You might want to look at how it's done in Postscript (a way of describing printer data, but it's actually a complete language) or Forth.