Read source file
From beginning of the code to the end {
If symbol is '>'
Cell++
If symbol is '<'
Cell--
If symbol is '+'
Memory at cell++
(etcetera)
}
For example, the M-code executable is an interpreter.
Read source file
From beginning of the code to the end {
If symbol is '>'
Cell++
If symbol is '<'
Cell--
If symbol is '+'
Memory at cell++
(etcetera)
}
For example, the M-code executable is an interpreter.
I don't even know where to begin...
It WILL be difficult with my low-level C programming abilities and my not-so-long attention span.
All you're doing is replacing letters with numbers. An interpreter sees code and does what it says.
The only difference between an interpreter and a compiler is that a compiler spits the code out to assembly to make an executable. An interpreter makes it into its own form of assembly and runs it. Mine is already close to assembly, so little of that is going on.
All you're doing is replacing letters with numbers. An interpreter sees code and does what it says.
The only difference between an interpreter and a compiler is that a compiler spits the code out to assembly to make an executable. An interpreter makes it into its own form of assembly and runs it. Mine is already close to assembly, so little of that is going on.
One of the major parts of being a programmer is breaking it down into smaller tasks. The first step would be to read the file into a big string, then to break that big string up into fragments according to spaces and newlines, then to recognise symbols in the fragments. That's a good start and if you can get that far then you can set about analysing the structure of this big list of fragments, to see how it would flow and such.
@nex
A BF compiler is much easier since you only need to look at one character at a time
@poke
Visualize this with me. I'm breaking everything down into its core components. The core pieces are easy, so when you can get them to work together, you've got a program. This is why most people are truly incapable of understanding code without inhuman amounts of practice, because they can't do this in their mind. You show promise.
Interpret a BF script
- Read a BF script from a file
- - Open the file into memory
- - Store each character into a string
- - - Start at the beginning of the file
- - - Add the current character to the end of the string
- - - Increment the character lookup position by one
- - - Go back to "Add.." until the end of the file is reached
- Interpret the file
- - From the beginning to the end of the file, look at each character individually and do what it says
- - - Start at the string's beginning
- - - Do what the character's instruction is
- - - - If it's a "<" or ">", move the cell pointer
- - - - - Establish an array and the program's position in it. (Not here, but before the main parsing loop)
- - - - - Increment/decrement the cell pointer by one
- - - - - Keep the cell pointer in bounds of the array so you don't get an error
- - - - - - If it becomes <0 set it to the array's maximum
- - - - - - If it becomes >the array's maximum, set it to 0
- - - - If it's a "+" or "-"
- - - - - Increment/decrement the cell under the pointer by one
- - - - - Generally, BF interpreters make this value wrap 0-255, meaning if it's 0 and decremented it becomes 255, and if it's 255 and incremented it becomes 0.
- - - - If it's a "." printf the ASCII character of the cell under the pointer
- - - - If it's a "," (scanf? Can't recall the command) to get an ASCII to store in the cell under the pointer
- - - - If it's a "["
- - - - - If the cell under the pointer is >0, continue
- - - - - If the cell under the pointer is 0, jump past the matching "]"
- - - - - - Go through each character starting at the current position with a variable to keep track of nest. Start it at int nest = 1
- - - - - - Every time a "[" is encountered, nest++
- - - - - - Every time a "]" is encountered, nest--
- - - - - - If nest=0 you've found where you need to be
- - - - - - If the end of the string has been reached and nest>0, someone made an error writing their BF script.
- - - - If it's a "]"
- - - - - Jump back to the matching "["
- - - - - - Go backwards starting at the current position in the string
- - - - - - Keep track of nesting just like with the "["
- - - - If the end of the string has been reached, end the program
- - - Increment position in string by one
- - - Go back to "Do.." until the end of the string is reached and it's not a "]" character.
I'm working on a BrainF*ck interpreter in this M-code, which is infinitely more difficult than writing one otherwise. When you're trying to handle larger tasks, or just doing them in assembly or anything similar where even the smallest tasks can become quite large, it's critical that you can go through this kind of process on your own.
Well? I'm glad to help and I'm sure nex is. What exactly don't you understand?
For the second line of the pseudo-code, what does it mean when you "read" a BF script from a file?
I also don't know what "intercept" means.
Look here, I don't have an exquisite vocabulary for programming terms.
I'm not in a good school, I'm not in college, high school, not even middle school.
Don't assume that I understand everything about C.
And what is a "pointer"?
Well? I'm glad to help and I'm sure nex is. What exactly don't you understand?
For the second line of the pseudo-code, what does it mean when you "read" a BF script from a file?
I also don't know what "intercept" means.
Look here, I don't have an exquisite vocabulary for programming terms.
I'm not in a good school, I'm not in college, high school, not even middle school.
Don't assume that I understand everything about C.
And what is a "pointer"?
Read:
If you type something in Notepad, say "Hello", that's data that can be read by the computer. stdio.h has some functions for reading files. For example, reading that text file with "Hello" in it, when read, would put "Hello" in your program almost like it does a string. (A string is a bunch of chars strung together. "A" is just a char, "Hello, Mr. Anderson." is a string.)
Intercept:
I'm not sure where I used this, but it means to catch in the middle of - like an interception in football where the player interrupts the ball to use for himself. However, if you meant
Increment:
Increment = increase, decrement = decrease. They mean exactly the same thing, but increment and decrement are the more common terminology when dealing with programming.
Pointer:
In its most technical sense, it's the address (or position) of a variable in your computer's RAM (random-access memory). Generally, it can just mean the position of any particular number or variable. "Cell pointer" could be a literal pointer to look through an array very quickly. However, simply using it to find an index in an array is no different functionally and only extremely slightly slower than using a pointer.
Array:
Whereas "int number;" is a variable, "int number[64];" is an array of 64 variables. To reference one of these 64 variables individually, you reference them like "if ( number[22] == 0 )", where the 23rd (number[0] is the first) variable in the number[ ] array is the one being operated on.
Not exactly. Increment means an increase by a specific amount (usually by some quanta) whereas increase doesn't refer to any sort of value. Increment implies that there's a relevant quantity, increase does not. Same for decrement and decrease. Subtle and pedantic? Absolutely.
Rollback Post to RevisionRollBack
Never attribute to malice what can adequately be explained by incompetence.
I don't know what an interpreter is.
(sorry for double post)
If I deserve one, give me one.
For example, the M-code executable is an interpreter.
I don't even know where to begin...
It WILL be difficult with my low-level C programming abilities and my not-so-long attention span.
If I deserve one, give me one.
I believe in you! You can do it! YOU WILL SUCCEED. Because if you don't, I will look for you. And I will find you, and I will kill you.
I don't even know BrainF*ck...
If I deserve one, give me one.
But I got an idea for an esoteric language. D:
If I deserve one, give me one.
Well, it's like a different version of the decimal ASCII table chart.
Here's Hello World in my language:
It's not original I think.
If I deserve one, give me one.
That's not a language.
Then what is it? :/
If I deserve one, give me one.
The only difference between an interpreter and a compiler is that a compiler spits the code out to assembly to make an executable. An interpreter makes it into its own form of assembly and runs it. Mine is already close to assembly, so little of that is going on.
I am still not capable of making an interpreter.
If I deserve one, give me one.
I don't know what that means.
If I deserve one, give me one.
A BF compiler is much easier since you only need to look at one character at a time
@poke
Visualize this with me. I'm breaking everything down into its core components. The core pieces are easy, so when you can get them to work together, you've got a program. This is why most people are truly incapable of understanding code without inhuman amounts of practice, because they can't do this in their mind. You show promise.
Interpret a BF script
- Read a BF script from a file
- - Open the file into memory
- - Store each character into a string
- - - Start at the beginning of the file
- - - Add the current character to the end of the string
- - - Increment the character lookup position by one
- - - Go back to "Add.." until the end of the file is reached
- Interpret the file
- - From the beginning to the end of the file, look at each character individually and do what it says
- - - Start at the string's beginning
- - - Do what the character's instruction is
- - - - If it's a "<" or ">", move the cell pointer
- - - - - Establish an array and the program's position in it. (Not here, but before the main parsing loop)
- - - - - Increment/decrement the cell pointer by one
- - - - - Keep the cell pointer in bounds of the array so you don't get an error
- - - - - - If it becomes <0 set it to the array's maximum
- - - - - - If it becomes >the array's maximum, set it to 0
- - - - If it's a "+" or "-"
- - - - - Increment/decrement the cell under the pointer by one
- - - - - Generally, BF interpreters make this value wrap 0-255, meaning if it's 0 and decremented it becomes 255, and if it's 255 and incremented it becomes 0.
- - - - If it's a "." printf the ASCII character of the cell under the pointer
- - - - If it's a "," (scanf? Can't recall the command) to get an ASCII to store in the cell under the pointer
- - - - If it's a "["
- - - - - If the cell under the pointer is >0, continue
- - - - - If the cell under the pointer is 0, jump past the matching "]"
- - - - - - Go through each character starting at the current position with a variable to keep track of nest. Start it at int nest = 1
- - - - - - Every time a "[" is encountered, nest++
- - - - - - Every time a "]" is encountered, nest--
- - - - - - If nest=0 you've found where you need to be
- - - - - - If the end of the string has been reached and nest>0, someone made an error writing their BF script.
- - - - If it's a "]"
- - - - - Jump back to the matching "["
- - - - - - Go backwards starting at the current position in the string
- - - - - - Keep track of nesting just like with the "["
- - - - If the end of the string has been reached, end the program
- - - Increment position in string by one
- - - Go back to "Do.." until the end of the string is reached and it's not a "]" character.
I'm working on a BrainF*ck interpreter in this M-code, which is infinitely more difficult than writing one otherwise. When you're trying to handle larger tasks, or just doing them in assembly or anything similar where even the smallest tasks can become quite large, it's critical that you can go through this kind of process on your own.
If I deserve one, give me one.
And coding [ ]'s for bf in m-code is a complete and utter nightmare ._.
For the second line of the pseudo-code, what does it mean when you "read" a BF script from a file?
I also don't know what "intercept" means.
Look here, I don't have an exquisite vocabulary for programming terms.
I'm not in a good school, I'm not in college, high school, not even middle school.
Don't assume that I understand everything about C.
And what is a "pointer"?
If I deserve one, give me one.
Read:
If you type something in Notepad, say "Hello", that's data that can be read by the computer. stdio.h has some functions for reading files. For example, reading that text file with "Hello" in it, when read, would put "Hello" in your program almost like it does a string. (A string is a bunch of chars strung together. "A" is just a char, "Hello, Mr. Anderson." is a string.)
Intercept:
I'm not sure where I used this, but it means to catch in the middle of - like an interception in football where the player interrupts the ball to use for himself. However, if you meant
Increment:
Increment = increase, decrement = decrease. They mean exactly the same thing, but increment and decrement are the more common terminology when dealing with programming.
Pointer:
In its most technical sense, it's the address (or position) of a variable in your computer's RAM (random-access memory). Generally, it can just mean the position of any particular number or variable. "Cell pointer" could be a literal pointer to look through an array very quickly. However, simply using it to find an index in an array is no different functionally and only extremely slightly slower than using a pointer.
Array:
Whereas "int number;" is a variable, "int number[64];" is an array of 64 variables. To reference one of these 64 variables individually, you reference them like "if ( number[22] == 0 )", where the 23rd (number[0] is the first) variable in the number[ ] array is the one being operated on.
Not exactly. Increment means an increase by a specific amount (usually by some quanta) whereas increase doesn't refer to any sort of value. Increment implies that there's a relevant quantity, increase does not. Same for decrement and decrease. Subtle and pedantic? Absolutely.