Recursive descent parser: Difference between revisions

Content deleted Content added
sort
Ululation (talk | contribs)
m Remove stray comma.
Line 50:
What follows is an implementation of a recursive descent parser for the above language in [[C (programming language)|C]]. The parser reads in source code, and exits with an error message if the code fails to parse, exiting silently if the code parses correctly.
 
Notice how closely the predictive parser below mirrors the grammar above. There is a procedure for each nonterminal in the grammar. Parsing descends in a top-down manner, until the final nonterminal has been processed. The program fragment depends on a global variable, ''sym'', which contains the current symbol from the input, and the function ''nextsym'', which updates ''sym'' when called.
 
The implementations of the functions ''nextsym'' and ''error'' are omitted for simplicity.