How to make a programing language....
How to make a programing language....
Thats my queston...(Title)
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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.
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.
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
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.
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.
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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
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
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
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:
so yah......PLEASE REPLY ASAP
Lee
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
Lee
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:
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:
Is this kind of what you're talking about?
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
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
Last edited by Stoves on Fri Aug 10, 2007 12:18 pm, edited 1 time in total.
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.
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.
Well, here's some blocks of code that should hopefully get you started:
This code reads in a file line by line:
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:
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
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
-
- Veteran
- Posts: 288
- Joined: Sat Feb 18, 2006 4:02 pm
You just need to do library of sub's and functions for start.
Example, you want command wich clears screen in certain color?
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.
etc. etc. etc.
Learn to create libraries, then your imagination is only limit (and few other things with qb)
Example, you want command wich clears screen in certain color?
Code: Select all
SUB CLR(ScrColor AS Integer)
Color ScrColor, ScrColor
CLS
END SUB
To use it like CLR Black you need to CONST colors in your library too.
Code: Select all
CONST Black = 0
CONST Blue = 1
Learn to create libraries, then your imagination is only limit (and few other things with qb)
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.Lee wrote:I would like to try but im guessing i would have to use some kind editor and understand hex etc....
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.
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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
Then Have a <ModuleName..BI include file to have the declare for all these.
MYLIB.BI
Something like this and then look at QB's online help. it should tell you how to make a library. step by step.
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
MYLIB.BI
Code: Select all
DECLARE SUB This()
DECLARE SUB That()
DECLARE SUB Them()
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com