Page 4 of 4 First ... 234
  • Jump to page:
    #46
  1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    408
    Originally Posted by Lux Perpetua
    That's not necessary.
    Good to know then
  2. #47
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2002
    Posts
    596
    Rep Power
    24
    Here's a very interesting article about writing your own simple PL - http://www.dedasys.com/articles/hecl...mentation.html - the guy describes writing a small scripting language to run on java enabled phones. Very good intro to the issues.

    Link found on the excellent PL site LtU
    Last edited by jamieB; April 28th, 2006 at 09:15 AM.
  4. #48
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    408
    Originally Posted by jamieB
    Here's a very interesting article about writing your own simple PL - http://www.dedasys.com/articles/hecl...mentation.html - the guy describes writing a small scripting language to run on java enabled phones. Very good intro to the issues.

    Link found on the excellent PL site LtU
    Interesting.. .but what's funny is... His site text roll's out of its home in firefox but.. nice..
  6. #49
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2002
    Posts
    596
    Rep Power
    24
    Originally Posted by xlordt
    Interesting.. .but what's funny is... His site text roll's out of its home in firefox but.. nice..
    I often find that the geekier the site, the lower the interest in design "I need to make my site look nice? OK, as soon as I finish writing this compiler..."
  8. #50
  9. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    408
    Originally Posted by jamieB
    I often find that the geekier the site, the lower the interest in design "I need to make my site look nice? OK, as soon as I finish writing this compiler..."
    hmm well... that can be true.. no one is perfect
  10. #51
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    2
    Rep Power
    0

    Lightbulb The real way


    Here is the real way to make a programming language: C/C++.

    I have provided the code for you to use:

    //--------------------------------------------
    // YOUR PROGRAMMING LANGUAGE
    // by: YOU!
    //--------------------------------------------
    #include <vector>
    #include <stdio.h>
    #include <iostream>
    #include <conio.h>
    using namespace std;
    typedef std::vector<int> mem_t;
    mem_t program;
    mem_t memory;
    mem_t::iterator mem_pos;
    mem_t::iterator prog_pos;

    int register_val;
    bool has_register_val = false;

    void quit( bool error )
    {
    if( error )
    {
    printf( "\nERROR!\n" );
    exit(1);
    }

    printf( "\nDone.\n" );
    exit(0);
    }

    bool exec( int instruction )
    {
    // printf( "EXEC: %d\n", instruction );

    switch( instruction )
    {
    // instructions for command 0
    case 0:
    char chr;

    // instructions for command 1
    case 1:
    int num;

    // bad stuff
    default:
    quit( false );
    };

    prog_pos++;

    return true;
    }


    int main( int argc, char** argv )
    {
    if( argc < 2 )
    {
    printf( "Usage: %s program.toast\n\n", argv[0] );
    exit( 1 );
    }

    FILE* f = fopen( argv[1], "rb" );

    if( f == NULL )
    {
    printf( "Cannot open source file [%s].\n", argv[1] );
    exit( 1 );
    }

    char buf[3];
    memset( buf, 0, 3 );
    int pos = 0;

    while( !feof(f) )
    {
    int found = 0;
    buf[2] = fgetc( f );

    if( found = !strncmp( "<command here>", buf, <number of characters in command here> ) )
    program.push_back( 0 );
    else if( found = !strncmp( "<command here>", buf, <number of characters in command here> ) )
    program.push_back( 1 );

    if( found )
    {
    memset( buf, 0, 3 );
    }
    else
    {
    buf[0] = buf[1];
    buf[1] = buf[2];
    buf[2] = 0;
    }
    }

    fclose( f );

    printf( "Welcome to my language!\n\nExecuting [%s]...\n\n", argv[1] );

    // init main memory.
    memory.push_back( 0 );
    mem_pos = memory.begin();

    prog_pos = program.begin();
    while( prog_pos != program.end() )
    if( !exec( *prog_pos ) )
    break;

    quit( false );
    return 0;
    }

    ---end of code, do not compile this line or anything past it---
    <command here> - replace this with the command, do not remove the quotes

    <number of characters in command here> - replace with number of characters in that command

    Let's say we want a 3 command programming language called SSS (Simply Stupid Syntax). The three commands would be, s1, s2, and s3. s1 would print Hello, s2 would print World, and s3 would print !. The code would be...

    //--------------------------------------------
    // SSS PROGRAMMING LANGUAGE
    // by: Cplusdev
    //--------------------------------------------
    #include <vector>
    #include <stdio.h>
    #include <iostream>
    #include <conio.h>
    using namespace std;
    typedef std::vector<int> mem_t;
    mem_t program;
    mem_t memory;
    mem_t::iterator mem_pos;
    mem_t::iterator prog_pos;

    int register_val;
    bool has_register_val = false;

    void quit( bool error )
    {
    if( error )
    {
    printf( "\nERROR!\n" );
    exit(1);
    }

    printf( "\nDone.\n" );
    exit(0);
    }

    bool exec( int instruction )
    {
    // printf( "EXEC: %d\n", instruction );

    switch( instruction )
    {
    // s1
    case 0:
    cout << "Hello ";

    // s2
    case 1:
    cout << "World";

    // s3
    case 2:
    cout << "!";

    // bad stuff
    default:
    quit( false );
    };

    prog_pos++;

    return true;
    }


    int main( int argc, char** argv )
    {
    if( argc < 2 )
    {
    printf( "Usage: %s program.toast\n\n", argv[0] );
    exit( 1 );
    }

    FILE* f = fopen( argv[1], "rb" );

    if( f == NULL )
    {
    printf( "Cannot open source file [%s].\n", argv[1] );
    exit( 1 );
    }

    char buf[3];
    memset( buf, 0, 3 );
    int pos = 0;

    while( !feof(f) )
    {
    int found = 0;
    buf[2] = fgetc( f );

    if( found = !strncmp( "s1", buf, 2 ) )
    program.push_back( 0 );
    else if( found = !strncmp( "s2", buf, 2 ) )
    program.push_back( 1 );
    else if( found = !strncmp( "s3", buf, 2 ) )
    program.push_back( 2 );

    if( found )
    {
    memset( buf, 0, 3 );
    }
    else
    {
    buf[0] = buf[1];
    buf[1] = buf[2];
    buf[2] = 0;
    }
    }

    fclose( f );

    printf( "Welcome to SSS!\n\nExecuting [%s]...\n\n", argv[1] );

    // init main memory.
    memory.push_back( 0 );
    mem_pos = memory.begin();

    prog_pos = program.begin();
    while( prog_pos != program.end() )
    if( !exec( *prog_pos ) )
    break;

    quit( false );
    return 0;
    }

    ---end of code---

    Well, how about that! Now create a new text document and type:

    s1 s2 s3

    Save it and drag and drop it on the SSS executable. CONGRATS! It prints "Hello World!" and quits. Can't tell what it says because it closes too fast? insert getch(); after cout << "!"; and the program will pause. See it now? KUDOS to You!
    Last edited by cplusdev; May 24th, 2006 at 05:54 PM. Reason: oh, no reason...
  12. #52
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    70
    Not to knock your accomplishment or initiative but is I really a programming language if everything is hard coded and nothing can be expressed using it?

    It seems that you read a file, which may as well be called a config and using that to direct your program .

    I guess it comes down to what is a language but in any case nice one .

    Mark.
    programming language development: www.netytan.com Hula

  14. #53
  15. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    408
    Originally Posted by netytan
    Not to knock your accomplishment or initiative but is I really a programming language if everything is hard coded and nothing can be expressed using it?

    It seems that you read a file, which may as well be called a config and using that to direct your program .

    I guess it comes down to what is a language but in any case nice one .

    Mark.
    Although, anything is possiable hehe
  16. #54
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Talking I know a simple way to make a "language"


    there's a very simple way to make a text based.. er.. thingy.
    i made the language in BASIC, which shows how easy it is.
    here's how i made it:
    create a basic interface with at least a text editor and a run button or menu item.
    then, make the "interpreter" read the first line, then do something with the next line. i know that sounds kinda weird, here's an example of what i mean written in one of my own languages, RScript:
    output=.. <<<tells the compiler to read the next line then print it
    hello world <<<text to print
    so basically, here's how i did itliberty BASIC)
    [run]
    open "Program name" for text as #a
    print #main.texteditor, "!line 1 line1$"
    print #main.texteditor, "!line 2 line2$"
    if line1$ = "output=.." then print #a, line2$
    There are (or course!) several flaws with this method:
    to make a "good" language, you need to spend AGES programming all the different commands and lines
    the amount of lines you can use in a program written in your language are limited
    still, you get a great deal of satisfaction out of it!

    Comments on this post

    • Schol-R-LEA disagrees : Aiieeee, zombie thread! Zombie thread!!!!
  18. #55
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2002
    Posts
    596
    Rep Power
    24
    Originally Posted by crazyguy66
    still, you get a great deal of satisfaction out of it!
    Maybe you should get out more often. Or read more books.
  20. #56
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Angry


    Originally Posted by jamieB
    Maybe you should get out more often. Or read more books.
    What?! So you think that i'm a sad, geeky nerd with no life.
    Fine. But what else would I feel after something like that? Anger? Despair? Depressed?
    Noob!!
  22. #57
  23. No Profile Picture
    rebel with a cause
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2004
    Location
    The Batsh!t Crazy State.
    Posts
    5,817
    Rep Power
    3462
    Hey if you losers wanna screw around go to the outhouse. Leave the serious forums for serious things.
    Dear God. What is it like in your funny little brains? It must be so boring.
  24. #58
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Well heres anyother way to make a programming


    Well, another way to do it is to make a bunch of libraries and name them the lines that you want to add to the syntax in your programming language. Also, add the functions to the libraries. Make its so that when you press execute, it will load the function that is types into the text area. It may sound simple, but it is hard work. A million lines I say.
  26. #59
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0
    Well I am making a simple interpretor in vb.net and am most likely going to do it in less then 200 lines mabey less than 150. Although for a compiler you need to know machine code and that may add a few steps.
Page 4 of 4 First ... 234
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo