Dialect Language Reference - Fama

Sep 14, 1999 - This reference document describes the complete Dialect language in its current state. .... So to get the fifth element of an array you could write x = myArray[5], or to set it ...... Of course, you can also call these functions explicitly:.
519KB taille 1 téléchargements 361 vues
Dialect Language Reference

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333 330-668-2267

Aristar, Inc.

Dialect Language Reference

Page 2

Dialect Language Reference Index Introduction to Dialect................................................5 Different Versions of Dialect..........................................6 Dialect Standard............................................................................................................................6 Dialect Professional.......................................................................................................................6 Technical Support for Dialect..........................................6 Miscellaneous Details..................................................7 Chapter 1—Data Types...................................................8 Chunks.........................................................................................................................................10 Functions.....................................................................................................................................11 Classes........................................................................................................................................12 Class Instance.............................................................................................................................13 Properties....................................................................................................................................14 Chapter 2—Expressions.................................................15 Chapter 3—Statements..................................................16 Assignment..................................................................................................................................16 Array Style Assignment................................................................................................................16 Break...........................................................................................................................................16 Continue.......................................................................................................................................16 Debug..........................................................................................................................................16 For..EndFor..................................................................................................................................16 ForEach..EndForEach.................................................................................................................17 If…...EndIf............................................................................................................17 Import...........................................................................................................................................18 Interpret.......................................................................................................................................18 Local............................................................................................................................................18 Print..............................................................................................................................................18 Return..........................................................................................................................................19 Run..............................................................................................................................................19 Throw...........................................................................................................................................19 Try....EndTry......................................................................................................19 While..EndWhile..........................................................................................................................19 With..EndWith..............................................................................................................................19 Chapter 4—Core Functions..............................................20 Chapter 5—File Handling...............................................25 File class members......................................................................................................................25 File class static members............................................................................................................26 Chapter 6—Scripts and Modules.........................................27 Run..............................................................................................................................................28 Import...........................................................................................................................................28 Outputs Module........................................................28 Exceptions Module.....................................................31 Throw...........................................................................................................................................31 Try....EndTry......................................................................................................31 Crypto Module.........................................................33 MD5 Class...................................................................................................................................33 SHA1 Class.................................................................................................................................33 Blowfish Class.............................................................................................................................33 DiffieHellman Class.....................................................................................................................33 Socket Module.........................................................35 Socket module functions.............................................................................................................35 Socket class members................................................................................................................35 Math Module...........................................................38 System Module.........................................................39 System Module Functions...........................................................................................................39 Sleep(milliseconds)..................................................................................................................39 ParseTime(dateTimeString).....................................................................................................39 Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 3

Createdate$(year, month, day, hour24, min, sec)...................................................................39 CompareTime(dateTime1, dateTime2)...................................................................................39 Exec(filename, ).........................................................................................................39 Status(processID)....................................................................................................................39 Ticks()......................................................................................................................................39 Seconds().................................................................................................................................40 PlaySound(filename, )................................................................................................40 OpenRegKey(keyString, bCreateOK)......................................................................................40 Regkey(keyString)....................................................................................................................40 The Regkey class methods......................................................................................................40 ComPort Class (serial port access).............................................................................................41 DLL Class....................................................................................................................................41 ADO Database Module...................................................44 The Connection Class.................................................................................................................44 The Recordset Class...................................................................................................................44 The Fields Class..........................................................................................................................46 The Field Class............................................................................................................................46 Predefined ADO Constants.........................................................................................................46 ObjectStateEnum (Not under WinCE).....................................................................................46 CursorTypeEnum.....................................................................................................................47 LockTypeEnum........................................................................................................................47 CommandTypeEnum...............................................................................................................47 AffectEnum (not under WinCE)...............................................................................................47 PositionEnum...........................................................................................................................47 SearchDirectionEnum (not under WinCE)...............................................................................47 StringFormatEnum (not under WinCE)....................................................................................47 Bookmarks (not under WinCE)................................................................................................47 RecordStatusEnum (not under WinCE)...................................................................................47 DataTypeEnum........................................................................................................................48 GUI Module............................................................50 GUI Module Functions.................................................................................................................50 Enter()......................................................................................................................................50 Exit().........................................................................................................................................50 ScreenRect()............................................................................................................................50 MsgBox(window, message, title, mbType)..............................................................................50 MousePos()..............................................................................................................51 PopupMenu(window, x, y, menuArray)....................................................................................51 FileOpenDlg(parent, filename, ext, types)...............................................................................51 FileSaveAsDlg(parent, filename, ext, types)............................................................................51 GUI Module Classes....................................................................................................................52 Window(text, rect, )........................................................................................52 Button(parent, text, rect, )..............................................................................53 Calendar(parent, initDate, rect)................................................................................................53 CheckBox(parent, text, rect)....................................................................................................54 ComboBox(parent, rect, )..............................................................................54 Edit(parent, text, rect, )..................................................................................55 Grid(parent, rect, numRows, colWidthsArray, ).............................................55 Layout(parent, rect, layoutFrame, dataFrame, )............................................57 Listbox(parent, rect, ).....................................................................................57 Menubar(parent, rect, menuArray, )..............................................................58 Note(parent, text, rect, ).................................................................................59 Pane(parent, rect, )........................................................................................59 Radio(parent, text, rect, )...............................................................................60 Scrollbar(parent, bHorz, rect, rangeMin, rangeMax, pageSize)...............................................61 Chapter 7—Regular Expressions.........................................62 Regex class members.................................................................................................................62 Using regex.replace()..................................................................................................................65 Using regex.match.......................................................................................................................65 Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 4

Chapter 8—Trouble Shooting and Your IDE...............................67 Things to Avoid.......................................................67 Recursive data structures............................................................................................................67 Invoking a “non-static” class member function by calling directly into the class (i.e. not calling from a class instance)..................................................................................................................67 Invoking class member functions after a class (or class instance) has been garbage collected.... 68 Integrated Development Environment Overview...........................69 Debugging...................................................................................................................................69 Making executables.....................................................................................................................69 Sample Scripts........................................................70 GUI Calendar Sample..................................................................................................................70 GUI POP3 Email Reader.............................................................................................................71 Sending Email via SMTP.............................................................................................................75 Double Echo Socket Server........................................................................................................77 Simple Text File Editor.................................................................................................................78 Date/Time Parser Using Regular Expressions............................................................................81 QuickForm - Displaying Layouts..................................................................................................83 ADO Rolodex Sample..................................................................................................................85

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 5

Introduction to Dialect The Dialect language originated as a version of the Basic language. The Basic roots give Dialect a simple to learn syntax and a good set of basic functions. For example, to print some text you might code something like: print "Hello world" To print the numbers from one to ten, you could write: for x = 1 to 10 print x, cr endfor In the above example cr stand for carriage return, telling the print statement to start a new line of text. To the Basic core we added special features to make it capable of handling database and data processing tasks. For example, to record information about John Doe you could do the following: johnDoe = {age:27, eyeColor:"Brown"} Later, if you need to print John Doe‘s age: print "John Doe is ", johnDoe.age, " years old" Or, you could store the information in a text file: file.save("JohnDoe.txt", johnDoe, 'ascii) You could then read back the information at a later time: johnDoe = file.load("JohnDoe.txt") Because of its simplicity, Dialect is extremely useful for writing small utility programs. Of course, sometimes you need more than just a simple utility program. For that reason, Dialect also supports advanced programming techniques such as functions, external modules, object-oriented classes, and regular expressions. Dialect currently runs under Windows 9x/NT and Windows CE 2. A modified version of Dialect, sans a few features, has been compiled under Linux and might be made available at a later date.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 6

Different Versions of Dialect This reference document describes the complete Dialect language in its current state. There are, however, several versions of Dialect. Some of these versions lack certain features as described below.

Dialect Standard Dialect Standard does not contain the ADO database module. Dialect Standard is free for personal, academic, and other not-for-profit uses.

Dialect Professional Dialect Professional contains all the functionality described in this reference. Demo versions of Dialect Professional may not contain the ability to generate stand-alone executables. Also, appropriate licenses must be purchased to use Dialect Professional in a commercial environment and to create commercial applications (including shareware).

Technical Support for Dialect Dialect is written and maintained by Aristar, Inc. Technical support is currently handled via email using the following address: [email protected] As time passes and as necessity dictates, we plan to support FAQ sheets accessible from our web site: http://www.aristar.com

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 7

Miscellaneous Details 

Dialect is case insensitive with regard to keywords and identifiers; thus: MyFrame = myframe = MYFRAME



The end of line (i.e. carriage return) is significant and expected at the end of every statement. The backslash character, \, may be used to continue the current line on the next line. The backslash character must be immediately followed by an end of line (by hitting ENTER or RETURN). Thus not even comments may follow a backslash character. OK:

x = 5 + 6 + 7 + \ 8 + 9 + 10 # Adding some numbers

ERROR:

x = 5 + 6 + 7 + \ 8 + 9 + 10

# Adding some numbers



Programmers familiar with C/C++ should note that memory management is accomplished with automatic garbage collection, relieving the programmer of the chore. When data is no longer referenced by any variable, Dialect frees the memory of that data. If the data is a class instance, then Dialect first calls the destructor for that class (i.e. the __del__ function) if it exists.



A frame called global is shared by all modules and can be used to store common data. For example, Dialect places some environment data in global.__environ__. So to display a dialog box giving the version of Dialect, you could use the following code: message(global.__environ__.version)



To execute a script from the command line, use the -run flag followed by the name of the script. For example: Dialect.exe -run D:\scripts\myScript.d In the event the script path or filename contains spaces, then be sure to surround the name in double-quotes.



Comments are notes a programmer leaves for himself in the code for future reference. When the time comes to modify a piece of code, and it will, without comments the programmer must reread every single line to find the line which needing modification. Dialect allows three types of comments: o Block comments may span multiple lines of code. Like block comments in the C language, a block comment begins with /* and ends with */. o Line comments tell Dialect to ignore everything to the right of the // comment marker, up to the end of line. This works the same as the C++ line comment. The # symbol may also be used to mark the beginning of a line comment. o Persistent comments are designed to survive compilation and serialization, unlike block and line comments that are removed during normal compilation. Persistent comments must be the only item on a line of code and are signified by two leading backward slashes, \\, not to be confused with the line comment which uses two forward slashes.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 8

Chapter 1—Data Types In Dialect, all information can be classified as belonging to one of two data types divided according to how they are held in memory. “Pass by Value” data types enjoy a simple one-to-one relationship between variables and their contents. “Pass by Reference” data types identify a reference point which in turn identifies other sources of information. Pass by Value

Pass by Reference

Integer Floating Point Boolean String Array Frame Symbol Chunk Function Class

Special

5 3.14159 true, false "Hello World" ["hello", "world", 5] {key:"Value", x:42} 'Fruit [:{encoding:"hex"}, "2DF4587E":] F = func() endfunc Class Ident EndClass X = myClass() nil P = prop(init, readFunc, writeFunc)

Class Instance Void Property Note that Elements within < > are optional.

Data is stored in named symbol tables. Only three forms of symbol table are possible for the resolution of a variable: module/script, class object, and function. Generally speaking, Dialect can not look outside a specific environment to resolve a variable. Thus a function could only see variables local to itself, local to the module in which it was declared, and local to its parent class if it belongs to a class object. Moreover, if a function is declared within another function, it will not see the encapsulating function’s local symbol table.

Integers

Integers are 32-bit signed numbers, the ones we learned to count with stones or cows. When evaluated as a Boolean value, zero returns false and all other values return as true.

Floating Points

Dialect uses IEEE 32-bit floating-point numbers, that is a string of numbers containing a single decimal point. All floating-point numbers must have at least one digit to the left of the decimal point. That digit may be zero (0). When evaluated as a Boolean value, 0.0 returns false and all other values represent true.

Boolean The keywords true and false are used to represent the two Boolean states. In Boolean logic, a thing either “is” or “is not,” the binary condition essential to digital existence.

Strings A string may hold zero or more characters and is defined using quotation marks as in: x = "This is a string" Two strings can be added using the + operator. The length of a string equals the number of characters in the string and can be determined using the len() function (see Core Functions). Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 9

Individual characters of a string are accessible using the bracket operator. To get the fifth character of a string and place it into the variable x, you could write x = myString[5]. To extract a range of characters from a string, use the range operator inside the brackets. Where a negative number in the range is interpreted as indexing from the end of the string to the front. To extract the substring containing the third through the fifth characters: x = myString[3 -> 5]. When evaluated as a Boolean value, the empty string returns false, while all other strings return true. When inside a double-quoted string expression, accent marks, `, are converted into quotation marks. message("Say `Goodnight, Gracey`") message("Goodnight, Gracey")

Arrays Arrays hold zero or more elements and are designated by square brackets, [ ]. Elements are separated by commas. Each element can be of a different data type, including another array. The length of an array is equal to the number of elements it contains, which can be determined using the len() function. When evaluated as a Boolean value, arrays always return true. There are two methods of creating arrays. Method one: x = ["a", "b", "c"] Method two: x = array(3) Elements of an array are accessed using the bracket operator. The first element in an array is at index 1, not zero. So to get the fifth element of an array you could write x = myArray[5], or to set it write myArray[5] = 23. Since a multi-dimensional array is simply an array of arrays, elements are accessed using multiple bracket expressions. If myArray is a two-dimensional array, you would get the value of row 6, column 2 in the following manner: x = myArray[6] [2]. If you need to get a series of elements from an array, you can specify a range between the brackets using the range operator -> . For example, to get an array that contains the fifth, sixth, and seventh elements of an array, you could write x = myArray[5 -> 7]. If a negative integer is used in describing a range, it is interpreted as indexing from the end of the array to the front. So, myArray[4 -> -1] would return all the elements starting at the fourth and ending at the last. Two arrays can be joined together to create a single larger array using the concatenation operator, ~ [1, 2, 3] ~ [4, 5, 6] results in the array [1, 2, 3, 4, 5, 6].

Frames

Frames store data by equating a string, which becomes the frame’s localized key, to a value. Thus a frame is essentially a storage system of key-value pairs, often called “hash tables” or “dictionaries”. A frame key must be a string (ex. x or myVariable), while the value can be of any data type. Frames are created using curly braces, {}. To set the variable x to an empty frame: x = {}. To create a frame with two initial key-value pairs, also known as slots, separate the values by commas (ex. myFrame = {age:27, eyeColor:"Brown"}, or, myFrame = {"age":27, "eyeColor":"Brown"}). Values are retrieved from a frame using either the dot or bracket operator. Thus both x = myFrame.age and x = myFrame["age"] yield the value 27. If a key is referenced that doesn't contain a value, the result will be nil. Once a frame has been created, new slots can be added using the same operators: myFrame.hairColor = "Blonde", or, myFrame["hairColor"] = "Blonde". To completely remove a slot from a frame, use the remove function. For example: remove(myFrame, "hairColor")

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 10

Two frames can be combined using the concatenation operator. If a key exists in both frames, then the value contained in the right operand is used in the result. For example: {a:1, b:2} ~ {b:3, c:4} results in the frame {a:1, b:3, c:4}. When evaluated as a Boolean value, all frames return true.

Symbols A symbol is any valid identifier preceded by a single quote. For example, 'imaSymbol_123. Symbols are case insensitive.

Chunks A chunk is a contiguous block of memory. It is similar to an array in concept, but is more efficient than an array when dealing with binary-type data. Chunks are declared using the [: and :] bracket symbols. Contained within the brackets must be a frame and a data item. The frame contains options for the chunk. The data item represents the data to be stored in the chunk. The frame may contain the following slots:  encoding: If the data item is a string, then the encoding type tells Dialect how to convert the string into binary data. Whenever the chunk is represented as a string, using the str$() function for example, Dialect will convert the data into a string using the specified encoding type. The three currently supported types are "hex", "base64", and "ascii". If not specified, "base64" is used as the default since it is more efficient than hexadecimal.  itype: Specifies the index type of the chunk. This is explained more thoroughly below. If not specified, the itype defaults to ui1 (an unsigned, one-byte integer).  dim: Specifies the length of each dimension of the chunk. Currently only onedimensional chunking is supported. Therefore, if specified, dim must be a positive integer. Dim is only required if the data item is nil, since Dialect will need to know how much memory to allocate. If not specified and the data item is not nil, then Dialect will allocate enough memory to store the decoded data item. The actual number of bytes allocated is the number of bytes required for the itype multiplied by the value provided for dim. The data item used to construct a chunk can be one of the following types:  string: If the data item is a string, then the encoding type given above is used to convert the string into binary data.  chunk: If a chunk is the data item, then the returned item will be the same chunk except the options may be different. This is how to change a chunk from "hex" to "base64" encoding, for example.  nil: If nil is given, then the chunk will be created with the size specified in the dim slot of the options frame and all its elements will be initialized to zero. Elements of a chunk are accessed using the bracket operators. So to get the fifth element of a chunk and assign its value to x, you would write: x = myChunk[5]. An element of a chunk is a number. The type of number, and how many bytes of the chunk are used to determine the number, is dependent upon the chunks itype property. The following is the list of currently supported itypes:  i1: One-byte signed integer  i2: Two-byte signed integer  i4: Four-byte signed integer  ui1: One-byte unsigned integer  ui2: Two-byte unsigned integer  f4: Four-byte floating point The itype for a chunk can be changed at anytime, although if a the byte-size of a chunk is not an even multiple of the byte-size of the itype, the remaining bytes will not be accessible until the itype Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 11

is changed back to an exact multiple. For example, if a chunk has 7 bytes of data and the itype is set to i4, then only the first four bytes will be accessible (and the len() function will return a length of one for the chunk). Also be aware that the byte order is machine specific for multi-byte numbers. Example: x = [:{encoding:"hex", itype:"ui1"}, "C365172E9501E2":] print "The hex string: ", x, cr print "Number of bytes: ", len(x), cr foreach byte in x print format("%.2X", byte), cr endforeach x = [:{itype:"ui2"}, x:] # Change the itype for x print "Number of two-byte integers: ", len(x), cr for idx = 1 to len(x) print format("%.4X", x[idx]), cr endfor Chunks may be serialized and cloned. When evaluated in a Boolean context, chunks always return true. A file opened for binary reading will return a chunk when read.

Functions A function is a group of statements that are executed by a function call. A function is declared starting with the func keyword and ending with the endfunc keyword. Example: factorial = func(x) if x < 2 then return 1 endif return x * factorial(x - 1) endfunc message("5! = " + str$(factorial(5))) In this example, we declare a function that computes the factorial of a number. The function uses the return statement to pass back the result of its computations. If the return statement is omitted or if there is no expression following the return keyword, then the return value defaults to nil. To execute a function, use the parenthesis operators. Place function arguments within the parenthesis and separate them with commas. Dialect will replace the functions declared parameters with the supplied arguments. So in the above example, when factorial is first executed in the message function, the value 5 is assigned to the variable x within the function. Notice also that message and str$ are core functions in Dialect. Message displays a dialog box and str$ converts data, in this case an integer, into a string. If function A is executed from inside another function, B, then function A will not see function B's local symbol table. This is true even if function A was declared inside function B. A function can only resolve variables in the following symbol tables (from greatest precedence to least): its own local symbol table, its class symbol table (if it's a class member), and the symbol table of the module in which it was declared. Therefore, if you must create a recursive function, a factorial for instance, inside another function, then the recursive function will need to take itself as an argument.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 12

Example: MyFunc = func() factorial = func(x, f) if x < 2 then return 1 endif return x * f(x - 1, f) endfunc message("5! = " + str$(factorial(5, factorial))) endfunc MyFunc() # Invoke the function Use the local statement to guarantee a variable used in a function resides in the function's local symbol table and won't read or modify a module or class variable. For more information on Core Functions, see Chapter 4.

Classes Dialect uses classes to support object-oriented style programming. A class is a data structure that can contain functions and other data objects. Dialect does not support multiple inheritance. If a class contains a function named __init__, then it is called when constructing an instance of the class object. If the class contains a function named __del__, then it is called when the class instance is garbage collected. The __init__ function may take zero or more arguments, while __del__ may take no arguments. The __init__ and __del__ functions are not intended to be called explicitly. The one exception to this rule is calling a base class’s constructor using inherited, since Dialect will not call an inherited constructor unless you specifically tell it to do so, or if the derived class being instantiated did not declare an __init__ function of its own. Inherited destructors are automatically called during object destruction from the top down. That is, the base class destructor is always called last. If an exception is thrown (see Exception Handling in Chapter 6) from inside the class constructor, then the destructor for that class will not be called. Therefore, if you are going to throw an exception inside the __init__ function, make sure you clean up first. Class base refCount = 0

// Shared data

__init__ = func() refCount = refCount + 1 message("Base class constructor") endfunc __del__ = func() refCount = refCount - 1 message("Base class destructor") endfunc EndClass Class vehicle(base) // Vehicle inherits from base __init__ = func(make) inherited.__init__() // Not required this.make = make message("Constructing a " + make) endfunc Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 13

__del__ = func() message("Destructing a " + this.make) endfunc getMake = func() return this.make endfunc EndClass Message("Vehicle count = " + str$(vehicle.refCount)) myCar = vehicle("Porsche") //Construct a vehicle hisCar = vehicle("Dodge") //Construct another Message("Vehicle count = " + str$(vehicle.refCount)) myCar = nil //Allow garbage collection hisCar = nil //Allow garbage collection Message("Vehicle count = " + str$(vehicle.refCount)) In this example, notice that to inherit from a higher order class, place the name of the base class within parenthesis after the name of the new class. Here, the class vehicle is derived (inherits) from the class base. Once a class instance is constructed, it contains a symbol table called this. The this symbol table is unique for each class instance and is used to store data unique to the class instance. In the above example, we stored the make of the car in the this symbol table. In the function getMake, we access the this symbol table to return the make of the vehicle. It’s very important to realize that if we had called getMake on the vehicle class, not the class instance we created, then the this symbol table wouldn’t exist and an exception would occur. myCar.getMake() vehicle.getMake()

// Returns "Porsche" // Error

Also notice the use of inherited in vehicle’s constructor. To call a base class function that you have overridden, use inherited to qualify the function name. If the function wasn’t overridden, then inherited is not necessary, as Dialect would use the inherited version anyway. All of a class’s data variables are shared by all instances of that class. They act like static members of a C++ class. Remember, it’s the this symbol table that stores data unique to a class instance. So in the above example, refCount is shared by all class instances. If our Porsche sets refCount to 32, then our Dodge will also see the value of refCount to be 32. It might not be immediately obvious, but class member functions are simply static shared data values. It’s the this that makes them special. The type of a class instance can be determined at runtime in two ways. The first is by using the type function. The second is by using the isa expression operator. Notice that type returns the name of the class that was instantiated, while isa is also capable of determining if a class instance is based on a class derived from another class. myCar = vehicle("BMW") type(myCar) -> "vehicle" myCar isa vehicle -> true myCar isa base -> true myCar isa fruit -> false

Class Instance Creates an object which will inherit properties from the parent class.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 14

Properties Properties are unique in that they are objects that allow the programmer to control access to a data value. Each property contains a single value of any valid Dialect data type. A property may also contain a read function and a write function. Both functions are not required, but at least one should exist or else you probably don’t need to be using a property variable. Properties are typically used in classes, but they can be used anywhere. The read function for a property must take exactly one argument. Dialect uses this argument to pass the current value of the property to the function. The value which the read function returns to the caller is perceived as the property’s value, regardless of its current internal property value. Note that the property value is not actually changed. That is reserved for the write function (below). The write function for a property must take exactly two arguments. The first argument is the current value of the property. The second argument is the value attempting to be assigned to the property. The property’s new value is the return value of the write function. If the read function is set to nil then a property returns its value immediately. If the write function is set to nil, then an assignment to the property sets the value immediately. A property is created using the prop function. The first argument of the function is the initial value of the property. The second argument is the read function, which may be nil. The third argument is the write function, which may also be nil. Example: readFunc = func(currentValue) // We will return the absolute value if currentValue < 0 then return –currentValue else return currentValue endif Endfunc writeFunc = func(currentValue, newValue) // Let’s only accept integer values if newValue isa integer then return newValue else // We could throw an exception here return currentValue endif Endfunc P = prop(5, readFunc, writeFunc) Print P, cr P = -7 Print P, cr

// Prints the number 5 // Assigns the value –7 to P // Prints the number 7 (not -7)

nil Lastly, nil is not really a data type per se. Nil is used to denote the absence of data, similar to NULL in C/C++. When evaluated as a Boolean value, nil always returns false.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 15

Chapter 2—Expressions Expressions are used in manipulating data. Be sure not to confuse the Boolean comparison operator with an assignment statement though both can be denoted by means of the equal sign, =. The distinction is drawn by means of the context in which the equal sign is used. Unlike in C, Dialect does not allow assignments to occur within an expression. Dialect supports Boolean short-circuiting of the and and or operators. If the result of a Boolean expression can be determined without further evaluation, evaluation stops. Example: x = true or foo() Since x will always be assigned the value true, no matter if the function foo returns true or false, Dialect sets x to true immediately without executing foo. Similar logic dictates that y, in the following example, will always be assigned the value false. Therefore Dialect does not execute foo. Example: y = false and foo() Operator Precedence: Lowest

Highest

?:

Ternary conditional (three operands)

= == >
>= < \ \( -> ( \+ -> + \. -> . \$ -> $ Etc...

\s

Metacharacter matching blank spaces. Short hand for the [:space:] class.

abc\s+123

\S

Metacharacter matching non-blank characters. Short hand for the [:graph:] class.

\S+\s+123

\d

Metacharacter matching numeric digits. Short hand for the [:digit:] class.

abc\s+\d+

.

The dot character matches any single character.

x.y .*z

^

When outside a bracket expression, ^ matches the ^abc.*$ start of line.

$

Matches the end of line.

Aristar, Inc. 302 N. Cleveland-Massillon Road Akron, OH 44333

^abc.*$

Date Last Modified 6/18/2001 1:30 PM

http://www.aristar.com mailto:[email protected] mailto:[email protected]

Aristar, Inc.

Dialect Language Reference

Page 64

[]

Bracket expression. Contains a set of characters [0-9] where any single character can match. If the list [a-z] starts with a ^, then it matches any character not in [^dew] the list. For example, [^xyz] will match any characters except x, y, or z. If two characters are separated by a -, then it denotes a range of characters. For example, [0-9] will match any single digit, [a-z] will match any single lower case letter, [A-Z] will match any uppercase letter, and [a-zA-Z] will match any single lower or upper case letter.

()

Used to denote a sub-expression. After a match xy([0-9]+)bc or during a replace, the specific text matching the sub-expression can be extracted.

*

Matches zero or more characters

[0-9]*

+

Matches one or more characters

[0-9]+

?

Matches zero or one character

[0-9]?

{m,n}

Matches at least m, and up to, but not exceeding n [0-9]{3} characters. If n is not given, will match exactly m [0-9]{2, 5} characters. 0