Skip to content

Commit

Permalink
part of check-in [a6e4c5ae] at 2017-08-02 03:21:11 on branch trunk — …
Browse files Browse the repository at this point in the history
…Add the "%token" control to the lemon parser. Not currently used by SQLite.
  • Loading branch information
ksherlock committed Aug 7, 2017
1 parent 20224aa commit 8a15d39
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,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 */
Expand Down Expand Up @@ -2524,6 +2525,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 ){
Expand Down Expand Up @@ -2678,6 +2681,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;
Expand Down

0 comments on commit 8a15d39

Please sign in to comment.