Cutting off the first 6 characters in a string

Programming, for all ages and all languages.
Post Reply
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Cutting off the first 6 characters in a string

Post by Troy Martin »

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!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Cutting off the first 6 characters in a string

Post by cr2 »

:? :?:

What the **** are you doing on the forums?

Man, this should be easy... #-o
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
Troy Martin
Member
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

Post by Troy Martin »

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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Cutting off the first 6 characters in a string

Post by Brendan »

Hi,
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.
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:

Code: Select all

Foo 1, 0x1234567, "Hello" + ASC(13) + "there", bar
You end up with:
  • 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".
You also need to handle syntax errors while you're doing this.

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.
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

Re: Cutting off the first 6 characters in a string

Post by kubeos »

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'
This isn't perfect but it should give you an idea of one way.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Cutting off the first 6 characters in a string

Post by DeletedAccount »

Source Code of a small basic intrerpreter : http://forum.osdev.org/viewtopic.php?f= ... +construct .


Regards
Sandeep
Post Reply