C ++帮助中的解析器!!我有流程图 [英] Parser in C++ Help!! I Have a Flowchart
本文介绍了C ++帮助中的解析器!!我有流程图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
推荐答案
另一个版本
/***************************************************
The following program will take user's input
and check whether it is in the following language:
<S> ---> a <B> | <A> | b
<A> ---> c <A> | c
<B> ---> d | <A>
****************************************************/
#include<iostream>
#include<string>
using namespace std;
#include<stdlib.h> // for the exit(1) function
char text[200]; // for input storage
char ThisOne; // for the checking character
char SProd(char ThisOne ); // <S> --> a <B> | <A> | b
char AProd(char ThisOne); // Grammar
char XProd(char ThisOne, char x);
char BProd(char ThisOne ); // <B> --> d | <A>
int main()
{
cout<<"Enter a string"<<endl;
cin>>text;
ThisOne = lexical();
SProd();
if(ThisOne == '\0')
cout<<"valid"<<endl;
else
cout<<"Invalid"<<endl;
}
char XProd(char ThisOne, char x)
{
ThisOne = XProd(ThisOne, 'a');
ThisOne = XProd(ThisOne, 'b');
ThisOne = XProd(ThisOne, 'c');
ThisOne = XProd(ThisOne, 'd');
return ThisOne;
}
char SProd(char ThisOne )
{
if(ThisOne == 'b')
{
ThisOne++;
}
else{
if(ThisOne == 'a')
{
ThisOne++;
BProd(ThisOne);
}
else{
AProd( ThisOne);
}
}
char AProd(char ThisOne)
{
if(ThisOne != 'c' )
{
cout<<"Invalid";
exit(1);
}
else{
ThisOne++;
while(ThisOne == 'c')
ThisOne++
return ThisOne
}
}
char BProd(char ThisOne )
{
if(ThisOne == 'd')
This++;
return ThisOne;
else
AProd(char ThisOne, char y);
}
这篇关于C ++帮助中的解析器!!我有流程图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文