Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.225.254.81
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/grpatillo/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/grpatillo/WFFcatcher2.cpp
/*	Author:         R.P. Patillo
        Instructor:     Dr. Ames
        Due Date:       Oct. 23, 2008
        Complilation:   g++ WFFcatcher2.cpp -o WFFcatcher2.out
        Execution:      ./WFFcatcher2.out
*/

#include <iostream>

using namespace std;

//----------------------
// WFF Catcher
//----------------------

bool WFFcatch()
{   
    char ch;
    cin.get(ch);

    if(ch != '\n')						// the starting  "if" loop 
    {
	if(ch == 'p' || ch == 'q' || ch == 'r' || ch == 's')	// base case stating WFF rule of p,q,r, or s
	{
	    return true;
	}

	else if(ch == 'N')
	{
	    return WFFcatch();					// Recursive call that supports WFF rule for N
	}
	
	else if(ch == 'C' || ch == 'A' || ch == 'K' || ch == 'E')	// Recursive call that states WFF rule for C, A, K, and E
	{ 
	    return (WFFcatch() && WFFcatch());	
	}

	else
	    return false;					// Return false if input doesn't follow any of the rules
    }

    else
	return false;		
}

//----------------------------------------------------


int main ()
{
    char ch;

    cout << "Enter a well-formed formula: ";

    if (WFFcatch())						// ensures that the input was a WFF
    {
	cin.get(ch);
	if(ch == '\n')
	    cout << "well formed" << endl;
	
	else
	    cout << "error" << endl;
    }

    else
	cout << "error" << endl;

    return 0;
}

Stv3n404 - 2023