beautypg.com

Fuzzy parsing, The crunch language, The crunch compiler – Crunch CRiSP File Editor 6 User Manual

Page 14

background image

Page 14

SQL

.sql

TeX

.tex

Perl

.pl, .pm

Verilog

.v, .verilog

VHD

.vhd, .vhdl

Yacc grammars

.y

Note that crtags uses a fuzzy-parsing

fuzzy parsing

mechanism to scan source files. This has the

advantage of working in spite of any syntax errors and avoids the complexity of worrying about compile-time
constant definitions which may affect the flow of the parsing (e.g. in the presence of #ifdef constructs).

The down-side of this is that the parsing may not be 100% correct as seen from the point of view of the
compiler. The aim is to provide a level of accuracy which makes the tool useful to you.

The CRUNCH Language

The crunch language is the language used to write macros for CRiSP. The crunch language looks and feels
a lot like the C language, and this should help users who are writing macros for the first time, but there are
significant differences, which the user should be aware of.

The CRiSP language supports a number of primitive data types(pg. 15).:

32-bit integers (int)
64-bit floating point numbers (float/double)
strings (string)
lists or arrays (list)
structs

CRiSP acts as an interpreter for the language. The programs which the user writes are first compiled to a
compact pseudo code format. Although CRiSP is designed to run as fast as possible and use as little CPU
resources as possible, the design of the interpreted language is aimed at keeping the size of the macros as
small as possible. Writing macros in the crunch language allows the internal architecture of CRiSP to be
extended and improved upon in the future whilst maintaining compatibility, at the source code level for user
written extensions to the editor.

The other advantages of writing macros in the crunch language is that the macros are totally machine
independent, working equally well on Windows or Unix platforms. Macros are also convenient when you do
not have access to a C compiler or other architecture specific development tools.

The crunch compiler is implemented using a full yacc grammar(pg. 25). of the ANSI C language, and
although many constructs may be accepted by the compiler, they may not generate any code, wrong code,
or cause the compiler to crash. When in doubt about the correct parsing of a macro, you should run the
crunch command with the -c flag. This will compile the source code into the .m intermediate language file
(the .m lisp-like language is CRiSP's assembly level code).

In order to write your own macros, you will need to understand various levels of detail. Writing simple one-off
macros is easy, but there are a lot of details to learn if coding up complex multi-file macro packages.

1.

The syntax of the language. The syntax is very close to ANSI C. For those of you who know this
language, this means there is very little mental energy involved in understanding what to write or what
to expect.

2.

The semantics of the language. This covers the actual context dependent meanings of constructs within
the language. This ranges from the meaning of a switch statement, to an understanding of the different
data and variable types.

3.

The internal data types and objects within the CRiSP language. CRiSP supports objects ranging from
32-bit integer values, to entire buffers containing edited files, callbacks, dialog boxes.

4.

An understanding of the macro primitives CRiSP provides. CRiSP provides numerous functions which
operate on internal data structures.

{button See Also, ALink(crunch,,,)}

The crunch compiler

The crunch program is the crunch compiler. It takes a source file (with .cr extension) and creates a .cm file,