Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char *x = "";
- int parse();
- int convert();
- int calc();
- int uInt();
- int equalSign();
- int sign();
- int term();
- int main()
- {
- if(parse())
- {
- std::cout << "successful";
- }
- else
- std::cout << "unsuccessful";
- }
- int parse()
- {
- if(uInt())
- {
- if(sign())
- {
- if(uInt())
- {
- if(equalSign())
- {
- return 1;
- }
- else{
- std::cout << "Equal sign expected\n";
- return 0;
- }
- }
- else
- {
- std::cout << "Expected digit\n";
- return 0;
- }
- }
- else
- {
- std::cout << "Operation sign expected\n";
- return 0;
- }
- }
- else
- {
- std::cout << "Expected digit\n";
- return 0;
- }
- }
- int uInt()
- {
- if(*x>='0' && *x<='9')
- {
- x++;
- uInt();
- return 1;
- }
- }
- int sign()
- {
- if(*x=='+' || *x=='/' || *x=='*' ||*x=='-')
- {
- x++;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int equalSign()
- {
- if (*x == '=')
- {
- return 1;
- }
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement