The Lemon Parser Generator

Lemon is an LALR(1) parser generator for C or C++. It does the same job as ``bison'' and ``yacc''.But lemon is not another bison or yacc clone. Ituses a different grammar syntax which is designed toreduce the number of coding errors. Lemon also uses a moresophisticated parsing engine that is faster than yacc andbison and which is both reentrant and thread-safe.Furthermore, Lemon implements features that can be usedto eliminate resource leaks, making is suitable for usein long-running programs such as graphical user interfacesor embedded controllers.

This document is an introduction to the Lemonparser generator.

Theory of Operation

The main goal of Lemon is to translate a context free grammar (CFG)for a particular language into C code that implements a parser forthat language.The program has two inputs:

  • The grammar specification.
  • A parser template file.

Typically, only the grammar specification is supplied by the programmer.Lemon comes with a default parser template which works fine for mostapplications. But the user is free to substitute a different parsertemplate if desired.

Depending on command-line options, Lemon will generate betweenone and three files of outputs.

  • C code to implement the parser.
  • A header file defining an integer ID for each terminal symbol.
  • An information file that describes the states of the generated parser automaton.

By default, all three of these output files are generated.The header file is suppressed if the ``-m'' command-line option isused and the report file is omitted when ``-q'' is selected.

The grammar specification file uses a ``.y'' suffix, by convention.In the examples used in this document, we'll assume the name of thegrammar file is ``gram.y''. A typical use of Lemon would be thefollowing command:

lemon gram.y

This command will generate three output files named ``gram.c'',``gram.h'' and ``gram.out''.The first is C code to implement the parser. The secondis the header file that defines numerical values for allterminal symbols, and the last is the report that explainsthe states used by the parser automaton.

Command Line Options

The behavior of Lemon can be modified using command-line options.You can obtain a list of the available command-line options togetherwith a brief explanation of what each does by typing

lemon -?

As of this writing, the following command-line options are supported:

  • -b
  • -c
  • -g
  • -m
  • -q
  • -s
  • -x

The ``-b'' option reduces the amount of text in the report file byprinting only the basis of each parser state, rather than the fullconfiguration.The ``-c'' option suppresses action table compression. Using -cwill make the parser a little larger and slower but it will detectsyntax errors sooner.The ``-g'' option causes no output files to be generated at all.Instead, the input grammar file is printed on standard output butwith all comments, actions and other extraneous text deleted. Thisis a useful way to get a quick summary of a grammar.The ``-m'' option causes the output C source file to be compatiblewith the ``makeheaders'' program.Makeheaders is a program that automatically generates header filesfrom C source code. When the ``-m'' option is used, the headerfile is not output since the makeheaders program will take careof generated all header files automatically.The ``-q'' option suppresses the report file.Using ``-s'' causes a brief summary of parser statistics to beprinted. Like this:

Parser statistics: 74 terminals, 70 nonterminals, 179 rules                      340 states, 2026 parser table entries, 0 conflicts

Finally, the ``-x'' option causes Lemon to print its version numberand copyright informationand then stop without attempting to read the grammar or generate a parser.

The Parser Interface

Lemon doesn't generate a complete, working program. It only generatesa few subroutines that implement a parser. This section describesthe interface to those subroutines. It is up to the programmer tocall these subroutines in an appropriate way in order to produce acomplete system.

Before a program begins using a Lemon-generated parser, the programmust first create the parser.A new parser is created as follows:

void *pParser = ParseAlloc( malloc );

The ParseAlloc() routine allocates and initializes a new parser andreturns a pointer to it.The actual data structure used to represent a parser is opaque --its internal structure is not visible or usable by the calling routine.For this reason, the ParseAlloc() routine returns a pointer to voidrather than a pointer to some particular structure.The sole argument to the ParseAlloc() routine is a pointer to thesubroutine used to allocate memory. Typically this means ``malloc()''.

After a program is finished using a parser, it can reclaim allmemory allocated by that parser by calling

ParseFree(pParser, free);

The first argument is the same pointer returned by ParseAlloc(). Thesecond argument is a pointer to the function used to release bulkmemory back to the system.

After a parser has been allocated using ParseAlloc(), the programmermust supply the parser with a sequence of tokens (terminal symbols) tobe parsed. This is accomplished by calling the following functiononce for each token:

Parse(pParser, hTokenID, sTokenData, pArg);

The first argument to the Parse() routine is the pointer returned byParseAlloc().The second argument is a small positive integer that tells the parse thetype of the next token in the data stream.There is one token type for each terminal symbol in the grammar.The gram.h file generated by Lemon contains #define statements thatmap symbolic terminal symbol names into appropriate integer values.(A value of 0 for the second argument is a special flag to theparser to indicate that the end of input has been reached.)The third argument is the value of the given token. By default,the type of the third argument is integer, but the grammar willusually redefine this type to be some kind of structure.Typically the second argument will be a broad category of tokenssuch as ``identifier'' or ``number'' and the third argument willbe the name of the identifier or the value of the number.

The Parse() function may have either three or four arguments,depending on the grammar. If the grammar specification file requestit, the Parse() function will have a fourth parameter that can beof any type chosen by the programmer. The parser doesn't do anythingwith this argument except to pass it through to action routines.This is a convenient mechanism for passing state information downto the action routines without having to use global variables.

A typical use of a Lemon parser might look something like thefollowing:

01 ParseTree *ParseFile(const char *zFilename){   02    Tokenizer *pTokenizer;   03    void *pParser;   04    Token sToken;   05    int hTokenId;   06    ParserState sState;   07   08    pTokenizer = TokenizerCreate(zFilename);   09    pParser = ParseAlloc( malloc );   10    InitParserState(&sState);   11    while( GetNextToken(pTokenizer, &hTokenId, &sToken) ){   12       Parse(pParser, hTokenId, sToken, &sState);   13    }   14    Parse(pParser, 0, sToken, &sState);   15    ParseFree(pParser, free );   16    TokenizerFree(pTokenizer);   17    return sState.treeRoot;   18 }

This example shows a user-written routine that parses a file oftext and returns a pointer to the parse tree.(We've omitted all error-handling from this example to keep itsimple.)We assume the existence of some kind of tokenizer which is createdusing TokenizerCreate() on line 8 and deleted by TokenizerFree()on line 16. The GetNextToken() function on line 11 retrieves thenext token from the input file and puts its type in the integer variable hTokenId. The sToken variable is assumed to besome kind of structure that contains details about each token,such as its complete text, what line it occurs on, etc.

This example also assumes the existence of structure of typeParserState that holds state information about a particular parse.An instance of such a structure is created on line 6 and initializedon line 10. A pointer to this structure is passed into the Parse()routine as the optional 4th argument.The action routine specified by the grammar for the parser can usethe ParserState structure to hold whatever information is useful andappropriate. In the example, we note that the treeRoot field ofthe ParserState structure is left pointing to the root of the parsetree.

The core of this example as it relates to Lemon is as follows:

ParseFile(){      pParser = ParseAlloc( malloc );      while( GetNextToken(pTokenizer,&hTokenId, &sToken) ){         Parse(pParser, hTokenId, sToken);      }      Parse(pParser, 0, sToken);      ParseFree(pParser, free );   }

Basically, what a program has to do to use a Lemon-generated parseris first create the parser, then send it lots of tokens obtained bytokenizing an input source. When the end of input is reached, theParse() routine should be called one last time with a token typeof 0. This step is necessary to inform the parser that the end ofinput has been reached. Finally, we reclaim memory used by theparser by calling ParseFree().

There is one other interface routine that should be mentionedbefore we move on.The ParseTrace() function can be used to generate debugging outputfrom the parser. A prototype for this routine is as follows:

ParseTrace(FILE *stream, char *zPrefix);

After this routine is called, a short (one-line) message is writtento the designated output stream every time the parser changes statesor calls an action routine. Each such message is prefaced usingthe text given by zPrefix. This debugging output can be turned offby calling ParseTrace() again with a first argument of NULL (0).

Differences With YACC and BISON

Programmers who have previously used the yacc or bison parsergenerator will notice several important differences between yacc and/orbison and Lemon.

  • In yacc and bison, the parser calls the tokenizer. In Lemon, the tokenizer calls the parser.
  • Lemon uses no global variables. Yacc and bison use global variables to pass information between the tokenizer and parser.
  • Lemon allows multiple parsers to be running simultaneously. Yacc and bison do not.

These differences may cause some initial confusion for programmerswith prior yacc and bison experience.But after years of experience using Lemon, I firmlybelieve that the Lemon way of doing things is better.

Input File Syntax

The main purpose of the grammar specification file for Lemon isto define the grammar for the parser. But the input file alsospecifies additional information Lemon requires to do its job.Most of the work in using Lemon is in writing an appropriategrammar file.

The grammar file for lemon is, for the most part, free format.It does not have sections or divisions like yacc or bison. Anydeclaration can occur at any point in the file.Lemon ignores whitespace (except where it is needed to separatetokens) and it honors the same commenting conventions as C and C++.

Terminals and Nonterminals

A terminal symbol (token) is any string of alphanumericand underscore charactersthat begins with an upper case letter.A terminal can contain lowercase letters after the first character,but the usual convention is to make terminals all upper case.A nonterminal, on the other hand, is any string of alphanumericand underscore characters than begins with a lower case letter.Again, the usual convention is to make nonterminals use all lowercase letters.

In Lemon, terminal and nonterminal symbols do not need to be declared or identified in a separate section of the grammar file.Lemon is able to generate a list of all terminals and nonterminalsby examining the grammar rules, and it can always distinguish aterminal from a nonterminal by checking the case of the firstcharacter of the name.

Yacc and bison allow terminal symbols to have either alphanumericnames or to be individual characters included in single quotes, likethis: ')' or '$'. Lemon does not allow this alternative form forterminal symbols. With Lemon, all symbols, terminals and nonterminals,must have alphanumeric names.

Grammar Rules

The main component of a Lemon grammar file is a sequence of grammarrules.Each grammar rule consists of a nonterminal symbol followed bythe special symbol ``::='' and then a list of terminals and/or nonterminals.The rule is terminated by a period.The list of terminals and nonterminals on the right-hand side of therule can be empty.Rules can occur in any order, except that the left-hand side of thefirst rule is assumed to be the start symbol for the grammar (unlessspecified otherwise using the %start directive described below.)A typical sequence of grammar rules might look something like this:

expr ::= expr PLUS expr.  expr ::= expr TIMES expr.  expr ::= LPAREN expr RPAREN.  expr ::= VALUE.

There is one non-terminal in this example, ``expr'', and fiveterminal symbols or tokens: ``PLUS'', ``TIMES'', ``LPAREN'',``RPAREN'' and ``VALUE''.

Like yacc and bison, Lemon allows the grammar to specify a blockof C code that will be executed whenever a grammar rule is reducedby the parser.In Lemon, this action is specified by putting the C code (containedwithin curly braces {...}) immediately after theperiod that closes the rule.For example:

expr ::= expr PLUS expr.   { printf("Doing an addition...\n"); }

In order to be useful, grammar actions must normally be linked totheir associated grammar rules.In yacc and bison, this is accomplished by embedding a ``$$'' in theaction to stand for the value of the left-hand side of the rule andsymbols ``$1'', ``$2'', and so forth to stand for the value ofthe terminal or nonterminal at position 1, 2 and so forth on theright-hand side of the rule.This idea is very powerful, but it is also very error-prone. Thesingle most common source of errors in a yacc or bison grammar isto miscount the number of symbols on the right-hand side of a grammarrule and say ``$7'' when you really mean ``$8''.

Lemon avoids the need to count grammar symbols by assigning symbolicnames to each symbol in a grammar rule and then using those symbolicnames in the action.In yacc or bison, one would write this:

expr -> expr PLUS expr  { $$ = $1 + $3; };

But in Lemon, the same rule becomes the following:

expr(A) ::= expr(B) PLUS expr(C).  { A = B+C; }

In the Lemon rule, any symbol in parentheses after a grammar rulesymbol becomes a place holder for that symbol in the grammar rule.This place holder can then be used in the associated C action tostand for the value of that symbol.

The Lemon notation for linking a grammar rule with its reduceaction is superior to yacc/bison on several counts.First, as mentioned above, the Lemon method avoids the need tocount grammar symbols.Secondly, if a terminal or nonterminal in a Lemon grammar ruleincludes a linking symbol in parentheses but that linking symbolis not actually used in the reduce action, then an error messageis generated.For example, the rule

expr(A) ::= expr(B) PLUS expr(C).  { A = B; }

will generate an error because the linking symbol ``C'' is usedin the grammar rule but not in the reduce action.

The Lemon notation for linking grammar rules to reduce actionsalso facilitates the use of destructors for reclaiming memoryallocated by the values of terminals and nonterminals on theright-hand side of a rule.

Precedence Rules

Lemon resolves parsing ambiguities in exactly the same way asyacc and bison. A shift-reduce conflict is resolved in favorof the shift, and a reduce-reduce conflict is resolved by reducingwhichever rule comes first in the grammar file.

Just like inyacc and bison, Lemon allows a measure of control over the resolution of paring conflicts using precedence rules.A precedence value can be assigned to any terminal symbolusing the %left, %right or %nonassoc directives. Terminal symbolsmentioned in earlier directives have a lower precedence thatterminal symbols mentioned in later directives. For example:

%left AND.   %left OR.   %nonassoc EQ NE GT GE LT LE.   %left PLUS MINUS.   %left TIMES DIVIDE MOD.   %right EXP NOT.

In the preceding sequence of directives, the AND operator isdefined to have the lowest precedence. The OR operator is oneprecedence level higher. And so forth. Hence, the grammar wouldattempt to group the ambiguous expression

a AND b OR c

like this

a AND (b OR c).

The associativity (left, right or nonassoc) is used to determinethe grouping when the precedence is the same. AND is left-associativein our example, so

a AND b AND c

is parsed like this

(a AND b) AND c.

The EXP operator is right-associative, though, so

a EXP b EXP c

is parsed like this

a EXP (b EXP c).

The nonassoc precedence is used for non-associative operators.So

a EQ b EQ c

is an error.

The precedence of non-terminals is transferred to rules as follows:The precedence of a grammar rule is equal to the precedence of theleft-most terminal symbol in the rule for which a precedence isdefined. This is normally what you want, but in those cases whereyou want to precedence of a grammar rule to be something different,you can specify an alternative precedence symbol by putting thesymbol in square braces after the period at the end of the rule andbefore any C-code. For example:

expr = MINUS expr.  [NOT]

This rule has a precedence equal to that of the NOT symbol, not theMINUS symbol as would have been the case by default.

With the knowledge of how precedence is assigned to terminalsymbols and individualgrammar rules, we can now explain precisely how parsing conflictsare resolved in Lemon. Shift-reduce conflicts are resolvedas follows:

  • If either the token to be shifted or the rule to be reduced lacks precedence information, then resolve in favor of the shift, but report a parsing conflict.
  • If the precedence of the token to be shifted is greater than the precedence of the rule to reduce, then resolve in favor of the shift. No parsing conflict is reported.
  • If the precedence of the token it be shifted is less than the precedence of the rule to reduce, then resolve in favor of the reduce action. No parsing conflict is reported.
  • If the precedences are the same and the shift token is right-associative, then resolve in favor of the shift. No parsing conflict is reported.
  • If the precedences are the same the the shift token is left-associative, then resolve in favor of the reduce. No parsing conflict is reported.
  • Otherwise, resolve the conflict by doing the shift and report the parsing conflict.

Reduce-reduce conflicts are resolved this way:

  • If either reduce rule lacks precedence information, then resolve in favor of the rule that appears first in the grammar and report a parsing conflict.
  • If both rules have precedence and the precedence is different then resolve the dispute in favor of the rule with the highest precedence and do not report a conflict.
  • Otherwise, resolve the conflict by reducing by the rule that appears first in the grammar and report a parsing conflict.

Special Directives

The input grammar to Lemon consists of grammar rules and specialdirectives. We've described all the grammar rules, so now we'lltalk about the special directives.

Directives in lemon can occur in any order. You can put them beforethe grammar rules, or after the grammar rules, or in the mist of thegrammar rules. It doesn't matter. The relative order ofdirectives used to assign precedence to terminals is important, butother than that, the order of directives in Lemon is arbitrary.

Lemon supports the following special directives:

  • %destructor
  • %extra_argument
  • %include
  • %left
  • %name
  • %nonassoc
  • %parse_accept
  • %parse_failure
  • %right
  • %stack_overflow
  • %stack_size
  • %start_symbol
  • %syntax_error
  • %token_destructor
  • %token_prefix
  • %token_type
  • %type

Each of these directives will be described separately in thefollowing sections:

The %destructor directive

The %destructor directive is used to specify a destructor fora non-terminal symbol.(See also the %token_destructor directive which is used tospecify a destructor for terminal symbols.)

A non-terminal's destructor is called to dispose of thenon-terminal's value whenever the non-terminal is popped fromthe stack. This includes all of the following circumstances:

  • When a rule reduces and the value of a non-terminal on the right-hand side is not linked to C code.
  • When the stack is popped during error processing.
  • When the ParseFree() function runs.

The destructor can do whatever it wants with the value ofthe non-terminal, but its design is to deallocate memoryor other resources held by that non-terminal.

Consider an example:

%type nt {void*}   %destructor nt { free($$); }   nt(A) ::= ID NUM.   { A = malloc( 100 ); }

This example is a bit contrived but it serves to illustrate howdestructors work. The example shows a non-terminal named``nt'' that holds values of type ``void*''. When the rule foran ``nt'' reduces, it sets the value of the non-terminal tospace obtained from malloc(). Later, when the nt non-terminalis popped from the stack, the destructor will fire and callfree() on this malloced space, thus avoiding a memory leak.(Note that the symbol ``$$'' in the destructor code is replacedby the value of the non-terminal.)

It is important to note that the value of a non-terminal is passedto the destructor whenever the non-terminal is removed from thestack, unless the non-terminal is used in a C-code action. Ifthe non-terminal is used by C-code, then it is assumed that theC-code will take care of destroying it if it should reallybe destroyed. More commonly, the value is used to build somelarger structure and we don't want to destroy it, which is whythe destructor is not called in this circumstance.

By appropriate use of destructors, it is possible tobuild a parser using Lemon that can be used within a long-runningprogram, such as a GUI, that will not leak memory or other resources.To do the same using yacc or bison is much more difficult.

The %extra_argument directive

The %extra_argument directive instructs Lemon to add a 4th parameterto the parameter list of the Parse() function it generates. Lemondoesn't do anything itself with this extra argument, but it doesmake the argument available to C-code action routines, destructors,and so forth. For example, if the grammar file contains:

%extra_argument { MyStruct *pAbc }

Then the Parse() function generated will have an 4th parameterof type ``MyStruct*'' and all action routines will have access toa variable named ``pAbc'' that is the value of the 4th parameterin the most recent call to Parse().

The %include directive

The %include directive specifies C code that is included at thetop of the generated parser. You can include any text you want --the Lemon parser generator copies to blindly. If you have multiple%include directives in your grammar file, their values are concatenatedbefore being put at the beginning of the generated parser.

The %include directive is very handy for getting some extra #includepreprocessor statements at the beginning of the generated parser.For example:

%include {#include <unistd.h>}

This might be needed, for example, if some of the C actions in thegrammar call functions that are prototyed in unistd.h.

The %left directive

The %left directive is used (along with the %right and%nonassoc directives) to declare precedences of terminalsymbols. Every terminal symbol whose name appears aftera %left directive but before the next period (``.'') isgiven the same left-associative precedence value. Subsequent%left directives have higher precedence. For example:

%left AND.   %left OR.   %nonassoc EQ NE GT GE LT LE.   %left PLUS MINUS.   %left TIMES DIVIDE MOD.   %right EXP NOT.

Note the period that terminates each %left, %right or %nonassocdirective.

LALR(1) grammars can get into a situation where they requirea large amount of stack space if you make heavy use or right-associativeoperators. For this reason, it is recommended that you use %leftrather than %right whenever possible.

The %name directive

By default, the functions generated by Lemon all begin with thefive-character string ``Parse''. You can change this string to somethingdifferent using the %name directive. For instance:

%name Abcde

Putting this directive in the grammar file will cause Lemon to generatefunctions named

  • AbcdeAlloc(),
  • AbcdeFree(),
  • AbcdeTrace(), and
  • Abcde().

The %name directive allows you to generator two or more differentparsers and link them all into the same executable.

The %nonassoc directive

This directive is used to assign non-associative precedence toone or more terminal symbols. See the section on precedence rulesor on the %left directive for additional information.

The %parse_accept directive

The %parse_accept directive specifies a block of C code that isexecuted whenever the parser accepts its input string. To ``accept''an input string means that the parser was able to process all tokenswithout error.

For example:

%parse_accept {      printf("parsing complete!\n");   }

The %parse_failure directive

The %parse_failure directive specifies a block of C code thatis executed whenever the parser fails complete. This code is notexecuted until the parser has tried and failed to resolve an inputerror using is usual error recovery strategy. The routine isonly invoked when parsing is unable to continue.

%parse_failure {     fprintf(stderr,"Giving up.  Parser is hopelessly lost...\n");   }

The %right directive

This directive is used to assign right-associative precedence toone or more terminal symbols. See the section on precedence rulesor on the %left directive for additional information.

The %stack_overflow directive

The %stack_overflow directive specifies a block of C code thatis executed if the parser's internal stack ever overflows. Typicallythis just prints an error message. After a stack overflow, the parserwill be unable to continue and must be reset.

%stack_overflow {     fprintf(stderr,"Giving up.  Parser stack overflow\n");   }

You can help prevent parser stack overflows by avoiding the useof right recursion and right-precedence operators in your grammar.Use left recursion and and left-precedence operators instead, toencourage rules to reduce sooner and keep the stack size down.For example, do rules like this:

list ::= list element.      // left-recursion.  Good!   list ::= .

Not like this:

list ::= element list.      // right-recursion.  Bad!   list ::= .

The %stack_size directive

If stack overflow is a problem and you can't resolve the troubleby using left-recursion, then you might want to increase the sizeof the parser's stack using this directive. Put an positive integerafter the %stack_size directive and Lemon will generate a parsewith a stack of the requested size. The default value is 100.

%stack_size 2000

The %start_symbol directive

By default, the start-symbol for the grammar that Lemon generatesis the first non-terminal that appears in the grammar file. But youcan choose a different start-symbol using the %start_symbol directive.

%start_symbol  prog

The %token_destructor directive

The %destructor directive assigns a destructor to a non-terminalsymbol. (See the description of the %destructor directive above.)This directive does the same thing for all terminal symbols.

Unlike non-terminal symbols which may each have a different data typefor their values, terminals all use the same data type (defined bythe %token_type directive) and so they use a common destructor. Otherthan that, the token destructor works just like the non-terminaldestructors.

The %token_prefix directive

Lemon generates #defines that assign small integer constantsto each terminal symbol in the grammar. If desired, Lemon willadd a prefix specified by this directiveto each of the #defines it generates.So if the default output of Lemon looked like this:

#define AND              1    #define MINUS            2    #define OR               3    #define PLUS             4

You can insert a statement into the grammar like this:

%token_prefix    TOKEN_

to cause Lemon to produce these symbols instead:

#define TOKEN_AND        1    #define TOKEN_MINUS      2    #define TOKEN_OR         3    #define TOKEN_PLUS       4

The %token_type and %type directives

These directives are used to specify the data types for valueson the parser's stack associated with terminal and non-terminalsymbols. The values of all terminal symbols must be of the sametype. This turns out to be the same data type as the 3rd parameterto the Parse() function generated by Lemon. Typically, you willmake the value of a terminal symbol by a pointer to some kind oftoken structure. Like this:

%token_type    {Token*}

If the data type of terminals is not specified, the default valueis ``int''.

Non-terminal symbols can each have their own data types. Typicallythe data type of a non-terminal is a pointer to the root of a parse-treestructure that contains all information about that non-terminal.For example:

%type   expr  {Expr*}

Each entry on the parser's stack is actually a union containinginstances of all data types for every non-terminal and terminal symbol.Lemon will automatically use the correct element of this union dependingon what the corresponding non-terminal or terminal symbol is. Butthe grammar designer should keep in mind that the size of the unionwill be the size of its largest element. So if you have a singlenon-terminal whose data type requires 1K of storage, then your 100entry parser stack will require 100K of heap space. If you are willingand able to pay that price, fine. You just need to know.

Error Processing

After extensive experimentation over several years, it has beendiscovered that the error recovery strategy used by yacc is aboutas good as it gets. And so that is what Lemon uses.

When a Lemon-generated parser encounters a syntax error, itfirst invokes the code specified by the %syntax_error directive, ifany. It then enters its error recovery strategy. The error recoverystrategy is to begin popping the parsers stack until it enters astate where it is permitted to shift a special non-terminal symbolnamed ``error''. It then shifts this non-terminal and continuesparsing. But the %syntax_error routine will not be called againuntil at least three new tokens have been successfully shifted.

If the parser pops its stack until the stack is empty, and it stillis unable to shift the error symbol, then the %parse_failed routineis invoked and the parser resets itself to its start state, readyto begin parsing a new file. This is what will happen at the veryfirst syntax error, of course, if there are no instances of the ``error'' non-terminal in your grammar.

(0)

相关推荐