Sign in to follow this  

my programming language

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

If you intended to correct an error in the post then please contact us.

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)

1 2 3 9 ADD ADD ADD
1 2 12 ADD ADD
1 14 ADD

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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'Caml
let rec mcCarthy n =
if n > 100
then n - 10
else mcCarthy (mcCarthy (n + 11))

// C language
int
McCarthy(int n) {
if (n > 100) {
return n - 10;
}
return McCarthy(McCarthy(n + 11));
}

// C++ metaprogramming
template<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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by andrew1123
I'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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this