Page 1 of 1

How to make a programing language....

Posted: Sun Aug 05, 2007 3:07 pm
by Sinuvoid
Thats my queston...(Title)

Posted: Sun Aug 05, 2007 4:32 pm
by MystikShadows
The answer to this question varies alot based on the type of programming language you want to make. Some of the decisive factors (questions to answer) are:

1. Do you want to make an interpreter or a compiler.

2. What kind of language is it? As in is it more C like, more pascal like, more BASIC like, closer to assembly language mnemonics.

3. What platform do you want this language to compile for (the typical target platforms is Intel, Mac with DOS, Windows Linux or Mac OS/X or all of them.

Once you can answer these questions then we can elaborate the answers alot more.

I wouldn't quite go with the flow either. If you see most compilers written in C, I would just conclude that C is the only language to use. If I was to make a language I would use a language that resembles the new language as much as possible. Not just for the development. but in the end, when you compile that into an exe, you can compare your code with that generated by that compiler see how fast you are and do benchmarks.

So let's start by answer the first 3 questions here and take it from there.

Posted: Sun Aug 05, 2007 4:55 pm
by Stoves
Mystik beat me to it, but here's my less adequate answer...

Decide the purpose of your language: creating images, scanning websites for data, processing and organizing data, etc. Choose what to implement your language in: ASM, C, etc. (even QBasic) Come up with a list of commands and operators: IF, THEN, DECLARE, endline character, =, +, ", etc. Determine what the commands and operators will do: allocate memory, define a datatype, store a variable, concatonate strings, compare values, run a shell command, etc. Create a compiler to interpret the commands and either process and execute the commands or encode the commands into a standalone program that can be run to execute the commands.

While technically speaking you could create a language without a compiler or interpreter, the language would be useless, so I included it as the last step. It could be as simple as creating a qbasic program to open a file that contains the code of the new language, reads the commands, and executes them.

Posted: Mon Aug 06, 2007 6:27 pm
by MystikShadows
You still managed to make some good points in your reply Stoves. I don't believe in inadequate answers, just the fact that you did answer is awesome in itself :-).

What I do believe in is when a variety of answers is answer on questions like this one especially. He can make himself a more complete image if the project he's taking. More complete, more informed decisions, etc. So it's all cool :-)

Posted: Fri Aug 10, 2007 11:44 am
by Sinuvoid
Ok first mystik.
1. dont know what those are....but i think a compiler makes the exe file of the language.
2. More of a BASIC language....but I want to make a language SIMPLER than this for my brother and other people.
3. I want it to be used for i guess what ever QBASIC is used for(WINDOWS)

Now Stoves''....
Purpose:To program other programs (LMAO)
Emplement langauge:QBASIC
The rest of what you asked me i have in my head
but the compiler part dont understand


Now this is what i tried to do:

Code: Select all


'This doesnt work i have tried oh most EVERYTHING i mixed in variables etc...

PRINT = PRINT    'prints something(BASIC command)
START = SHELL "START"  'starts a program(DOS command)
COPY = SHELL "COPY"  'copies a file to another directory(DOS command)
etc
etc
etc

INPUT programstart$  'start writing program with programing language

'this part istn correct but it saves your program to a file
OPEN test1.BAS OUTPUT AS #1
INPUT programstart$
CLOSE #1
so yah......PLEASE REPLY ASAP
Lee

Posted: Fri Aug 10, 2007 12:09 pm
by Stoves
Ah, ok, I think I understand what you're going for now. Before discussing your code, let me make sure I'm on the same page...

So, I take it ideally you'd like someone to be able to open Notepad and type something along the lines of:

Code: Select all

CLEARSCREEN
PRINT "Ball Program" AT 30,30
PAUSE FOR 2 SECONDS
CLEARSCREEN
DRAW CIRCLE SIZE 10 COLOR RED AT 50, 50 NAMED ball
CLEARSCREEN
MOVE ball FROM 10,100 TO 100,100
Then they could save the file and then run a qbasic program (probably compiled as exe) that you would write which would read in that file they just created, create a new .BAS file with the QB equivalent code, and create an exe file that they could run to see their program in action.

The resulting .BAS code converted from the code above that the user wouldn't necessarily see might look like:

Code: Select all

CLS
LOCATE 4, 4
PRINT "Ball Program"
SLEEP 2
CLS
CIRCLE (50, 50), 5, 4
PAINT (50, 50), 4
GET (44, 44) - (56, 56), ball
CLS
y = 100
FOR x = 0 TO 90
  PUT (10 + x, y), ball  
NEXT
Is this kind of what you're talking about?

Posted: Fri Aug 10, 2007 12:15 pm
by Sinuvoid
YES STOVES!!!!!!!!!!YOU'RE A GENIUS!!!!!!!!!

Posted: Fri Aug 10, 2007 12:23 pm
by Stoves
Cool. This sounds like a fun project.

First step will probably be to decide on a list of simplified commands for your new language. Like CLEARSCREEN, DRAW SQUARE, MOVE, etc. Then work out how that simplified code would look in QBasic.

The second step could be to work on the engine that reads in the file containing the simplified code and converts it to QBasic code.

The third step could be to work out how to export the new QBasic code to a .BAS file and compile it. You should even be able to have it automatically run the code after compiling it.

Posted: Fri Aug 10, 2007 12:28 pm
by Sinuvoid
I need help on how to start it...can you help??

Posted: Fri Aug 10, 2007 12:50 pm
by Stoves
Well, here's some blocks of code that should hopefully get you started:

This code reads in a file line by line:

Code: Select all

'Ask for the file.
INPUT "Filename"; filename$

'Get a free file number.
f = FREEFILE
'Open up the file
OPEN filename$ FOR INPUT AS #f
  'Read in the next line of code to process until the end of the file is reached.
  DO UNTIL EOF(1)
    'Read in the next line of code.
    LINE INPUT #f, lineofCode$

    'Do whatever you need to do with the current lineofCode$ here.    

  LOOP
CLOSE #f
Once you read in the line of code, you'll probably find a use for MID$, INSTR, LTRIM$, and RTRIM$ functions to extract the information.

This code exports a line of code to a file:

Code: Select all

exportCode$ = "CLS"
exportFile$ = "newcode.bas"
f = FREEFILE
'APPEND allows us to add a line of information to a file. If the file doesn't exist, QB creates the file.
OPEN exportFile$ FOR APPEND AS #f
  PRINT #f, exportCode$
CLOSE #f

Posted: Fri Aug 10, 2007 1:02 pm
by Sinuvoid
Ok this is getting to complicated already :?
I think ill just go with something easier than this hehe but maybe YOU can make it? It would be a good project for you...

Posted: Mon Aug 13, 2007 2:29 pm
by Quicky
well instead of making a new language why dont you just improve qbasic if that is possible

Posted: Thu Aug 16, 2007 11:09 am
by Sinuvoid
I would like to try but im guessing i would have to use some kind editor and understand hex etc....

Posted: Thu Aug 16, 2007 12:57 pm
by bungytheworm
You just need to do library of sub's and functions for start.

Example, you want command wich clears screen in certain color?

Code: Select all

SUB CLR(ScrColor AS Integer)
    Color ScrColor, ScrColor
    CLS
END SUB
Now, you only need to do this CLR 0 and screen is cleared to black.
To use it like CLR Black you need to CONST colors in your library too.

Code: Select all

CONST Black = 0
CONST Blue = 1
etc. etc. etc.

Learn to create libraries, then your imagination is only limit (and few other things with qb)

Posted: Thu Aug 16, 2007 1:06 pm
by Stoves
Lee wrote:I would like to try but im guessing i would have to use some kind editor and understand hex etc....
Nah, no hex editing necessary. The code I posted earlier allows you to read contents of a text file and write text to a file, so all you need to do is learn what to do with the text that's read in.

The lineofCode$ variable is a string that holds each line of text as it's read in, so analyze that variable, convert it to the appropriate Qbasic language resulting in a new string variable exportCode$ that you can write out to the final .BAS file.

For starters, try just reading in the contents of a file and printing them to the screen. And then try writing some text to a file and then opening the resulting file in notepad to see the results. I think that should help demonstrate how the code works.

Posted: Sat Aug 18, 2007 8:05 am
by Sinuvoid
I think ill go with E.K's suggestion :D
Itll be a library ..but how do you create libraries?and run them?

Posted: Sat Aug 18, 2007 4:49 pm
by MystikShadows
Libraries are just a special kind of module.

IN QB don't have any code in the main part of the program, just a list of SUBS and FUNCTIONS (as needed).

MILIB.BAS

Code: Select all

SUB This()
        ....CODE for the sub
END SUB

SUB That()
        ....CODE for the sub
END SUB

SUB Them()
        ....CODE for the sub
END SUB

Then Have a <ModuleName..BI include file to have the declare for all these.

MYLIB.BI

Code: Select all

DECLARE SUB This()
DECLARE SUB That()
DECLARE SUB Them()
Something like this and then look at QB's online help. it should tell you how to make a library. :-) step by step.

Posted: Mon Aug 20, 2007 8:55 pm
by Quicky
is it possible to someday have qb run with windows