-> ---> a | b ---> 1 | 1파서 도움말 프로그램이 작동하지 않습니다.
a 또는 b와 1을 나중에 시작하는 것으로 가정합니다. 얼마나 많은 1이 a 나 b 뒤에 있는지는 중요하지 않습니다. 예를 들어 : A1, B1, b111111, A111 내가 입력 모든 유효하지만 유효한 있어야하는데 : A1, B1, b111111,
/*
<S> --> <A><B>
<A> ---> a | b
<B> ---> 1 | 1 <B>
It suppose to be vaild for example: a1, b1, b111111, a111
*/
#include <iostream>
#include<stdlib.h> // for the exit(1) function
using namespace std;
char text[100];
char ToBeChecked;
char lexical(); //identify the characters
void SProd();
void AProd();
void BProd();
int main()
{
cout<<"Enter a string(max. 100 characters"<<endl;
cin>>text;
ToBeChecked = lexical(); //identify the character; find the first letter and give it to ToBeChecked
SProd();
if(ToBeChecked = '\0')
cout<<"Valid"<<endl;
else
cout<<"Invalid"<<endl;
cin.get();
return 0;
}
char lexical()
{
static int index = -1; //a memory box named index with a value of -1; is static so it won't change.
//is -1 because -1 to 1 is 0; everytime move on to next one
index++; //update index
return text[index]; //return the value of index
}
//<S> --> <A> <B>
void SProd()
{
AProd();
BProd();
}
//<A> ---> a | b
void AProd()
{
if(ToBeChecked == 'a'){
ToBeChecked = lexical();
}
else
{
if(ToBeChecked == 'b'){
ToBeChecked = lexical();
}
}
}
//<B> ---> 1 | 1 <B>
void BProd()
{
if(ToBeChecked != '1')
{
cout<<"Invalid"<<endl;
exit(1);
}
else
while (ToBeChecked == '1')
ToBeChecked = lexical();
}
게시물을 다시 포맷해야 실제로 질문 할 수 있습니다. –
내가 입력 한 모든 내용은 유효하지 않지만 유효합니다. a1, b1, b111111, a111 – Mugetsu
이것은 진술입니다. 질문이 뭐야? – razlebe