GRAMMAR ANALYZER - Clemson University

[Pages:2]GRAMMAR ANALYZER

I. Given a grammar as input, the Grammar Analyzer program can be directed to

1) determine if that grammar is a Simple, Weak, or Operator Precedence,

2) build the appropriate Precedence Relations Matrix, and

3) try to calculate one or more of the Linear Precedence Functions that represent the entries of the precedence matrix.

The specific actions to perform are specified by a set of directives embedded in the file containing the grammar specification.

To use the Grammar Analyzer, a grammar is encoded in a file using the format described below. Additionally, certain directives (or commands) are added to the file that tells the Grammar Analyzer what processing is to be performed. This file is then directed as standard input to the analyzer program. The output from the Grammar Analyzer is on standard output.

To simplify the use of the Grammar Analyzer, a shell script is provided that invokes the analyzer and properly directs the I/O. This shell script is called 'analyzer.sh' and can be found on the class web site directly under the link to the current semester's grammar. You should download the script into the working directory where the grammar files will be used.

To use the Grammar Analyzer with this shell script, simply enter

analyzer.sh

where is replaced with the name of the file containing the grammar. The output report will be in the file named 'filename.out'.

Note: The Grammar Analyzer program resides in /home/grossman/faculty/analyzer and is called 'analyzer.2' or `analyzer.2.centos' depending on which operating system you are using.

II. The grammar is specified by putting productions, directives and comments in a file using the following format. The first column of each record specifies whether the record contains a production, directive or comment.

Column 1 = $ The record contains a directive or comment. The legal directives are:

SP

- calculate simple precedence matrix

OP

- calculate operator precedence matrix

WP

- calculate weak precedence matrix

SPFILE - output results on "spfile"

OPFILE - output results on "opfile"

WPFILE - output results on "wpfile"

PFFILE - output results on "pffile"

FLOYD - precedence functions via Floyd's method

MARTIN - precedence functions via Martin's method

BELL - precedence functions via Bell's method

Column 1 = nonblank and not $ This record contains a production in the following format: L R1 R2 R3 . . . where L, R1, R2, R3, . . . are symbol strings representing either terminals or non-terminals. Each may be up to 14 characters long. Each component is separated from its neighbors by one or more blanks. L is assumed to be the left hand side of the production and R1, R2, R3, . . . are the components of a single alternative.

Column 1 = blank This record contains only the right hand side of a production and is assumed to be an alternative definition of the last encountered L. The format is: R1 R2 R3 . . .

III. File Formats

The four files (spfile, opfile, pffile, wpfile) have identical information at the beginning of each.

Record 1 contains the total number of productions(npr), the total number of symbols(Vn), and the total number of terminal symbols(Vtn), respectively.

The next Vn records contain the actual symbols used in the productions.

The next npr records contain the numeric encoding of the productions where the number j represents the jth symbol to occur on the preceding record. Each record is of the following format:

N R1 R2 . . . Rn L where n is the number of symbols on the right hand side of the production, R1, R2, . . . Rn are the encoded symbols of the production's right hand side, and L is the encoding of the symbol on the left hand side.

The remainder of the file has the following information:

spfile

The next Vn records contain the simple precedence matrix written one row per record. number of symbols in the grammar. The precedence relations in the file are encoded as

no relation : 0 less than : 3 equal : 1

greater than : 2

Vn is the

opfile The next Vtn records contain the operator precedence matrix written one row per record. The precedence relations are encoded as before.

wpfile Same information as in the spfile.

pffile

The next k records contain 3 numbers: the encoded symbol for which the next two values are the F and G function values, respectively. k is either Vn if simple precedence or weak precedence relations were used or Vtn if operator precedence relations were used in calculating the precedence functions.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download