How to make your own Programming language ?

???

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 28027 Views - Last Post: 12 August 2010 - 11:03 AM

#1 Rickster0  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 236
  • Joined: 08-July 08

How to make your own Programming language ?

Posted 12 November 2008 - 09:18 AM

how can i make my own programming language...

i want to make my own for one of my projects can anybody give me a hand
Is This A Good Question/Topic? 0
  • +

Replies To: How to make your own Programming language ?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to make your own Programming language ?

Posted 12 November 2008 - 09:47 AM

Given your current level of understanding of programming, OOP concepts and such (not trying to be rude or anything I swear, I just making this observation from your questions in the VB.NET forum) I would say taking on a project like this is well above your head. Creating a language is no simple task, it takes a team years to develop and debug a language
Was This Post Helpful? 0
  • +
  • -

#3 Rickster0  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 236
  • Joined: 08-July 08

Re: How to make your own Programming language ?

Posted 12 November 2008 - 09:53 AM

oh ok...also no offense is taken since i know im not great at proggramming so no worries.. and ok.. i just wanted to know how to do it thats all..
Was This Post Helpful? 0
  • +
  • -

#4 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: How to make your own Programming language ?

Posted 12 November 2008 - 10:53 AM

Start off with some reading: Programming Language Processors in Java - Compilers and Interpreters (Watt & Brown)

But, be aware! Building a complete langue is hard and there are university courses about them, still not covering all aspects.
Was This Post Helpful? 0
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: How to make your own Programming language ?

Posted 12 November 2008 - 01:48 PM

As Psycho said, no offense, but it's really above you. HOWEVER. [read on]

You could make your own interpreted language. That's not difficult. It's basically just reading in a file, and either:
1) Outputting the "translated" code to a language which you DO know
2) Running it directly through your interpreter. No secondary code.

Here's an example~ I wrote my own Brainfuck interpreter the other day.
[click for blog entry]

Note, this is a really simple interpreter. Brainfuck only has 8 commands.
/*
 * A brainfuck interpreter
 * Author: Danny Battison
 * Contact: gabehabe@gmail.com
 */

#include <iostream>
#include <fstream>
using namespace std;

void DisplayHelp();

int main(int argc, char *argv[]) {
    if (argc < 2 || argc > 3) {
        DisplayHelp();
        return EXIT_FAILURE;
    }
    if (!strcmp(argv[1], "-?")) {
            cout << "BRAINFUCK INTERPRETER: WRITTEN BY DANNY BATTISON" << endl
                 << "This program is designed to interpret a brainfuck application." << endl
                 << "Written in C++" << endl
                 << "Contact the author: gabehabe (at) gmail (dot) com";
    }

    else if (!strcmp(argv[1],"-i")) {
            if (argc < 2 || argc > 3) {
                DisplayHelp();
                return EXIT_FAILURE;
            } else {
                ifstream file;
                file.open(argv[2]);
                if (!file.is_open()) {
                    cout << "ERROR: File could not be found.";
                    return EXIT_FAILURE;
                }
                string bf = "";
                char buffer;
                file.get(buffer);
                bf += buffer;
                while (!file.eof()) {file.get(buffer); bf += buffer;}
                file.close();
                char* ptr = new char[5000];
                int sub;
                for (sub = 0; sub < 5000; sub++) ptr[sub] = 0;
                sub = 0;

                unsigned int i;
                int loopPosition = -1;
                for (i = 0; i < bf.length(); i++) {
                    switch (bf[i]) {
                        case '+': ptr[sub]++; break;
                        case '-': ptr[sub]--; break;
                        case '>': sub++; break;
                        case '<': sub--; break;
                        case '.': cout << ptr[sub]; break;
                        case ',': ptr[sub] = getchar(); if (ptr[sub] == 13) {ptr[sub] = '\0'; loopPosition = -1;} break;
                        case '[': loopPosition = i; break;
                        case ']': if (loopPosition != -1) {if (ptr[sub] != '\0') i = loopPosition-1; else loopPosition = -1;} break;
                    }
                }
            }
            return EXIT_SUCCESS;
    }
}

void DisplayHelp() {
    cout << "Invalid arguments. Example Usages:" << endl
             << "\tInterpret:\tbf.exe -i C:\\file.bf" << endl
             << "\tabout:\t\tbf.exe -?";
}


Other than that, I'd say avoid trying to make your own compiled language. I'm getting books on it soon, I'll most likely be blogging about it. Keep an eye out, I try to write stuff in layman's terms.
Was This Post Helpful? 3
  • +
  • -

#6 muballitmitte  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 174
  • View blog
  • Posts: 470
  • Joined: 05-November 08

Re: How to make your own Programming language ?

Posted 13 November 2008 - 12:53 AM

and how is what you wrote helping him? *confused*
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5165
  • View blog
  • Posts: 26,841
  • Joined: 10-May 07

Re: How to make your own Programming language ?

Posted 13 November 2008 - 12:55 AM

HAHAHAHA, in your face Gabe!

Hey, does anyone else smell toast?
Was This Post Helpful? 0
  • +
  • -

#8 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: How to make your own Programming language ?

Posted 13 November 2008 - 06:30 AM

Because it's an example to show him how an interpreter works.

And I don't smell toast. Though I could earlier. Around the same time that you posted that.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5165
  • View blog
  • Posts: 26,841
  • Joined: 10-May 07

Re: How to make your own Programming language ?

Posted 13 November 2008 - 07:30 AM

Attached Image
Was This Post Helpful? 0
  • +
  • -

#10 muballitmitte  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 174
  • View blog
  • Posts: 470
  • Joined: 05-November 08

Re: How to make your own Programming language ?

Posted 13 November 2008 - 07:35 AM

hahahahaahahahahaha
Was This Post Helpful? 0
  • +
  • -

#11 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: How to make your own Programming language ?

Posted 13 November 2008 - 08:21 AM

No2 you have made my day. :) Burnt toast gabe!
Was This Post Helpful? 0
  • +
  • -

#12 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: How to make your own Programming language ?

Posted 13 November 2008 - 02:07 PM

It's funnier because you can still see where you didn't crop the corners properly. :lol:

Future reference: gabehabe~ All lower case. See, this is why I don't call any more.

EDIT: also looks like someone went a little crazy with the clone tool in PS. no2, did you do that, or was it that shoddy when you found it? :lol:
Was This Post Helpful? 0
  • +
  • -

#13 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: How to make your own Programming language ?

Posted 13 November 2008 - 02:16 PM

Very useful topic about compilers here!
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5165
  • View blog
  • Posts: 26,841
  • Joined: 10-May 07

Re: How to make your own Programming language ?

Posted 13 November 2008 - 02:19 PM

View Postgabehabe, on 13 Nov, 2008 - 03:07 PM, said:

It's funnier because you can still see where you didn't crop the corners properly

EDIT: also looks like someone went a little crazy with the clone tool in PS. no2, did you do that, or was it that shoddy when you found it? :lol:

M$Paint ftw. I just did a Google Images search. :P
Was This Post Helpful? 0
  • +
  • -

#15 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: How to make your own Programming language ?

Posted 14 November 2008 - 05:57 AM

View PostHary, on 13 Nov, 2008 - 08:16 PM, said:

Very useful topic about compilers here!

Toast compiles my code, so I don't have to.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2