How 2 make a language?

mankxman

Solid State Member
Messages
8
Hey. i really wanna know how to make ur own programming langauge. and i would also like 2 know how to make ur own file types? :confused: any help would be much appreciated! :D
 
Im not sure but that is probably very very difficult, im sorry to say this and I will probably get a bad rep. point for it but...... google it.....I would but I'm at school and cant be bothered...soz
 
Well first you should learn an actual programming language so you know how they work and then ask around programming communities for some help it will probably be to difficult and if it's not serious I wouldn't bother wasting my time.
 
easier to make a proghramming language

1) study other languages (to get an idea of what to make)
2) design the language
3) make interpretor or compiler
4) discover that existing languages are better than yours
5) get depressed
6) visit pub
7) get drunk
8) remove pants
9) ???
10) Profit!!
 
Tulsileaf said:
easier to make a proghramming language

1) study other languages (to get an idea of what to make)
2) design the language
3) make interpretor or compiler
4) discover that existing languages are better than yours
5) get depressed
6) visit pub
7) get drunk
8) remove pants
9) ???
10) Profit!!

Sadly, Tulsileaf probably isn't joking.

You need to be pretty hardcore to make your own language.
 
how do you mean you want to write a programming language? do you mean interperator
for languages like PHP or perl
or a compilable language like visual basic, or C...

the former is definitly easier.

In fact I'll have a go at making one (interperated/scripting language) to get you started...
 
ok...

heres a simple script interperator, (you'll have to use your imagination though!!)

the script is run from the command line, in the form script.exe [script file]

there are three code files (at the minute) because I've only coded two very smple function, "add" and "writeword", there is currently no other function and no support for variables...
(I'll add some more functions later).

everyone should feel free to add to this language, it's a first come first server affair,
so if someone wants to write a function with a stupid name, or indeed a stupid function. respect the fact that they did that, and don't go changng other peoples functions name or functions function...

It's currently written in C and is compilable on both windows Linux and Mac, (a truly portable scripting language?)...

feel free to write OS specific functions, but don't to also write the code to make it so that it'll still compile (albeit ignoring your functins) on another OS...


heres the code so far....



script.c
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include "functionslist.h"



int main(int argc, char *argv[])
{
	int x;
	
	float a,b,c; /*declare some random variables incase they are needed later*/
	char inpath[50], task[50], arg[100];
	FILE *input;
	for (x=0; x<argc; x++)
	{
		if (x>1)
		{
			printf("you can only run one script at a time");
			exit(1);
		}
	}
	if (x==1)
	{
		printf("Usage is scrip.exe [scriptname]");
		exit(1);
	}
	if (strlen(argv[1])>=50)
	{
		printf("script names are limited to 50 chars");
		exit(1);
	}
	input = fopen(argv[1],"r");
	if (input==NULL)
	{
		printf("Error 1 - could not find input file - %s\n\n\r",inpath);
		exit(1);
	}
	/*here we decide what functions we'll be allowing, and the permissible arguments for each function
	for this example the functions that I have decided to allow are

	add some numbers (because it's simple)

	*/
	while (x=fscanf(input,"%s",&task)!=EOF) /*scan for task*/
	{
		if(strcmp(task,addfunction)==NULL)
		{
			fscanf(input,"%f,%f",&a,&b);
			c = addfunc(a,b);
			printf("%f\r\n",c);
		}
		if(strcmp(task,printwordfunction)==NULL)
		{
			fscanf(input,"%s",&arg); /*not all scripting functions will need a seperate function, echo to the screen is a good example of this*/
			printf("%s\r\n",arg);
		}
	}
}

functionslist.h
Code:
/*list functions here*/
float addfunc(float, float);

/*declare functions that will be available
these are global variables, just because it 
was easier and cleaner to do it like this*/

char *addfunction = "add"; 
char *printwordfunction = "writeword";
char *printstringfunction = "writestring"; //not included this but you get the picture right
[code]

and lastly the function specific file
addfunc.c
[code]
float addfunc(float a, float b)
{
	float result;
	result = a + b;
	return(result);
}

I've tried to structure the programming so tat new functions can be added without bloating the software.

For some users they may have to add lines to include the addfunc.c file at the start of the functionslist.h file... the IE I used was VS.NET and having these three files added to the solution meant that the addfunc.c file was added automatically...

so like I say, if anyone is intersted, please feel free to extend this language.


---edit--
just for completion... the script I used was called hello.txt and looked like this

add 1,20
writeword hello
 
boz4life said:
why dont you make your own os just need to know c++ and asm.

OK lets think. For one person with no programming language experience that would take more than 15 years to make a os and I don't think he wants to do 15 years of learning the ins and outs of os and programming languages just for something to do.
 
Back
Top Bottom