#include <iostream.h>
#include <string.h>
#include <conio.h>
char a[10];

/*void readnext(){
	do{
		a=f.getch();
		
	}
	while(a != EOF);
}*/
void match(char x)
{
	if(x==a) 
		readnext();
	else cout<<"ERROR";
}
void program(){
	match("program");
	match("identifier");
	match(';');
	block();
}
void block(){
	match('begin');
	statement();
	statement();
	match('end');
}
void statement(){
	if(a!='identifier')
		ifstatement();
	eles
		assigstatement();}
void assigstatement(){
	match('identifier');
	match(':=');
	expr();
}
void ifstatemant(){
	match('if');
	match('identifier);
	if(a=='=' || a=='<>' || a=='<' || a=='<=' || a=='>=' || a=='>')
		readnext();
	match('identifier');
	match('then');
	statement();
}
void expr(){
  term();
  while(a=='+' || a=='-'){
    readnext();
    term();
    }
    }

void term(){
  fact();
  while(a=='*' || a=='/'){
    readnext();
    fact();
    }
    }

void fact(){
  if(a=='('){
    readnext();
    expr();
    if(a!=')')
      cout<<"Error, ) expected"<<endl;
    else
      readnext();
    }
  else
    if(a=='1' || a=='2' ||a=='3' || a=='4' || a=='5' || a=='6' || a=='7' || a=='8' || a=='9' || a=='0')
    while(a>='0' && a<='9')
      readnext();
  else
    cout<<"Error ,invalid input"<<endl;
    }
/*void main(){
ifstream f("Text1.txt");
if(!f)
{
 cout<<"Error...";
 exit(1);
}
f>>a;
program();
if(a==NULL)
cout<<"accept";
else
cout<<"ERROR";
}*/
void readnext(){
   do{
  a=getch();
  cout<<a;
  }while(a==' ');
}

void main(){
   clrscr();
  int k;
  do{
    cout<<"Enter 1 to continue"<<endl;
    cin>>k;
    cout<<"Enter your expression"<<endl;
    readnext();
    s();
    if(a !='.')
      cout<<" Error, . expected"<<endl;
    else
      cout<<"\n\nSuccess \n\n"<<endl;
  getch();
  }while(k==1);

  getch();
  }

