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;
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.
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: