Language Constructs

The Slick-C® language is rooted in the C language. Slick-C contains some constructs from REXX and a dialog system usually found only in languages such as Microsoft® Visual Basic®. Slick-C also blends in object-oriented features from C++, Java, and Python.

Topics in this section:

Identifiers

A variable or identifier may contain any of the characters "A-Za-z$_0-9" and must start with one of the characters "A-Za-z_$".

Reserved Words and Keywords

The following keywords are reserved in the Slick-C® language:

  • _command

  • _notinit

  • _reinit

  • _str

  • arg

  • auto

  • boolean

  • break

  • case

  • class

  • const

  • continue

  • default

  • defexit

  • defined

  • definit

  • defload

  • defmain

  • do

  • double

  • else

  • enum

  • enum_flags

  • extern

  • false

  • for

  • foreach

  • if

  • in

  • instanceof

  • int

  • intdiv

  • interface

  • long

  • loop

  • namespace

  • no_code_swapping

  • null

  • parse

  • private

  • protected

  • public

  • return

  • short

  • static

  • struct

  • switch

  • this

  • true

  • typedef

  • typeless

  • union

  • using

  • var

  • void

  • while

  • with

The following keywords are reserved for built-in functions:

  • _a2e

  • _asc

  • _assert

  • _callmethod

  • _callmethod

  • _chr

  • _construct

  • _delete_unused

  • _deleteel

  • _dllexport

  • _dllload

  • _e2a

  • _el

  • _fieldindex

  • _fieldindex

  • _fieldname

  • _fieldname

  • _findmethod

  • _findmethod

  • _get_var

  • _getfield

  • _getfield

  • _indexin

  • _insertel

  • _instanceof

  • _instanceof

  • _isempty

  • _isfunptr

  • _length

  • _length

  • _load

  • _load_template

  • _make

  • _makeempty

  • _maybe_e2a

  • _nextel

  • _set_var

  • _setfield

  • _setfield

  • _sort

  • _typename

  • _typename

  • _update_template

  • _varformat

  • _write_state

  • call

  • call_event

  • call_index

  • call_key

  • center

  • delete_name

  • dsay

  • env_match

  • error_pos

  • event2index

  • event2name

  • eventtab_index

  • eventtab_inherit

  • exit

  • file_match

  • find_index

  • get_env

  • index_callable

  • index2event

  • insert_name

  • isinteger

  • isnumber

  • keyin

  • last_index

  • lastpos

  • length

  • list_bindings

  • lowcase

  • name_index2funptr

  • name_info

  • name_match

  • name_name

  • name_type

  • name2event

  • nls

  • pos

  • pow

  • prev_index

  • replace_name

  • say

  • set_env

  • set_eventtab_index

  • set_name_info

  • signal_handler

  • stop

  • stranslate

  • strappend

  • strcmp

  • stricmp

  • strieq

  • strip

  • strrev

  • substr

  • togglecase

  • trace

  • translate

  • upcase

  • verify

The following keywords are reserved for future use:

  • catch

  • finally

  • throw

  • try

The following keywords are reserved, but deprecated. Avoid using them.

  • _notinit

  • bigint

  • bigfloat

  • bigstring

The following keywords are reserved and used for event, dialog, and menu programming.

  • _check_box

  • _combo_box

  • _command_button

  • _control

  • _editor

  • _form

  • _frame

  • _gauge

  • _hscroll_bar

  • _image

  • _inherit

  • _label

  • _list_box

  • _menu

  • _minihtml

  • _nocheck

  • _picture_box

  • _print_preview

  • _radio_button

  • _spin

  • _sstab

  • _sstab_container

  • _text_box

  • _tree_view

  • _vscroll_bar

  • def

  • defeventtab

  • endsubmenu

  • submenu

All identifiers starting with p_ are reserved to be used as Slick-C property names. SlickEdit® reserves all identifiers starting with an underscore (_) for internal use.

Comments

Slick-C® supports both of the C++ comment styles.

  • Use // to declare that the rest of the line is a comment

  • Use /* to open a block comment and */ to close a block comment.

  • Block comments can be nested.

Example:

i=1; //this is a comment
/* this is a /* nested */ comment */

String Literals

Strings can be surrounded with single or double quotes. Double-quoted strings are identical to C++ string literals.

A backslash followed by a character has special meaning, as outlined in the table below.

Characters

Meaning

\a

Bell character (7)

\b

Backspace character (8)

\f

Form feed character (12)

\n

New line character (10)

\r

Carriage return (13)

\t

Tab character (9)

\v

Vertical tab character (11)

\?

Question mark character

\'

Single quote character

\"

Double quote character

\\

Backslash character

\x hh

Hexadecimal character code

\ ooo

Octal character code

If single quotes are used, two single quotes consecutively represent one single quote character. If double quotes are used, a backslash followed by a double quote represents one double quote character. The operator :== used in the example below compares two strings for exact equality. The Slick-C® language does have an operator ==. However, this operator strips leading and trailing spaces and tabs from both operands.

Examples:

"abc" :== 'abc'
"Can't find file" :== 'Can''t find file'
"\t" :== _chr(9) 
\t :== _chr(9)
" spaces " == "spaces"

A backslash (not inside quotation marks) followed by a character or a number has the special meaning, as shown in the table below.

Characters

Meaning

\a

Bell character (7)

\b

Backspace character (8)

\f

Form feed character(12)

\n

New line (10)

\r

Carriage return (13)

\t

Tab character (9)

\v

Vertical tab character (11)

\x dd

Hexadecimal character code dd

\ ddd

Decimal character code ddd

Caution

Using the above feature is not recommended. Use a quoted string.

Numeric Literals

The Slick-C® language supports integer constants in both decimal and hexadecimal formats. Hexadecimal numbers are defined using 0x[hexdigits] just like they are in C.

The Slick-C language supports floating point numbers. The mantissa is limited to 32 digits and the exponent is limited to nine digits. When precision is lost, the result is rounded. Overflow and underflow are detected. Floating point numbers have the following syntax:

[+|-] digits [.][digits][E[+|-]digits]

or

[+|-] [.][digits][E[+|-]digits]

There may be blank spaces before and after the leading sign.

Example:

        4.04
        4e2
        4e2
        4E-2
        4E-2

Defining Constants Using #define

Slick-C® supports the #define preprocessor directive. The #define directive is for defining constants or in-line functions. Use the following syntax to define the constant or in-line function:


    #define name[(param1,param2,)] value
    

Use a backslash at the end of a line to indicate that the value text continues to the next line. Any occurrence of name is replaced with the text value before the source is compiled.

Caution

When value represents an expression, place parentheses around it to make sure that there is not a problem with operator precedence.

Example:

#define MAXLINES 15
#define MAXLINESP1                            (MAXLINES+1)
#define max(a,b)                              (((a) >= (b)) ? (a) : (b)) 
#define min(a,b)                              (((a) <= (b)) ? (a) : (b))

defmain() { 
    x=MAXLINES;
    y=MAXLINESP1; 
    a=max(x,y);
}

Defining Constants Using const

A const declaration is used to define a constant. A constant can be scoped within a class, namespace, or globally. The advantage to using const instead of #define is that const constants are pure constants and can be introspected using find_index() and name_info(), but a #define is just a lexical substitution. For consistency, we recommend that constants use all uppercase identifiers, optionally using underscores to separate words.

Examples:

const MAXLINES = 15;  
const MAXLINESP1 = (MAXLINES+1);
const SEARCHKEY = "<Search>";

A few notes about constants:

  • The const declaration works with Slick-C classes and namespaces.

  • Constants support type inference so that the compiler can tell ints from booleans from strings.

  • Constant names and values are stored in the state file in order to allow introspection.

  • Context Tagging® recognizes the const declaration correctly.

Defining Constants Using Enumerators

Slick-C® also allows you to define constants using enumerators. Enumerated types share the advantages of const declarations. They are discussed in more detail in the section Enumerated Types.

Namespaces

Slick-C® supports namespaces which allow you to partition functions and classes into independent areas in order to organize your code better, and to better isolate your code from name conflicts. Slick-C namespaces use "." instead of "::". Slick-C does not allow un-named namespace declarations. Slick-C supports two types of namespace declarations, as shown in the following code:

    // Module-wide (like Java).
    namespace slickedit.tagging;   
 
    // Scoped namespace declaration (like C++ and C#).
    namespace slickedit.search {
       . . .
    }

Namespace imports use the C++-style using syntax:

    // Pull all symbols from slickedit.tagging into current scope.
    using namespace slickedit.tagging;
 
    // Pull one symbol from slickedit.search into scope.
    using slickedit.search.Regex;
 
    // Qualified access to a symbol in the namespace.
    slickedit.diff.Diff( f1, f2 );

Slick-C includes the default; namespace, which will return you to the "default" global namespace.