Every time I read Slava Pestov's blog, I think of Dawn, a small scripting language I wrote for Jext 4 or 5 years ago. Dawn is a RPN language and contains only two keywords, needs and needsGlobal, both of which are used to import modules. When a Dawn interpreter is instanciated by a program, it can load package files. A package file is a plain text file containing a fully qualified class name on each line, as in this example:
# dawn.loop package - Dawn package to handle loops (for, while...) org.jext.dawn.loop.DoLoopFunction org.jext.dawn.loop.ForFunction org.jext.dawn.loop.WhileFunction # End of dawn.loop package
The interpreter then looks up for each class and loads it by reflection. A Dawn function is created in Java either as a Function or as a CodeSnippet. A Function instance maps a Dawn name to Java code whereas a CodeSnippet maps a Dawn name to a Dawn snippet. Here is for instance how the rot function is defined:
public class RotFunction extends CodeSnippet
{
public String getName()
{
return "rot";
}
public String getCode()
{
return "3 roll";
}
}
By default, Dawn interpreter loads the following packages: array, err, io, javaccess, loop, math, naming, stack, string, test and util. You can easily load your own packages if you embed Dawn in an application. For instance, Jext loads the jext package which gives access to some parts of Jext to Dawn scripts. You can also create new functions directly in Dawn scripts rather than writing them with Java. Now, here is a full Dawn script which can read a Java file and count the number of real lines of code, stripping blank lines and comments:
#######################################
# JAVA PURE SOURCE CODE LINES COUNTER #
#######################################
# (C)2000 Romain Guy #
# Dawn demonstration #
#######################################
# tells if we're inside a wing comment
0 wing ->
# builds the array required to check comments
array
"//" addElement
"/*" addElement
"*/" addElement
comments ->
# gets file name from user's prompt
"Java source file: " print
inputLine dup sourceFile ->
# open the file
"SOURCE.FILE" openForInput
# inits variables
"" line ->
0 codeLines ->
# parses the source code
while "SOURCE.FILE" isFileAvailable repeat
"SOURCE.FILE" readLine
if depth 0 > then
# removes white spaces
trim line ->
# exits from wing comment
if wing rcl 1 == then
if line rcl comments rcl 2 elementAt swap drop endsWith then
0 wing ->
end
else
# if line begins with '//' we do not count it
if line rcl comments rcl 0 elementAt swap drop startsWith not
line rcl size 0 > and then
# checks if we're inside a wing comment
if line rcl comments rcl 1 elementAt swap drop startsWith then
line rcl comments rcl 2 elementAt swap drop startsWith not
wing ->
else
codeLines ++
end
end
end
end
wend
sourceFile rcl ":\t\t" concat codeLines rcl ->str " lines of code" concat concat println
# End of script
Now you know why I ceased developping Dawn, it is a pain to read code you wrote a long time ago. Yet, Dawn was very handy in Jext. RPN interpreters are very easy to develop, it tooks me less than 3 days to create the first interpreter and more than 100 of functions, and can be quite handy if you are looking for a small library. Dawn weighs about 100 kB in Jext. I use it to create user-driven templates, see the XInsert tree, and even plugins as in this example:
######################################################
# MAKE SCRIPT FOR JEXT # (C) 2000 Romain Guy #
######################################################
# Creates a new menu item which launch the make tool #
######################################################
"\".\" constructPath \"/Makefile\" concat if exists not then \"cd $n\" console end "
"\"make -C $d -f $n/Makefile\" " concat
"\"Make target:\\n\" input " concat
"dup if size 0 > then \" \" swap concat concat else drop end " concat
"console" concat
"Make"
"script.make"
dup ".shortcut" concat "C+m" setProperty
createAction
# End of script
Put your Dawn script in a file called Anything.jext-script, pack it in a jar and move it to your plugins directory. Quite easy isn't it? If you are interested in seeing more of Dawn, check out the package org.jext.dawn in Jext source code. You can also have a look at Jext's documentation to see the full list of available functions with descriptions.
Last but not least, I used Syxigh to colorize the examples. It is a small tool I wrote in VB to colorize source code in HTML, HTML/CSS, RTF and PDF. It uses XML-based syntax descriptions so you can easily add your own or modify the existing ones. Default syntaxes include C, C#, C++, Java, XML…
i was beginning to assume i may end up being the only young woman that thought about this, at the very least at present i learn im not outlandish :) i will make sure to look into some different blogposts when i get some caffeine in me, it really is very hard to read without having my coffee, I was unbelivably late last evening jamming zynga poker and after downing a few ales i finished up burning off all my facebook poker chips take care :)
Hey Guys you can get a 100% BONUS (upto $600!) ON Filltiltpoker with the following code.. “BONUSCODE69″ Just add it in the referral box when signing up.