TOKEN(5)

Table of Contents

Name

TOKEN
C data structure type of token nodes
tok
returns the original specification string of a token
linenumber
returns the starting line number of a token colnumber returns the starting column number of a token
filename
returns the name of the file a token came from
whitespace
returns the white space found preceding a token lastwhitespace trailing white space in specification file

Synopsis

typedef struct {...} *TOKEN;
STRING tok(token)
TOKEN token;
int linenumber(token)
TOKEN token;
int colnumber(token)
TOKEN token;
STRING filename(token)
TOKEN token;
STRING whitespace(token)
TOKEN token;
STRING lastwhitespace;

Description

These components of the run-time library are the predefined type, macros and global variable that apply to the token nodes in the parse tree. The token nodes are the leaves of the parse tree; there is one token node for each lex token that is recognized in the specification.

TOKEN is the core data type for all token nodes. All new token data types that ivy*meta SDTB creates from the grammar section are extensions to TOKEN (TOKEN is an extension of ANY) (see GRAMMAR(2) and ANY(5) ).

Every TOKEN node contains a number of fields that may be accessed through macros. Macro tok returns the text from the specification file that makes up the body of the token. Macro linenumber returns the line number in the specification file where the text of the token begins. Macro colnumber returns the column number in the specification file where the text of the token begins. Macro filename returns the name of the specification file that contains the text of the token. Macro whitespace returns the white space string the precedes the token in the specification file.

The white space at the end of the file is not accessible with the whitespace macro. However, the final white space

is stored in the global variable lastwhitespace.

Example

If the grammar section of a source description file contained:
input: ( fname+ )
fname: <[a-zA-Z]+>
and if the specification, in file x.ds, were: abc def
Then the following expressions would return these values:

tok(fname(top))
returns «abc"
tok(next(fname(top)))
returns «def"
linenumber(fname(top))
returns 1
colnumber(fname(top))
returns 5
filename(fname(top))
returns «x.ds" whitespace(next(fname(top))) returns « «

See Also

GRAMMAR(2)
ANY(5)
FRONTIER(5)


© 1990 Lucent Technologies, Inc
© 1998 Harmony Software, Inc