Twelfth job - recursive descent parser

First, the purpose of the experiment:

The use of C language compiled recursive descent parsing procedures, and simple language parsing.

The preparation of a recursive descent parser, syntax checking and realize the structure of the word lexical analysis program provided by sequence analysis.

 

Second, the experimental principle

Each nonterminal symbol corresponds to a subroutine.

This subroutine is determined according to a next input symbol (SELECT sets) which are processed in a production, then the right end of the production according to:

  • Each encounter a terminator, it is determined whether the current read word matches the terminator, if matched, then the next word is read to continue the analysis; do not match, an error process is performed
  • Each encounter a nonterminal, the appropriate subroutine is called

 

Third, the experiment asked for clarification

Enter the word string to "#" end if the grammar is correct sentences, the output success information, print "success", otherwise output "error", and pointed out grammatical errors of the type and location.

E.g:

Input begin a: = 9; x: = 2 * 3; b: = a + x end #

Output success

Input x: = a + b * c end #

Output 'end' error

 

Fourth, the experimental procedures

      1. Grammar of the language to be analyzed (refer to P90)

      2. Grammar to be expressed, at least comprising

- Statement

-condition

-expression

3. eliminate left recursion

4. Extract the left common factor

5. SELECT set computing

6. LL (1) grammar is determined

7. recursive descent parser

Guess you like

Origin www.cnblogs.com/codekid/p/11950548.html