diff options
author | drh <drh@noemail.net> | 2017-08-02 03:21:11 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2017-08-02 03:21:11 +0000 |
commit | 59c435a015180c848e5f53e7bf7a68d53d164989 (patch) | |
tree | 238f6fe21da5111333547f9f14bbc6b7ce7f3f18 /tool/lemon.c | |
parent | 0019881e083765f470fcb714b2342e84a2b3c8e1 (diff) | |
download | sqlite-59c435a015180c848e5f53e7bf7a68d53d164989.tar.gz sqlite-59c435a015180c848e5f53e7bf7a68d53d164989.zip |
Add the "%token" control to the lemon parser. Not currently used by SQLite.
FossilOrigin-Name: a6e4c5ae8f29bc2e7f2088426341254e9281d19db9dc9a14abc376d56dad4c4b
Diffstat (limited to 'tool/lemon.c')
-rw-r--r-- | tool/lemon.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tool/lemon.c b/tool/lemon.c index fe0fb4c61..acc5450c9 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -2155,7 +2155,8 @@ enum e_state { WAITING_FOR_FALLBACK_ID, WAITING_FOR_WILDCARD_ID, WAITING_FOR_CLASS_ID, - WAITING_FOR_CLASS_TOKEN + WAITING_FOR_CLASS_TOKEN, + WAITING_FOR_TOKEN_NAME }; struct pstate { char *filename; /* Name of the input file */ @@ -2470,6 +2471,8 @@ to follow the previous rule."); }else if( strcmp(x,"fallback")==0 ){ psp->fallback = 0; psp->state = WAITING_FOR_FALLBACK_ID; + }else if( strcmp(x,"token")==0 ){ + psp->state = WAITING_FOR_TOKEN_NAME; }else if( strcmp(x,"wildcard")==0 ){ psp->state = WAITING_FOR_WILDCARD_ID; }else if( strcmp(x,"token_class")==0 ){ @@ -2624,6 +2627,26 @@ to follow the previous rule."); } } break; + case WAITING_FOR_TOKEN_NAME: + /* Tokens do not have to be declared before use. But they can be + ** in order to control their assigned integer number. The number for + ** each token is assigned when it is first seen. So by including + ** + ** %token ONE TWO THREE + ** + ** early in the grammar file, that assigns small consecutive values + ** to each of the tokens ONE TWO and THREE. + */ + if( x[0]=='.' ){ + psp->state = WAITING_FOR_DECL_OR_RULE; + }else if( !ISUPPER(x[0]) ){ + ErrorMsg(psp->filename, psp->tokenlineno, + "%%token argument \"%s\" should be a token", x); + psp->errorcnt++; + }else{ + (void)Symbol_new(x); + } + break; case WAITING_FOR_WILDCARD_ID: if( x[0]=='.' ){ psp->state = WAITING_FOR_DECL_OR_RULE; |