![]() What happens if it sees “subject subject” or some other invalid list of tokens? The parser calls yyerror(), which we provide in the user subroutines section, and then recognizes the special rule error. Our example prints a message if it sees a “subject VERB object” list of input tokens. Subsequent calls to yyparse() reset the state and begin processing again. The parser returns to its caller, in this case the main program, when the lexer reports the end of the input. Since sentence is the top-level symbol, the entire input must match a sentence. ![]() In our sentence rule, the action reports that we’ve successfully parsed a sentence. ![]() The parser executes an action at the end of a rule as soon as the rule matches. The action part of a rule consists of a C block, beginning with “”. It is usually read as “or,” e.g., in our grammar a subject can be either a NOUN or a PRONOUN. In our grammar we use the special character “|”, which introduces a rule with the same left-hand side as the previous one.
0 Comments
Leave a Reply. |