March 10th, 2006, 12:22 PM
-
Originally Posted by Lux Perpetua
That's not necessary.
Good to know then
April 28th, 2006, 09:13 AM
-
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.
April 28th, 2006, 09:26 AM
-
Originally Posted by jamieB
Interesting.. .but what's funny is... His site text roll's out of its home in firefox
but.. nice..
April 28th, 2006, 09:48 AM
-
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..."
April 28th, 2006, 09:49 AM
-
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
-
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...
-
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.
-
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
September 1st, 2008, 01:47 PM
-
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 it
liberty 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
September 1st, 2008, 07:33 PM
-
Originally Posted by crazyguy66
Maybe you should get out more often. Or read more books.
September 4th, 2008, 11:35 AM
-
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!!
September 4th, 2008, 02:20 PM
-
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.
July 26th, 2009, 12:27 PM
-
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.
August 30th, 2009, 12:39 PM
-
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.