I'm working on a BASIC interpreter for an OS (not mine) and I need to know how to chomp the first six (or any other number or) characters off of a string.
Example:
User types print "Hello, world!"
program chops off print (space removed as well)
program removes all "'s (have a syscall for that in MikeOS already)
program prints out the final string, Hello, world!
Cutting off the first 6 characters in a string
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Cutting off the first 6 characters in a string
What the **** are you doing on the forums?
Man, this should be easy...
OS-LUX V0.0
Working on...
Memory management: the Pool
Working on...
Memory management: the Pool
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Cutting off the first 6 characters in a string
Sorry, was half asleep at the time.
I'm doing this in 32-bit assembly, so it makes it a little harder.
That's what the **** I'm doing on the forums.
I'm doing this in 32-bit assembly, so it makes it a little harder.
That's what the **** I'm doing on the forums.
Re: Cutting off the first 6 characters in a string
Hi,
You end up with:
After you've done this you'd try to find the command name in a list of commands, and see if the number of parameters and the type of each parameter is acceptable.
Lastly, I'd recommend inventing some way to store the results from parsing so that if the same BASIC command is executed a second time you can skip the parsing and just use the previous results. That way you'll end up doing a lot less parsing in the middle of loops.
Cheers,
Brendan
No, you need to know how to parse a string and extract a command name and a list of parameters, so that for a string like:Troy Martin wrote:I'm working on a BASIC interpreter for an OS (not mine) and I need to know how to chomp the first six (or any other number or) characters off of a string.
Code: Select all
Foo 1, 0x1234567, "Hello" + ASC(13) + "there", bar
- Command: Foo
- Parameters: 4
- Parameter 1: Type = integer constant, value = 0x00000001
- Parameter 2: Type = integer constant, value = 0x01234567
- Parameter 3: Type = string, value = "Hello\nthere"
- Parameter 4: Type = variable name, value = "bar".
After you've done this you'd try to find the command name in a list of commands, and see if the number of parameters and the type of each parameter is acceptable.
Lastly, I'd recommend inventing some way to store the results from parsing so that if the same BASIC command is executed a second time you can skip the parsing and just use the previous results. That way you'll end up doing a lot less parsing in the middle of loops.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Cutting off the first 6 characters in a string
Code: Select all
string db "print something",0
cmd1 db "print"
cmd2 db "goto"
parser:
mov si,string
mov di,cmd1
mov cx,5
rep cmpsb
je printcalled
.... (more checks)
printcalled:
mov si,string
add si,6
;now si is pointing to the 's' in 'something'
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Cutting off the first 6 characters in a string
Source Code of a small basic intrerpreter : http://forum.osdev.org/viewtopic.php?f= ... +construct .
Regards
Sandeep
Regards
Sandeep