Page 1 of 3 123>
Topic Options
#132349 - 2005-01-13 06:16 PM Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Has anyone done any KiX work on a KiX based syntax lexer FOR KiX? I know Jooel was working on a script to convert VBS to KiX, and I'd like to resume working on it. I know, I know... But my hands are tied...
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132350 - 2005-01-13 06:25 PM Re: Lexer for KiX
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hey Jim, good to see you back. You talking about something for syntax checking, or for conversion or both ? Jooel also did the PostPrep parser ... can look that one up.
Top
#132351 - 2005-01-13 06:38 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what is lexer?
what you mean for kix?

_________________________
!

download KiXnet

Top
#132352 - 2005-01-13 06:41 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Hey there Shawn! I pop in and out, just to keep an eye on things. =) When are you guys going to send us some snow down here. 64F in PA today... Damn snow blower is collecting dust.

I'm looking primariy to convert. As it seems, I'll need to check syntax in order to do that. Really not sure what I'm in for. Postprep hadn't occured to me, but that sounds like a great starting place.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132353 - 2005-01-13 06:42 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:


what is lexer?
what you mean for kix?




Syntax parser Kix.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132354 - 2005-01-13 06:50 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you looking for converting from kix or to kix?
_________________________
!

download KiXnet

Top
#132355 - 2005-01-13 06:52 PM Re: Lexer for KiX
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
idk - I think the VBS to KIX script would be your best starting point. Don't look directly into the PostPrep Kix2Html function - you'll go blind (I did).
Top
#132356 - 2005-01-13 06:54 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:

idk - I think the VBS to KIX script would be your best starting point. Don't look directly into the PostPrep Kix2Html function - you'll go blind (I did).




Too late! I don't know how he reads this stuff! =) I'll follow your second suggestion.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132357 - 2005-01-13 06:58 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:

so, you looking for converting from kix or to kix?




Jooel, looking to convert kix to vbs.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132358 - 2005-01-13 07:05 PM Re: Lexer for KiX
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
lonk has a lokenizer for his script... he writes it with real vars and tabs and spacers and such, then lonkenizes it to convert $temp to $!, $loop to $_, etc...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#132359 - 2005-01-13 07:10 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
lol! No household should be without a Lonkenizer 2000. It slices! It dices! ...And takes out the garbage!
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132360 - 2005-01-13 07:11 PM Re: Lexer for KiX
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
a lokenizer !!! roflmao
Top
#132361 - 2005-01-13 07:12 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sometimes maybe, but normally I just start with $ and go on from there with $_, $! $1, $2, $a, $b and so on.
_________________________
!

download KiXnet

Top
#132362 - 2005-01-14 06:08 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
This sucks. Here's what I've got so far. Anyone bored to tears feel free to pitch in.

Code:
 ; Based on Jooel's VBS2Kix Script

Break On
Kix2VBS("test.kix","test.vbs")

function Kix2VBS($src,$dst)
dim $file,$,$Counter,$LineLength,$String,$t,$u,$Character
$file=freefilehandle
if not $file
exit 1
endif

$=open($file,$src)
if @error
exit @error
endif

$=readline($file)
redim $src
while @error=0
$u=ubound($src)+1
redim preserve $src[$u]
$src[$u]=$
$=readline($file)
loop
$=close($file)

$file=0+freefilehandle
if not $file
exit 1
endif

if exist($dst)
del $dst
endif

$=open($file,$dst,5)
if @error
exit @error
endif
redim $dst[$u]

for $=0 to $u
$Line=$src[$]
? "Line: >"+$Line+"<"
$String=""
$Counter=0

$Line=Replace($Line, "@@Error", "Err.Number")
$Line=Replace($Line, "@@SError", "Err.Description")
$Line=Replace($Line, "EndIf", "End If")
$Line=Replace($Line, "EndFunction", "End Function")
$Line=Replace($Line, "$$", "var")
$Line=Replace($Line, "?", "wscript.echo")

? "Line: >"+$Line+"<"
$LineLength=len($Line)

for $Counter=1 to $LineLength
$Character=substr($Line,$Counter,1)
;? "Current beginning char is >"+$Character+"<"
select
; Strings encased in dbl quotes
case $Character='"'
$String=$String+$Character
do
if $Counter>=$LineLength
$dst[$]=$String
$=$+1
$Line=$src[$]
$String=''
$Counter=0
$LineLength=len($Line)
endif
do
$Counter=$Counter+1
$Character=substr($Line,$Counter,1)
$String=$String+$Character
until $Character='"' or $Counter=>$LineLength
until $Character='"' or $=$u

; Spaces
case $Character=" " or $Character=" "
$String=$String+$Character

; Concantenation Char
case $Character="+"
$String=$String+"&"

; Comments
case $Character=";"
? "Found comment"
$String=$String+"'"

case 1
$t=""
$bitDQ=0
$bitSQ=0
$TTP=""

;? "LL "$LineLength
;? "CT "$Counter
For $i=1 to $LineLength
$Char=Substr($Line,$i,1)
;? "Char>"+$Char+"<"
$TTP=$TTP+$Char
Select
; Apostrophe
;1=DQ active
;2=DQ master
;4=SQ active
;8=SQ master

;3=DQ active master
;7=DQ active master, SQ active lesser
;12=SQ active master
;13=SQ active master, DQ active lesser

Case $Char="'" and $bitDQ=1 and $bitSQ=1

Case $Char='"' and $bitDQ=0 ;out of a dq block
$bitDQ=1
? "Entering a DQ string>"+$TTP+"<"

Case $Char="'" and $bitSQ=0 ;out of a sq block
$bitSQ=1
? "Entering a SQ string>"+$TTP+"<"
Case $Char='"' and $bitDQ=1 ;in a dq block
$bitDQ=0
? "Exiting a DQ string>"+$TTP+"<"
Case $Char="'" and $bitSQ=1 ;in a sq block
$bitSQ=0
? "Exiting a SQ string>"+$TTP+"<"
Case 1

EndSelect
Next

do
$t=$t+$Character
$Counter=$Counter+1
$Character=substr($Line,$Counter,1)
until $Counter=>$LineLength+1;instr(" ",$Character);
$Counter=$Counter-1

? "T is >"+$t+"<"

select
case $t="_" or $t="then" or $t="wscript.echo"

; Remove Break On
case Substr(Ltrim($t),1,8)="Break On"
$t=Replace($t,"Break On","")
$String=$String+$t ;+" ' VBC: Removed Break On"

; Global to Dim
case Substr(Ltrim($t),1,6)="global"
$t=Replace($t,"global","Dim")
? "G"
? "T is Now>"+$t+"<"
$String=$String+$t+" ' VBC: Converted from a global"

; Add Set to objects
Case instr($t,"CreateObject") or instr($t,"GetObject")
$String=$String+"Set "+$t

; Handle Optionals
Case Substr(Ltrim($t),1,8)="Function"
; While Instr($t,"Optional")<>0
; $pstart=Instr($t,"Optional")
; $parm=Substr($t,$pstart)
; $parm=Trim(Substr($t,9))
; ? "parm>"+$parm+"<"
;
; Loop

;If Not IsNull(optViewOutput) Then
;End If
$String=$String+"dim"

case $t="set"
do
$Counter=$Counter+1
$Character=substr($Line,$Counter,1)
until $Character<>" " and $Character<>" "
$Counter=$Counter-1
$String=$String+"$$"

case $t="quit"
$String=$String+"wscript.quit"

case $t="not 0"
$String=$String+"true"

case $t="not 1"
$String=$String+"false"

case $t+substr($Line,$Counter,3)="endif"
$String=$String+"end if"

case 1
$String=$String+$t
endselect
endselect
next
$dst[$]=$String
next

for $=0 to $u
$Counter=writeline($file,$dst[$]+@crlf)
next

endfunction


; Function Replace()
;
; Author Randy Watson (aerathistorm@yahoo.com)
;
; Action Replaces first or all occurrences of one string with another
;
; Syntax Replace(Source, SearchString, ReplaceString, First, CaseSensitive)
;
; Parameters
; Source
; String to search
; SearchString
; String being replaced
; ReplaceString
; New string
; First (Optional)
; Pass the value 1 to replace only first occurrence. Default is replace all.
; CaseSensitive (Optional)
; Pass the value 1 to turn on case sensitivity. Default is off.
;
; Returns
; Returns the new string.
;
; Remarks
;
;
; Dependencies
; None
;
; Example(s)
; Replace all occurences of a non case sensative string with another:
;$StringSource = "Three Apples + four apples makes seven apples"
;$StringSearch = "apple"
;$StringReplace = "orange"
;$StringReplaced = Replace($StringSource, $StringSearch, $StringReplace)
;? "Original string: $StringSource"
;? "New string: $StringReplaced"
; Replace only the first case sensative occurrence:
;$StringReplaced = Replace($StringSource, $StringSearch, $StringReplace, 1, 1)
;? "Original string: $StringSource"
;? "New string: $StringReplaced"; Source:
;Exit
Function Replace($SourceString, $SearchString, $ReplaceString, Optional $First, Optional $CaseSensitive)
Dim $String1
Dim $String2
Dim $Finished $Finished = 0
$Counter = 0
$String1 = $SourceString
If $CaseSensitive
$PreviousState = SetOption("CaseSensitivity", "On")
EndIf
While Not $Finished
$String2 = $String1
$Location = InStr($String1, $SearchString)
If $Location > 0
$String1 = Substr($String1, 1, $Location - 1) + $ReplaceString + Substr($String1, $Location + Len($SearchString))
Else
$Finished = 1
EndIf
If $First
$Finished = 1
EndIf
If $String1 = $String2
$Finished = 1
EndIf
Loop
$Replace = $String1
$Nul = SetOption("CaseSensitivity", $PreviousState)
EndFunction


_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132363 - 2005-01-14 06:31 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hehee.
the problem you are gonna face is that kixtart is freeform language.
you can't trust that someone writes:
Code:
writeline(1,"blaah")



when he can do:
Code:
writeline(1,"blaah" +
"blaah blaah" +
"blaah,
blaah, blaah blaah")

_________________________
!

download KiXnet

Top
#132364 - 2005-01-14 06:48 PM Re: Lexer for KiX
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
kix to vbs will be quite a pain to write, since vbs is lacking all of the built-in functionality of kix. kix on the other hand, can handle just about all of the objects that vbscript does, so to go from vbs to kix is more of a syntax change than anything else.

For example, how would plan on converting say

$ = writevalue(\\computer\hklm...)

to vbscript. you'd probably have to recognize that you're writing to a remote computer, which i think in vbscript would basically require you to create a wmi regprov object and then use it's properties and methods...

And that's only one example of many - other built-in functions, commands and macros. Good luck with all of that! but i don't think i'll ever be that bored
_________________________
Eric

Top
#132365 - 2005-01-14 07:10 PM Re: Lexer for KiX
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
good points, I would suggest that if your serious about this, you could "pass-through" these non-standard function calls directly to vbs, so for example writevalue in kix:

$ = writevalue("\\computer\hklm...")

would simply move to vbs like this:

writevalue("\\computer\hklm...")

then, you can have a library of vbs functions, that get "included" into the bottom of your converted script, that would handle these calls. I wouldn't suggest you do this for ALL the functions, just the ones that are "odd" and can't be converted to easyily ... hmmm, seems like much work.

Top
#132366 - 2005-01-14 07:21 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not that much.
but it will indeed be quite bloated system.
_________________________
!

download KiXnet

Top
#132367 - 2005-01-14 07:30 PM Re: Lexer for KiX
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jim,
I see from your avatar that you won't be pulling your hair out trying to get this to work cuz the whole free-form thing could result in some serious hair pulling.
Then there is the blasphemy of converting away from KiX. tsk, tsk
In the old days, you would be burned at the stake or at the least sentenced to eternal damnation.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#132368 - 2005-01-14 10:27 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
All good points. To Jooel's point regarding freeform, I just about gave up yesterday when I tried figured out how to parse KiX's ability to
$ret=shell('cmd /c CD "\My Folder\Jim's Stuff" & Dir /b & Pause')
...Emphasis on the apostrophe and that doesn't even cover multiline strings.

To Maciep's point, there is just some stuff it's not worth converting, such as Select Case statements where the methodolgy behind the command is completely different. In those cases I'm just going to slap a comment at the end of the line stating that it needs a manual approach.

Shawn, I'm way ahead of you buddy. I started a project on SF to do exactly that. vbscript.sf.net

But I am going to do everything: commands, functions, macros and selected udf's. The CVS is mess and I have a ticket in for complete removal so I can start clean. Check back next week sometime. I'm just about finished with the commands and am moving on to functions as we speak. My intent is to have a library to emulate kix in vbs do to vbs sucking so hard. (For instance, the Set commands (set,setm,setl) are proving a bit difficult to convert cleanly...)

Les, my dr. evil avatar is far from my actual appearance (unfortunately for me) and the hair pulling is in full stride. The great thing about using VBScript is that you actually learn to despise it once you start using it a lot hence my need to create a "KiX like" experience. My hands are tied.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
Page 1 of 3 123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.078 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org