I am reading the grammar of SQLite and having a few questions about the following paragraph.
// The name of a column or table can be any of the following:
//
%type nm {Token}
nm(A) ::= id(A).
nm(A) ::= STRING(A).
nm(A) ::= JOIN_KW(A).
The nm
has been used quite widely in the program. The lemon parser documentation said
Typically the data type of a non-terminal is a pointer to the root of a parse-tree structure that contains all information about that non-terminal
%type expr {Expr*}
Should I understand {Token}
actually stands for a syntactic grouping which is a non-terminal token that "is a parse-tree structure that contains all.."?
What is nm short for in this same, is it simply "name"?
What is the period sign (dot .
) that each nm(A) declaration ends up with?
Token
is a C object type used for the semantic value of nm
s.
(It is defined in sqliteInt.h
and consists of a pointer to a non-null terminated character array and the length of that array.)The comment immediately above the definition of nm
starts with the words "the name", which definitely suggests to me that nm
is an abbreviation for "name", yes. That is also consistent with its semantic type, as above, which is basically a name (or at least a string of characters).
All lemon productions end with a dot. It tells lemon where the end of the production is, like semicolons indicate to a C compiler where the end of a statement is. This makes it easier to parse consecutive productions, since otherwise the parser would have to look several symbols ahead to see the ::=