Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / script/parser

Author
Message
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 6th Jan 2003 05:54
Making a parser is much more difficult than i had anticipated Ive looked around but havent found much on the subject... Does anyone have a good tut or snippet offhand that you could relay to me? Thanks in advance
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 7th Jan 2003 01:27
or if anyone knows off the top of their head a descent way it would be greatly appreciated
Manson
21
Years of Service
User Offline
Joined: 20th Oct 2002
Location: Denmark
Posted: 7th Jan 2003 02:30
It depends what kind of scipt you're talking about,,,

I'm going to create con-file (anybody knows duke3d?) support for my game at some point, so I have a few thoughts on the matter

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 7th Jan 2003 03:02
well a script for an rpg.. heres the format i want, or something similar

"." would be spaces
//my script
DECLARE NEW CHARACTER
...TYPE 1
...TEXTURE Characters/char.bmp
...SIZE 10 10
;

DECLARE NEW MAP
...TEXTURE Maps/map.bmp
;

DO
...UPDATE EVERYTHING
LOOP
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 7th Jan 2003 05:52
ok, ive got most things sorted out, now its just a matter of one tiny problem..

POSITION CHAR 1 100 100

Ok, we have a position command, with numbers separated with a space. I need a function that will read this command, find the spaces, and put the differant words in differant arrays.. so lets have an array and the command already in one big string.



DIM words$(4)

mycommand$ = "POSITION CHAR 1 100 100"

now once this function is done with the array should have values as such:
words$(0) = "position"
words$(1) = "char"
words$(2) = "1"
words$(3) = "100"
words$(4) = "100"

then i can go in and convert the characters to numbers if i need to. I think this is very simple to do in theory, but I just cant get it to work in the program.. If anyone can figure it out I would be in your debt
Collector
21
Years of Service
User Offline
Joined: 6th Jan 2003
Location:
Posted: 8th Jan 2003 03:33
Hi,

Just a suggestion, but given the text manipulation stuff available in DB, I would follow the following procedure:

You can select each letter of a string using mid$(string$, position) by incrementing the position value in a loop.

As you take a character from the string, you can then test each character retrieved, by comparing it with the ASCII value - which you can get from the ASC() function.

Based on the result (probably best done with a select statement inside a loop) you can then parse the string, and based on various logic, save each segment into an array. You can copy the parsed section by cutting it with combinations of the left$(), right$() and/or mid$()function.

Hope that helps,

Cheers.

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 8th Jan 2003 08:43
yes i know what u mean, i just cant seem to get it to work, and it is exactly what i tried.. id post what i have so far, but im on a differant computer:/ thanx tho
Collector
21
Years of Service
User Offline
Joined: 6th Jan 2003
Location:
Posted: 9th Jan 2003 00:56
Hi again,

This is a bit quick and dirty but it should help ... its
customized somewhat to your example (no management of bad input or special characters etc) using the pseudocode approach above. You should be able to make it more robust. It runs by itself when copied and executed from DB.
Cheers.

rem declare word array
dim words$(4)
rem declare test string
mycommand$ = "POSITION CHAR 1 100 100"
rem declare looop variables
i=1
n=0
rem start loop
repeat
rem get character from string
ch$=mid$(mycommand$,i)
rem get the ASCII value for the character retrieved
ascval = ASC(ch$)
rem send it to function to return type
kind = det(ascval)
rem test the type in a select statement
select kind
rem creates a string of the letters
case 1: words$(n)= words$(n)+ ch$ :endcase
rem creates a string of the numbers
case 2: words$(n)= words$(n) + ch$:endcase
rem starts a new string
case 3: inc n : endcase
rem safety valve for the function ...
case 0: print "Special character"; " "; ch$ :endcase
endselect
inc i
until (i > len(mycommand$))
rem print out the parsed results
for p = 0 to 4
print words$(p)
next p
rem suspend for user
suspend for mouse
rem we're done
end

rem Returns a value for a character retrived
rem 1 = letter
rem 2 = number
rem 3 = space

function det(ascval)
rem is a letter?
if ((ascval>=65 and ascval=<90) or (ascval>=97 and ascval=<122))
exitfunction 1
endif
rem is a number?
if (ascval>=48 and ascval=<57)
exitfunction 2
endif
rem is a space?
if ascval=32
exitfunction 3
endif
endfunction 0

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 9th Jan 2003 07:21
oh oh thank you! and i was worried i wouldnt get an answer and it works perfectly too dont worry i can take care of any dirty parts when i go through it.. But thanks im in your debt
Collector
21
Years of Service
User Offline
Joined: 6th Jan 2003
Location:
Posted: 9th Jan 2003 09:07
My pleasure ...

Its a good karma feeling when you can help.

Good luck with the rest!



bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 9th Jan 2003 11:09
thanx^_^

Login to post a reply

Server time is: 2024-04-16 19:40:38
Your offset time is: 2024-04-16 19:40:38