| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 654 人关注过本帖
标题:用C语言采用模拟DFA算法编写一个扫描器(词法分析器)
只看楼主 加入收藏
淡雅蜻蜓
Rank: 1
等 级:新手上路
帖 子:23
专家分:8
注 册:2010-11-21
结帖率:25%
收藏
 问题点数:0 回复次数:0 
用C语言采用模拟DFA算法编写一个扫描器(词法分析器)
用C语言采用模拟DFA算法编写一个扫描器(词法分析器),用来识别:由任意个a或b开始后接aa再自加或自减1的字符串,即正规式r=(a|b)*aa(+|-)1描述的语言L(r)。 哪个高手帮我把下面那段语言改用C来写啊,谢谢啦

#include<iostream>
#include<string>
using namespace std;
bool scan(string &s);

//-------------------------------
void main()
{
    cout<<"请输入一串字符"<<endl;
    string s;
    cin>>s;
    bool tag;
    tag=scan(s);
    {
            if(tag==true)
        cout<<s<<"为可识别字符串"<<endl;
   
            else if(tag==false)
        cout<<s<<"为不可识别字符串"<<endl;
                cout<<end1<<"DFA如下"<<endl;
                outputfa(len,h,t);<<输出DFA
                cout<<"其中终态:"<<endnode<<endl;
//DFA最小化
}
//-------------------------------
bool scan(string &s)
{
    bool flag=true;
    int i=1;
    char c=s[0];
    if(c!='a'&&c!='b') return false;
    c=s[1];
    while(c!=NULL&&flag)
    {
        if(c=='a'||c=='b')
            i++;
      else    if(c=='-'||c=='+')
        {
            if(s[i+1]=='1'&&s[i+2]==NULL&&s[i-1]=='a'&&s[i-2]=='a')
                return true;
            else
                return false;
        }
        else
            flag=false;
        c=s[i];
    }
    return flag;
}
搜索更多相关主题的帖子: 扫描器 算法 include C语言 字符串 
2012-05-05 13:36
快速回复:用C语言采用模拟DFA算法编写一个扫描器(词法分析器)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010745 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved