Hey everyone!
I was in the [url=http://www.facepunch.com/showthread.php?t=796916]Fake Programming Languages[/url] thread a while ago, and saw [url=http://www.facepunch.com/showthread.php?p=16840329#post16840329]a post about a brainfuck-derived language[/url]; long story short wanted to do something with C/C++, and decided to make an interpreter for this language. I'm calling the language EasyBrainfuck while I work on it, and calling the actual program EasyBf
Decided to add another command to the list [url=http://www.facepunch.com/member.php?u=294]jivemasta[/url] provided, # comments out the current line to the end, like '//' does in C++
Anyways, here's a download link, this zip file includes a binary for Ubuntu (No XP yet, I'll get one up when Ima boot to XP), as well as the source, readme, and a few examples: [url]http://www.filepak.com/upload/5_EasyBf.zip[/url]
Here's the source:
[code]/********************************************************
**** ####### ####### Alpha2 ****
**** ## ## ## ****
**** ## #### ##### # # ## ## ##### ****
**** ###### ## ## ## ## ## ####### ## ****
**** ## ###### #### #### ## ## ##### ****
**** ## ## ## ## ## ## ## ## ****
**** ######## ## ## ##### ## ######## ## ****
*********************************************************
*********** EasyBf EasyBrainfuck Interpreter ***********
******* Coded by Danneh (dan11999922@hotmail.com) *******
**************************************************************************
*** COPYING LICENCE ******************************************************
** EasyBf is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** EasyBf is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with EasyBf. If not, see <http://www.gnu.org/licenses/>
**************************************************************************
** Usage: easybf <EasyBrainfuck File> -d (flagDebug)
** The -d switch adds Debug output, any error submissions should
** include the program output with this switch
**
** EasyBrainfuck is inspired by the original Brainfuck, written by Urban Müller
** EasyBrainfuck is a language specced by JiveMasta (AIM BIGPrEttyunIcrNS)
**
***************************************
********** Language Specifications ****
** 'I always wanted to take brainfuck and make it a
** little less of a brain fuck, and more useful'
** -jivemasta
**
**** Language Operators ****
** > and < move the memory index pointer
** 0-9 add integers to the memory at the current index
** a-Z add chars to the memory at the current index
** +,-,*,/ does the operation to the current index
** -and the next index to the right
** @(#) copies the current index to index of #
** -( like @(3) copies to the third memory index)
** . prints the current index
** , takes input
** {} loops, if current index = 0, break loop
** [] if current index = 0 skip stuff inside
** # comments out the current line to the end, like C++ '//' comments
**
**** Language Examples ****
** :Hello World:
** Program: H>e>l>o>W>r>d<<<<<<.>.>..>.>.<.>>.<<<.>>>>.
** Output : HelloWorld
**
** :Countdown:
** Program: 9>1<{.-}B.l.a.s.t.o.f..
** Output : 987654321Blastoff
**
**********************************
********** EasyBf Limitations ****
** Problems and Limits with the Interpreter
**
***** Program Length ****
** The program can only be max 65534 characters long;
** this may be adusted changing the #define MAXARRAY,
** though thee unsigned int's fileDataIndex and memDataIndex
** may need to be changed to alternate datatypes
** in order to handle Indexing the new array dimentions
**
***** @(#) ****
** The '#' value can only be 1 digit long, for example:
** whereas @(2) works, @(11) does not
**
***************************************************/
#include <iostream>// I/O Stream
#include <fstream> // File Stream
#include <sstream> // String Stream
#include <string> // String Functions
using namespace std;
/* Bool Values */
#define FALSE 0
#define TRUE (-1)
#define MAXARRAY 65535 // This is the min. value for an Unsigned Int;
// used this value so Unsigned Ints can index the arrays
char memCharData[MAXARRAY], fileData[MAXARRAY];
int memIntData[MAXARRAY];
unsigned int memDataIndex = 0, fileDataIndex = 0;
bool flagDebug;
/* Function Prototypes */
bool isInt(string inString), isInt(char inChar), isLetter(char inChar);
int toInt(string inString), toInt(char inChar);
string toString(int inInteger), toString(char inChar);
string returnData(int index);
int main(int argc, char *argv[])
{
//Clear Data Arrays
for(int i = 0; i < MAXARRAY; i++) {
memIntData[i] = 0;
memCharData[i] = '\0';
fileData[i] = '\0';
}
/*******************
*** Title Stuffs **/
cout << "\nEasyBf -Alpha 2\n";
cout << " An EasyBrainfuck Interpreter\n";
/**********************
*** File Operations **/
if(argc > 1) {
ifstream inFile;
inFile.open(argv[1]);
if(inFile.is_open()) {
char fileDataTemp[MAXARRAY];
while(!inFile.eof()) {
inFile.getline(fileDataTemp, MAXARRAY);
int i = 0;
while((fileDataTemp[i] != '#') && (fileDataTemp[i] != '\0')) {
fileData[fileDataIndex] = fileDataTemp[i];
fileDataIndex++;
i++;
}
}
fileDataIndex = 0;
// Program too long
if(fileData[MAXARRAY-1] != '\0') {
cout << "\nERROR: Program is too long to read\n";
return 1;
}
// Debug Flag
if((argc > 2) && ((string)argv[2] == "-d")) {
flagDebug = TRUE;
} else {
flagDebug = FALSE;
}
} else { // Couldn't open file
cout << "ERROR: Failed to open file:\n" << argv[1] << "\n";
return 1;
}
} else { // User didn't enter any arguments
cout << "Usage: easybf <EasyBrainfuck File> -d (flagDebug)\n";
cout << "Check readme for more information\n\n";
return 1;
}
cout << "Program Started\n\n";
// Print current program to screen
cout << "Program: " << fileData << '\n';
/**************************
*** Language Operations **/
while(fileData[fileDataIndex] != '\0') {
/**** Memory Index Pointer Foward ****/
if(fileData[fileDataIndex] == '>') {
memDataIndex++;
if(flagDebug) { // DebugStart
cout << ">|| memData(" << memDataIndex << ')';
} // DebugEnd
}
/**** Memory Index Pointer Backward ****/
else if(fileData[fileDataIndex] == '<') {
memDataIndex--;
if(flagDebug) { // DebugStart
cout << "<|| memData(" << memDataIndex << ')';
} // DebugEnd
}
/**** Addition ****/
else if(fileData[fileDataIndex] == '+') {
if(flagDebug) { // DebugStart
cout << "+|| memData(" << memDataIndex << ')';
cout << " was \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
memIntData[memDataIndex]+= memIntData[memDataIndex+1];
if(flagDebug) { // DebugStart
cout << " || memData(" << memDataIndex << ')';
cout << " is now \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
}
/**** Subtraction ****/
else if(fileData[fileDataIndex] == '-') {
if(flagDebug) { // DebugStart
cout << "-|| memData(" << memDataIndex << ')';
cout << " was \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
memIntData[memDataIndex] -= memIntData[memDataIndex+1];
if(flagDebug) { // DebugStart
cout << " || memData(" << memDataIndex << ')';
cout << " is now \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
}
/**** Multiplication ****/
else if(fileData[fileDataIndex] == '*') {
if(flagDebug) { // DebugStart
cout << "*|| memData(" << memDataIndex << ')';
cout << " was \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
memIntData[memDataIndex] *= memIntData[memDataIndex+1];
if(flagDebug) { // DebugStart
cout << " || memData(" << memDataIndex << ')';
cout << " is now \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
}
/**** Division ****/
else if(fileData[fileDataIndex] == '/') {
if(memIntData[memDataIndex+1] != 0) { /* Divide by Zero */
if(flagDebug) { // DebugStart
cout << "/|| memData(" << memDataIndex << ')';
cout << " was \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
memIntData[memDataIndex] /= memIntData[memDataIndex+1];
if(flagDebug) { // DebugStart
cout << " || memData(" << memDataIndex << ')';
cout << " is now \'" << returnData(memDataIndex) << '\'';
} // DebugEnd
} else {
cout << "ERROR: Division by zero";
}
}
/**** Print Current Memory Index ****/
else if(fileData[fileDataIndex] == '.') {
if(flagDebug) { // DebugStart
cout << ".|| memData(" << memDataIndex << ") \'";
} // DebugEnd
cout << returnData(memDataIndex);
if(flagDebug) { // DebugStart
cout << "\'";
} // DebugEnd
}
/**** Input to Current Memory Index ****/
else if(fileData[fileDataIndex] == ',') {
char userInput;
do {
cout << "\nInput: ";
cin >> userInput;
} while(isInt(userInput) || isLetter(userInput));
if(isInt(userInput)) {
memIntData[memDataIndex] = toInt(userInput);
memCharData[memDataIndex] = '\0';
} else if(isLetter(userInput)) {
memCharData[memDataIndex] = userInput;
}
if(flagDebug) { // DebugStart
cout << ",|| memData(" << memDataIndex << ')';
cout << "is now " << returnData(memDataIndex);
} // DebugEnd
}
/**** SSkip Entry ****/
else if(fileData[fileDataIndex] == '[') {
if(memIntData[memDataIndex] == 0) {
if(flagDebug) { // DebugStart
cout << "[|| Skipped SSkip : Index(" << returnData(memDataIndex) << ')';
} // DebugEnd
int loopIndex = 0;
int i = fileDataIndex;
while(fileData[i] != '\0') {
if(fileData[i] == '[') {
loopIndex++;
} else if(fileData[i] == ']') {
loopIndex--;
if(loopIndex == 0) {
fileDataIndex = --i;
break;
}
}
i++;
}
} else {
if(flagDebug) { // DebugStart
cout << "[|| Entered SSkip : Index(" << returnData(memDataIndex) << ')';
} // DebugEnd
}
}
/**** SSkip Exit ****/
else if(fileData[fileDataIndex] == ']') {
if(flagDebug) { // DebugStart
cout << "]|| Exited SSkip : Index(" << returnData(memDataIndex) << ')';
} // DebugEnd
}
/**** Loop Entry ****/
else if(fileData[fileDataIndex] == '{') {
if(flagDebug) { // DebugStart
cout << "{|| Entered Loop : Index(" << returnData(memDataIndex) << ')';
} // DebugEnd
}
/**** Loop Exit ****/
else if(fileData[fileDataIndex] == '}') {
if(memIntData[memDataIndex] != 0) {
if(flagDebug) { // DebugStart
cout << "}|| Reentered Loop : Index(" << returnData(memDataIndex) << ")";
} // DebugEnd
int loopIndex = 0;
int i = fileDataIndex;
while(fileData[i] != '\0') {
if(fileData[i] == '}') {
loopIndex++;
} else if(fileData[i] == '{') {
loopIndex--;
if(loopIndex == 0) {
fileDataIndex = --i;
break;
}
}
i--;
}
} else {
if(flagDebug) { // DebugStart
cout << "}|| Exited Loop : Index(" << returnData(memDataIndex) << ')';
} // DebugEnd
}
}
/**** Copy Current Memory Index ****/
else if(fileData[fileDataIndex] == '@') {
fileDataIndex += 2;
/* TODO: FIX THIS UGLY HACK */
if(isInt(fileData[fileDataIndex])) {
memIntData[toInt(fileData[fileDataIndex])] = memIntData[memDataIndex];
}
if(flagDebug) {
cout << "@|| ";
cout << "memData (" << fileData[fileDataIndex] << ") ";
cout << "is now " << memIntData[memDataIndex];
} /* Debug */
fileDataIndex++;
}
/**** Numbers ****/
else if(isInt(fileData[fileDataIndex])) {
memIntData[memDataIndex] = toInt(fileData[fileDataIndex]);
memCharData[memDataIndex] = '\0';
if(flagDebug) { // DebugStart
cout << "N|| ";
cout << "memData(" << memDataIndex << ") ";
cout << "is now " << fileData[fileDataIndex];
} // DebugEnd
}
/**** Letters ****/
else if(isLetter(fileData[fileDataIndex])) {
memCharData[memDataIndex] = fileData[fileDataIndex];
if(flagDebug) { // DebugStart
cout << "C|| ";
cout << "memData(" << memDataIndex << ") ";
cout << "is now " << fileData[fileDataIndex];
} // DebugEnd
}
if((fileData[fileDataIndex] != ' ') && flagDebug) {
getchar(); // To pause at each instruction,
} else {} // so people can read them
fileDataIndex++;
}
cout << '\n';
if(!flagDebug) {
cout << '\n';
} else {
cout << "Program Finished\n";
}
return 0;
}
bool isInt(string inString) {
bool isNum = TRUE;
for(int i = 0; inString[i] != '\0'; i++) {
// If is not number
if(!((int)inString[i] >= 48) || !((int)inString[i] <= 58)){
isNum = 0;
}
}
return isNum;
}
bool isInt(char inChar) {
if(((int)inChar >= 48) && ((int)inChar <= 58)){
return 1;
}
return 0;
}
bool isLetter(char inChar) {
/* Capitol Letters */
if(((int)inChar >= 65) && ((int)inChar <= 92)){
return 1;
}
/* Lowercase Letters */
else if(((int)inChar >= 97) && ((int)inChar <= 124)){
return 1;
}
return 0;
}
int toInt(string inString) {
int outInteger;
istringstream buffer(inString);
buffer >> outInteger;
return outInteger;
}
int toInt(char inChar) {
return (int)(inChar-'0');
}
char toChar(int inInteger) {
return (char)(inInteger+'0');
}
string toString(int inInteger) {
ostringstream buffer;
buffer << inInteger;
string outString = buffer.str();
return outString;
}
string toString(char inChar) {
ostringstream buffer;
buffer << inChar;
string outString = buffer.str();
return outString;
}
string returnData(int index) {
if(memCharData[index] != '\0') {
return toString(memCharData[index]);
} else {
return toString(memIntData[index]);
}
}[/code]
Todo:
• Add String Support
• Add Integers>9 Detection
• Fix @(##) Problem
If you wanna see anything else added to this, want to post any language additions, or simply want to call me an idiot and post fixed code just post in here!
Any cc/advice welcomed, even just criticism is fine :v:
[b]Edit:[/b]
Seems this thread has mainly become EasyBrainfuck standards talk, so though I'd change the thread title to reflect that :D
[code]**************************************
**** EasyBrainfuck Specifications ****
**************************************
**** Operators ****
** > | Move the memory index pointer plus one higher
** < | Move the memory index pointer minus one lower
**
** . | Print data from the Current Index to the screen
** $ | Print a string starting from the current memory index
** | and ending at a 0 or NULL value to the screen
** , | Input data from the user to the Current Index
**
** 0-9 | Add integers to the memory at the Current Index
** | (Can go from 0 to max cell value of the implimentation)
** A-Z | Add characters to the memory at the Current Index
** "CC" | The characters inside double-quote tags are stored into the
** | current and following memory indexes, adding a
** | numerical 0 at the end of the string. While this happens,
** | the memory index pointer stays at the same position.
** | For example, "HELLOWORLD" would be equal to
** | H>E>L>L>O>W>O>R>L>D>0<<<<<<<<<<
**
** + - | Add/Minus Index+1 from the Current Index, store in Current Index
** * / | Multiply/Divide Index+1 from the Current Index, store in Current Index
**
** @(#) | Copy the Current Index to index of #
** | (like @(33) copies to the thirty-third memory index)
** !(#) | Change memory index pointer to the one specified in #
** | (like !(33) moves the memory index pointer to the 33rd place)
**
** {} | Loops, if Current Index is 0, break loop
** [] | If Current Index is 0, skip between the brackets
** # | Comment out the current line to the end
**
**** Operators, cont ****
** / - Divides are to round as accuratly as possible
** (<0.5 becomes 0, while >=0.5 becomes 1)
**
**** Cells ****
** The number of cells are implementation-defined, though should
** have at least from 0-9999 cells
**
** Cells should be able to contain the values a-z, A-Z,
** whitespace, newlines, question marks, slashes, single/double quotes
** (to be represented by ' , '\n, '?, '/, '\, '\', '\")
** Integer values should range from at least 0-255,
** though higher values are recommended
** Any other cell values are implementation-defined
**
** If the memory index pointer tries to move below the first cell,
** the pointer should be stopped at cell 0
** If the pointer attempts to move above the last cell,
** the pointer should 'wrap-around' to cell 0, this has been done so that
** programs using loops will not keep trying to go higher and higher
** and will actually stop and loop around to a reasonable cell
**
** If a program attempts to set a cell above the maximum value for that
** EBf implementation (set cell to 999999, cell only supports 255),
** the cell should be set to the highest possible value, along with an
** error message being printed, though the program should remain running
**
**** Brackets ****
** If a program contains unbalanced brackets, the program's behavior
** is to be implementation-defined, whether printing an error message,
** or attempting to run the program anyways
**
**** Language Examples ****
** :Hello World:
** Program: "HeloWrd".>.>..>.>.<.>>.<<<.>>>>.
** Program: "HelloWorld"$
** Output : HelloWorld
**
** :Countdown:
** Program: 9>1<{.-}B.l.a.s.t.o.f..
** Program: 9>1<{.-}"Blastoff"$
** Output : 987654321Blastoff
**
********[/code]
Those are the working specs, if you guys wanna post any modifications to them feel free!
Isn't it kinda counter-productive to make a easy version of a language which was made to be difficult? :v:
[QUOTE=noctune9;17738153]Isn't it kinda counter-productive to make a easy version of a language which was made to be difficult? :v:[/QUOTE]
I thought that too, but I really just wanted something to code, haven't done it in quite a while
GAH! I see a "goto"!
[QUOTE=high6;17738284]GAH! I see a "goto"![/QUOTE]
Yep, cbf'd working out an algorithm to get it to work without it
[QUOTE=Dan11999922;17738297]Yep, cbf'd working out an algorithm to get it to work without it[/QUOTE]
Maybe something like a while loop? :rolleye:
[QUOTE=Sporbie;17738590]Maybe something like a while loop? :rolleye:[/QUOTE]
Haha probably
I'm thinking maaybe algorithm wasn't the right word to use there
[b]Edit:[/b]
Righty, just fixed up the goto (I is an idiot)
Gonna work on the strings now, hope it isn't as difficult to get as the goto was! :v:
I don't really like how you are not using C++ at its fullest potential.
Examples:
#define FALSE 0
#define TRUE (-1)
...what?
or those type-conversion-functions. You could just use a single templated function. Well, with partial template specialization if you want different versions for toInt/toChar.
[QUOTE=ZeekyHBomb;17740748]I don't really like how you are not using C++ at its fullest potential.
Examples:
#define FALSE 0
#define TRUE (-1)
...what?
or those type-conversion-functions. You could just use a single templated function. Well, with partial template specialization if you want different versions for toInt/toChar.[/QUOTE]
Haha yeah, this is the second C/C++ program I've written for about two years (though didn't know it particularly well before then anyways); so there's probably a lot of stuff like that :v:
Well, in that case...
I'll 'fix' (not really, as it works; rather update or something) the code and post it when I'm finished.
Just gone through replacing that if..if else-chain with a switch (among some other minor things, such as using strings rather than arrays and iterators instead of indecies) and that was boring. So I'm gonna do something else and revisit the code later.
EDIT: I actually screwed that now. If you want I can post the version as far as I edited it (might not work, maybe not even compile; didn't test).
I'm writing my own interpreter now.
May I though suggest a specification-change? Brainfuck wasn't supposed to have parameters for its operators, which makes @(#) look weird. Maybe it could copy data[dataIndex] to data[dataIndex+1]?
And maybe an operator which sets the dataIndex to data[dataIndex]? Then you could do for example "H>e>l>o>W>r>d>0!.>.>..>.>.<.>>.<<<.>>>>.", ! being that new operator.
As for the problem of multiple-digit integers, you could specify it so you must declare them like '42' (and also '0' then), as else you might wanna set the memory address to '4' then to '2', not to '42' (that wouldn't make sense in a real application, but still...).
The Hello-World program would then become (with addition of the new operators):
[code]H>e>l>o>W>r>d>'0'!.>.>..>.>.<.>>.<<<.>>>>.[/code]
Note that this way, you can also have the numbers as chars, rather than numbers.
Maybe you should also have one operator for outputting data[dataIndex] as char, and one to output it as number. Maybe number could be '.' and char could be ';'.
An example:
[code]"N;"u;"m;"b;"e;"r;":;" ;'42'. #output: Number: 42[/code]
I also just invented using " to prefix chars, so you can have a space and such. You could maybe also do "\n (for a new line) then. To do \, you would use "\\, like in C.
It would also make sense to specify the biggest and the smallest number as well as the character-set to use.
Also, is behavior for overflow undefined? e.g. the program
[code]1+[/code]
Or underflow:
[code]+[/code]
[code]<[/code]
[QUOTE]**** Language Examples ****
** :Hello World:
** Program: H>e>l>o>W>r>d<<<<<<.>.>..>.>.<.>>.<<<.>>>>.
** Output : HelloWorld[/QUOTE]
Correct me if i'm wrong, but isn't hello world in EBF
H>e>l>l>o>W>o>r>l>d>
(with all the other dots and shit)
That second part of the program looks like a loop that goes back, picks up some chars, and copies them or something.
Actually, screw that memoryIndex-operator thing for which I used !. It's kinda dull if you think about it.
I'd still like to be able to differentiate between chars and ints though.
[code]H.e.l..o.W.o.r.l.d.[/code]
[code]H>e>l>l>o>W>o>r>l>d<<<<<<<<<.>.>.>.>.>.>.>.>.>.[/code]
[code]H>e>l>o>W>r>d<<<<<<.>.>..>.>.<.>>.<<<.>>>>.[/code]
All 3 output HelloWorld in BF and EBF.
I've heard of Brain Fuck, but this is ridiculous
Haha Zeeky, a lot of that is carry-over from the first version which used C rather than C++
Also, the underflow and overflow behaviours aren't defined no, though 1+ would (should) just output 1 since the data arrays are initialised to 0 and '\0' at the start of the program. Thanks for all the ideas as well!
The main reason I'd make something like '42' change the data to 42 rather than 4, than 2 is that if someone puts multiple numbers in a row, they're either wanting to set the data to a big number, or they want to set it to a bunch of small numbers in a row; since there's not really much use for the second method at all I decided to use the first for this program
[quote="cas97"]I've heard of Brain Fuck, but this is ridiculous [/quote]
l>i>e>V.>d>r>u>y>o>s>c<<<<<<<<.>>>.>>.<<.<<<<.>>>.<<<.>>>>>>>>>.<<<<.<<<<<<.>>>>>>>>.<<.>>>.
[QUOTE=Dan11999922;17750105]Haha Zeeky, a lot of that is carry-over from the first version which used C rather than C++[/QUOTE]
I noticed ;P
[QUOTE=Dan11999922;17750105]Also, the underflow and overflow behaviours aren't defined no, though 1+ would (should) just output 1 since the data arrays are initialised to 0 and '\0' at the start of the program. Thanks for all the ideas as well![/QUOTE]
Well, do they have to be initialized as 0? The language specification should say that if that is the case. Else you should write down that behavior can be undefined for clarification.
My interpreter will be using a dynamically sizing array, and as such I must know if I have to take care of that.
[QUOTE=Dan11999922;17750105]The main reason I'd make something like '42' change the data to 42 rather than 4, than 2 is that if someone puts multiple numbers in a row, they're either wanting to set the data to a big number, or they want to set it to a bunch of small numbers in a row; since there's not really much use for the second method at all I decided to use the first for this program[/QUOTE]
That is rather true :P
Is there a requirement for maximum/minimum values though? And what should happen if the number is to big/too small? Undefined behavior? Abort? Simply set to the maximum supported value?
And what if the interpreter would be capable of larger numbers than the specification defines? Still force to the lower values or, like in C, are they just a minimum requirement?
Also, what if I want 4 as a char, not a number? And what about input, shall it be capable of only reading chars, or as well numbers?
I'd much rather like different I/O commands for each type.
[QUOTE=cas97;17747349]I've heard of Brain Fuck, but this is ridiculous[/QUOTE]
Wait till I release my interpreter... I'm already using more than 150 lines (K&R-codestyle, very few comments) and I've not even started with EasyBf-interpretion yet. It's just parsing command-line parameters, a few function-prototypes and some variables.
That's ridiculous.
[QUOTE=ZeekyHBomb;17746836]Actually, screw that memoryIndex-operator thing for which I used !. It's kinda dull if you think about it.
I'd still like to be able to differentiate between chars and ints though.
[code]H.e.l..o.W.o.r.l.d.[/code]
[code]H>e>l>l>o>W>o>r>l>d<<<<<<<<<.>.>.>.>.>.>.>.>.>.[/code]
[code]H>e>l>o>W>r>d<<<<<<.>.>..>.>.<.>>.<<<.>>>>.[/code]
All 3 output HelloWorld in BF and EBF.[/QUOTE]
For that first one, since BF and possible EBF add the letter to the specific index wouldn't only the H be displayed then a bunch of nonsensical ASCII as the values get higher and higher?
Oh and I'm also taking a crack at EBF parsing, it seems like a lot of fun. I've got everything except loops done, and about to do those now. It's quite enjoyable
[QUOTE=t0rento;17754249]For that first one, since BF and possible EBF add the letter to the specific index wouldn't only the H be displayed then a bunch of nonsensical ASCII as the values get higher and higher?[/QUOTE]
Not in EBf. You do math via the operators +, -, * and / now. a-Z, 0-9 and ',' replace that memory.
Which makes me wonder... how shall / round? Always up? Always down? Or as accurate as possible (e.g. <0.5 becomes 0, while >=0.5 becomes 1)?
Alrighty then, time to write up some specs! :v:
Those are the working specs, if you guys wanna post any modifications to them feel free!
[b]Edit:[/b]
Specs are in the main post now
[QUOTE=Dan11999922;17756594]
Those are the working specs, if you guys wanna post any modifications to them feel free![/QUOTE]
I'd say for chars you just do the letter. Then for strings you do "string". " would be an operator that automatically adds all the chars to the memory until it gets to a second " and then it adds a 0 to the end. So, for example:
[code]
"Hello"
[/code]
Would work exactly the same as:
[code]
H>e>l>l>o>0
[/code]
But look less confusing. Then you could also have $ be a operator to print a string starting at a the current memory index until it gets to a 0 or null.
Everyone knows how to code interpreters but me D:
I started the esolang contest to learn from other people's code, lol :buddy:
[QUOTE=jivemasta;17759298]I'd say for chars you just do the letter. Then for strings you do "string". " would be an operator that automatically adds all the chars to the memory until it gets to a second " and then it adds a 0 to the end. So, for example:
[code]
"Hello"
[/code]
Would work exactly the same as:
[code]
H>e>l>l>o>0
[/code]
But look less confusing. Then you could also have $ be a operator to print a string starting at a the current memory index until it gets to a 0 or null.[/QUOTE]
So C for characters and "CCC" for strings sound alright?
(C is character)
[QUOTE=Eudoxia;17764730]Everyone knows how to code interpreters but me D:
I started the esolang contest to learn from other people's code, lol :buddy:[/QUOTE]
Haha, you just break it down into small parts
-Getting File Name
-Inputting File Data
-Parsing Code
Eventually, with enough breaking down, it gets to a codeable stage
[QUOTE=Dan11999922;17766243]So ' for characters and "" for strings sound alright?
Haha, you just break it down into small parts
-Getting File Name
-Inputting File Data
-Parsing Code
Eventually, with enough breaking down, it gets to a codeable stage[/QUOTE]
Thanks for the advice.
I'm gonna comment the shit out of your code, lol :v:
Haha np, I'm gonna pretty much start over in C++
The current code is mostly carry-over C stuff anyway
[QUOTE=Dan11999922;17766566]Haha np, I'm gonna pretty much start over in C++
The current code is mostly carry-over C stuff anyway[/QUOTE]
I just looked at the code, and noticed the using namespace std; thing.
That's odd, I thought the project was in plain C. The file extension was .c, after all.
[QUOTE=Eudoxia;17766679]I just looked at the code, and noticed the using namespace std; thing.
That's odd, I thought the project was in plain C. The file extension was .c, after all.[/QUOTE]
Yeah, it was in C, the other version
After a while I decided to convert it to C++ for all the shiny strings and crap, that's why Ima referring to carry-over C stuff from previous versions xD
[QUOTE=Dan11999922;17766730]Yeah, it was in C, the other version
After a while I decided to convert it to C++ for all the shiny strings and crap, that's why Ima referring to carry-over C stuff from previous versions xD[/QUOTE]
And when you convert it to D, you'll have this shiny little function that upcases the input, which is great for a command-line parser
[QUOTE=Eudoxia;17766756]And when you convert it to D, you'll have this shiny little function that upcases the input, which is great for a command-line parser[/QUOTE]
Haha, only for the -debug command flag though
I'd like this to run on Linux as well, which requires case-specificity in relation to paths and such
[QUOTE=Dan11999922;17766805]Haha, only for the -debug command flag though
I'd like this to run on Linux as well, which requires case-specificity in relation to paths and such[/QUOTE]
I compiled it on Linux (Ubuntu 9.04, using the command: g++ easy_bf.cpp -o "ebf") and there wer no errors :downs:
But I haven't [yet] tested the app while running, lol.
[QUOTE=Eudoxia;17766854]I compiled it on Linux (Ubuntu 9.04, using the command: g++ easy_bf.cpp -o "ebf") and there wer no errors :downs:
But I haven't [yet] tested the app while running, lol.[/QUOTE]
Haha, I've been using Ubuntu Jaunty with CodeBlocks to compile this
[QUOTE=Dan11999922;17766952]Haha, I've been using Ubuntu Jaunty with CodeBlocks to compile this[/QUOTE]
I've been using Geany to compile this experimental interpreter, but DAMN it doesn't work:
[CPP]#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
void man(){}
int main()
{
string keyword;
string argument[4];
cout << "BPLX Interpreter -- Alpha 1\n";
cout << "---------------------------\n";
cout << ":m to get help, :q to quit.\n";
cout << "---------------------------\n";
parser:
cout << "BPLX>>>";
cin >> keyword >> argument[0] >> argument[1] >> argument[2] >> argument[3] >> argument[4];
/*Parser*/
if(keyword == "out")
{
cout << argument[0];
if(argument[1] == ",")
{
cout << argument[2];
if(argument[3] == ",")
{
cout << argument[4];
}
}
}
else if(keyword == "input")
{
}
else if(keyword == "var")
{
}
else if(keyword == ":q")
{
goto TERMINATE;
}
else if(keyword == ":m")
{
man();
}
else
{
cout << "<System>*** Unknown Keyword // Arguments not responding.\n\a\a";
goto parser;
}
TERMINATE:
return 0;
}
[/CPP]
Total completed: 40%
Remaining: 100% ;_;
Sorry, you need to Log In to post a reply to this thread.