Crunch CRiSP File Editor 6 User Manual

Page 77

Advertising
background image

Page 77

inside the string, or any other non-printable character, you can use a backslash to affect the following
characters.

In many languages, string constants are handled differently. In ADA, strings are enclosed in single quotes,
and to quote a single quote, you just specify three apostrophes in a row.

There are other coding differences from one language to another. CRiSP has evolved to cater for many of
these different styles, but it is not generic enough to allow any kind of quoting policy.

Colorization is a process which analyses a file based on a syntax specification. This means that CRiSP is
looking at very little context to determine the meaning of any part of the text. For example, if CRiSP sees a
digit, it reasonably expects the digit to be part of a number, with successive digits and possibly a fraction to
follow (unless told otherwise)

CRiSP does not perform a semantic analysis of a file. Semantic analysis means parsing an entire file, and
determining that the exact order of words, keywords, constants etc., are valid or not. Take the following
example:

int fred = 3;

This is a statement in the C or C++ languages which creates an integer variable called fred initialised to
contain the value 3. From a syntax point of view, there are 5 tokens: int, a symbol, an = operator, a number
3, and a semicolon.

From a semantic point of view, the above statement is correct. Now consider this re-ordering

fred = ; int 3

This is total nonsense to a C or C++ compiler. CRiSP can colorize this nonsense quite happily because it
doesn't worry about the order and context of the tokens. It simply identifies each token by the first character
or so.

Thus you cannot specify a language in terms of valid statements, only valid keywords.

The reason for not performing a semantic analysis of your code is that this would be too slow, and many
software development tools excel in doing this for you.

The reason for emphasising this point is that for non-programmers, it may be difficult to understand what is
possible and what is not possible.

Case study #1: C colorizer

Colorization:case study 1

The following example illustrates the C colorizer provided with

CRiSP. The original file can be found in the distribution directory src/keywords/c.kwd.This colorizer file
demonstrates most of the features and facilities of writing a colorizer.

[c]

flags=c_hexadecimal c_floats

char_start="[A-Za-z_]"

char_next="[A-Za-z_0-9]"

char_new_token="[/*]"

char_operator="[-^!|&<>~()/*+=?:]"

directive="^[ \t]*#*"

comment=spell accept_backslashes "//*.*$"

comment=spell "/**.**/"

string=spell accept_backslashes "\"*.*\""

string=accept_backslashes "'*.*'"

Advertising