Modified LL (1) grammatical analysis program

zhaozj2021-02-16  74

Make a modification of the previous program, use the C standard library, remove the class written, and it is a bit.

/ * * File Name: Syntax Analysis. H * Summary: Analysis Table and String of Any Enter LL (1) Grammar, this program can automatically determine whether the string is * No is the sentence of this gram, and can give Analysis process. * Current version: 1.2 * Author: happyjyr * Completion Date: 2004.6.8 * Modification Date: 2004.7.24 ** /

#include #include #include #include

Using namespace std;

Void showstack (stack st) {INT I, J; Char Ch [100]; j = st.size (); for (i = 0; i = 0; I -) {cout << ch [i]; st.push (ch [i]);}} bool find (CHAR C, CHAR ARRAY []) // Find functions, return to Boolean value {INT I; BOOL FLAG = false; for (i = 0; i <100; i ) {if (c == array [i]) Flag = True;} Return flag;} int location (CHAR C, CHAR Array [] // Positioning function indicates the location of the character {INT i; for (i = 0; i <100; i ) {if (c == Array [I]) Return I;}} void error () {cout << "error!" << Endl;} void analyse (char vn [], char vt [], string m [100] [100]) { INT I, J, M, P, Q, LENGTH, T, H; CHAR W, X; String Str; OPT0: CIN >> Str; for (i = 0; I st; st.push (' # '); St.push (vn [0]); // # and identification symbols into the stack J = 0; h = 1; w = Str [0]; cout << "step" << "Analysis Stack" < <"Remaining input string" << "The generated" << endl; OPT1: COUT << h << ""; // Displays step h ; showstack (st); // Displays the content cout << "in the analysis stack (t = j; t

w) // Analysis Stack top element and the first element of the remaining input string compare {cout << "<< << << <<" << "<< Endl; J ; w = str [J]; GOTO OPT1 Else error ();} else {if (x == '#') {if (x == w) {cout << "" << "accept!" << endl << endl;} else Error );} Else {p = location (x, vn); q = location (w, vt); String S1 ("null"), S2 ("null"); if (m [p] [q] == S1 || M [P] [q] == S2) / / Find the generated error () in the two-dimensional array (); else {string str000 = m [p] [q]; cout << "<< x << "->" << STR0 << Endl; // Displays the corresponding generated IF (STR0 == "$") GOTO OPT1; Else {length = str0.size (); // Reversible Inn for (m = Length-1; m> = 0; m -) {st.push (STR0 [M]);} goto OPT1;}}}}} main ()}}} main ()}}} main ()}}} main ()}}} main ()}}} main ()}}} main ()}}} ], Vt [100], select; string m [100] [100]; cout << "* file name: syntax analysis" << Endl; cout << "* Summary: Analysis table and string of any input LL (1) text method, this program can automatically determine that the string is" << endl; cout << "* No is the grafting method Sentence and can give the analysis process.

转载请注明原文地址:https://www.9cbs.com/read-13361.html

New Post(0)