Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

/* * * C version * */ // E => T + E | T - E | T // T => F * T | F / T | F // F => I | D | ( E ) // I => a | ... | z // D => 0 | ... | 9 #include #include bool E(void); bool T(void); bool F(void); bool I(void); bool D(void); char *s; int main(int argc, char *argv[]) { char *t; s = t = argc == 2 ? argv[1] : ""; if (E() && *s == '\0') { XXXXXXXXXXprintf("The string \"%s\" is in the language.\n", t); } else { XXXXXXXXXXprintf("The string \"%s\" is not in the language.\n", t); } return 0; } bool E(void) { if (T()) { XXXXXXXXXXif (*s == '+' || *s == '-') { XXXXXXXXXXs; XXXXXXXXXXif (E()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } XXXXXXXXXXreturn true; } return false; } bool T(void) { if (F()) { XXXXXXXXXXif (*s == '*' || *s == '/') { XXXXXXXXXXs; XXXXXXXXXXif (T()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } XXXXXXXXXXreturn true; } return false; } bool F(void) { if (I()) { XXXXXXXXXXreturn true; } else if (D()) { XXXXXXXXXXreturn true; } else if (*s == '(') { XXXXXXXXXXs; XXXXXXXXXXif (E()) { XXXXXXXXXXif (*s == ')') { XXXXXXXXXXs; XXXXXXXXXXreturn true; } } } return false; } bool I(void) { if ('a' <= *s && *s <= 'z') { XXXXXXXXXXs; XXXXXXXXXXreturn true; } return false; } bool D(void) { if ('0' <= *s && *s <= '9') { XXXXXXXXXXs; XXXXXXXXXXreturn true; } return false; } /* * * C++ version * */ // E => T + E | T - E | T // T => F * T | F / T | F // F => I | D | ( E ) // I => a | ... | z // D => 0 | ... | 9 #include #include using std::cout; using std::endl; using std::string; bool E(void); bool T(void); bool F(void); bool I(void); bool D(void); string s; int main(int argc, char *argv[]) { string t; s = t = argc == 2 ? argv[1] : ""; if (E() && s == "") { XXXXXXXXXXcout << "The string \"" << t << "\" is in the language." << endl; } else { XXXXXXXXXXcout << "The string \"" << t << "\" is not in the language." << endl; } return 0; } bool E(void) { if (T()) { XXXXXXXXXXif (s[0] == '+' || s[0] == '-') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXif (E()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } XXXXXXXXXXreturn true; } return false; } bool T(void) { if (F()) { XXXXXXXXXXif (s[0] == '*' || s[0] == '/') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXif (T()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } XXXXXXXXXXreturn true; } return false; } bool F(void) { if (I()) { XXXXXXXXXXreturn true; } else if (D()) { XXXXXXXXXXreturn true; } else if (s[0] == '(') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXif (E()) { XXXXXXXXXXif (s[0] == ')') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXreturn true; } } } return false; } bool I(void) { if ('a' <= s[0] && s[0] <= 'z') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXreturn true; } return false; } bool D(void) { if ('0' <= s[0] && s[0] <= '9') { XXXXXXXXXXs = s.substr(1); XXXXXXXXXXreturn true; } return false; } /* * * Java version * */ // E => T + E | T - E | T // T => F * T | F / T | F // F => I | D | ( E ) // I => a | ... | z // D => 0 | ... | 9 public class Main { public static void main(String[] args) { XXXXXXXXXXs = args.length == 1 ? args[0] : ""; XXXXXXXXXXif (E() && i == s.length()) { XXXXXXXXXXSystem.out.println("The string \"" + s + "\" is in the language."); } XXXXXXXXXXelse { XXXXXXXXXXSystem.out.println("The string \"" + s + "\" is not in the language."); } } private static boolean E() { XXXXXXXXXXif (T()) { XXXXXXXXXXif (i < s.length() && (s.charAt(i) == '+' || s.charAt(i) == '-')) { XXXXXXXXXXi; XXXXXXXXXXif (E()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; } private static boolean T() { XXXXXXXXXXif (F()) { XXXXXXXXXXif (i < s.length() && (s.charAt(i) == '*' || s.charAt(i) == '/')) { XXXXXXXXXXi; XXXXXXXXXXif (T()) { XXXXXXXXXXreturn true; } XXXXXXXXXXreturn false; }
Answered Same Day Jun 07, 2022

Solution

Aditi answered on Jun 08 2022
90 Votes
ASSIGNMENT
1. C++ Solution:
a. Create one main program file and the code for the same is:
#include#include#includeusing namespace std;
declare local variables
int i, j;
string input;
function prototype
int A_G();
int E_G();
int P_G(int k);
int L_G();
int I_G();
int UI_G();
int UL_G();
main method
int main()
{

declare input file stream

with file name
ifstream file("input.txt");

use while loop to read the file
while (!file.eof())
{

set local variables to 0
i = 0;
j = 0;

ead the file input
file
input;

If the return value of E is not equal to -1

then print message input is in the language
if (A_G() != -1 && i == input.length())
{
cout
"The string "
input
" is in the language\n";
}

Otherwise, it will be shown not in the language
else
{
cout
"The string "
input
" is not in the language\n";
}
}

close file stream
file.close();
return 0;
}
int A_G()
{
if (I_G() != -1)
{
i = j;
if (input[i++] == '=')
{
if (E_G() != -1)
return 0;
}
else
{
i = 0;
if (E_G() != -1)
return 0;
}
}
else
{
i = 0;
if (E_G() != -1)
return 0;
}
return -1;
}
int E_G()
{
if (P_G(-1) != -1)
{
if (i == input.length())
return 0;
else
{

Implement the production O -> + | - | * | / | **
if (input[i] == '+' || input[i] == '-' || input[i] == '*' || input[i] == '/')
{
i++;
if (P_G(1) != -1)
return 0;
}
}
}
return -1;
}
int P_G(int k)
{

cout
"\nP_G()";
if (I_G() != -1)
{
if (k == -1)
{
i = j;
return 0;
}
else
{
if (j == input.length())
{
i = j;
return 0;
}
else
return E_G();
}
}
else if (L_G() != -1)
{
if (k == -1)
{
i = j;
return 0;
}
else
{
if (j == input.length())
{
i = j;
return 0;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here