ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 09 May 2017 My Price 8.00

A simple parser for C/C++-style variable declarations

// A simple parser for C/C++-style variable declarations. // THe grammar is as follows: // // <declaration> ::= <type> <var> ';' | <type> <var> '=' <number> ';' // <type> ::= int | float // <var> ::= A | B | C | D | E // <number> ::= <integer> | <float> // <integer> ::= <integer> <digit> | <digit> // <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 // <float> ::= <integer> '.' <integer> // // Input is entered at the keyboard. // If the input is correct, the program should print // "no error found", otherwise, it should print the type // of error and terminate its execution. There are four // possible errors: // // "unrecognizable type" // "illegal variable name" // "unexpected number" // "; expected" // // Error message is printed out by calling function // "error". An error code ranging from 0 to 4 can be // passed as an argument to the function indicating what // message is to be printed. The mapping from the error // code to the message can be found by looking at the // definition of function "error". // // The following are some sample input and the response // from the program: // // Please enter a declaration in format <type> <variable> [= number] ; // int A; // no error found // // Please enter a declaration in format <type> <variable> [= number] ; // int a; // illegal variable name // // Please enter a declaration in format <type> <variable> [= number] ; // short B; // unrecognizable type // // Please enter a declaration in format <type> <variable> [= number] ; // float C = 0.5; // no error found // // Please enter a declaration in format <type> <variable> [= number] ; // int A = 10, // unexpected token #include <iostream> #include <string> using namespace std; string token; string GetToken(); void error(int); int main() { cout << "Please enter a declaration in format " << "<type> <variable> [= number] ;" << endl; token = GetToken(); // Write the code here error(0); return 0; } string GetToken() { // Use the Gettoken function you have designed in Lab 1. } void error(int code) { switch (code) { case 0: cout << "no errors found" << endl; break; case 1: cout << "unrecognizable type" << endl; break; case 2: cout << "illegal variable name" << endl; break; case 3: cout << "unexpected number" << endl; break; case 4: cout << "; expected" << endl; } return; }

Answers

(11)
Status NEW Posted 09 May 2017 05:05 AM My Price 8.00

-----------

Not Rated(0)