zoukankan      html  css  js  c++  java
  • 词法分析器

    分析器有个问题一直无法解决,分析完会出现27和28。

    #include<stdio.h>
    #include<stdlib.h>
    void main()
    {
    int i;
    char s[100];
    printf("请输入字符串:");
    scanf("%s",&s);
    for(i=0;i<100;i++)
    {
    if(s[i]=='b'&&s[i+1]=='e'&&s[i+2]=='g'&&s[i+3]=='i'&&s[i+4]=='n')
    printf("1 , begin ");
    else if(s[i]=='i'&&s[i+1]=='f')
    printf("2 , if ");
    else if(s[i]=='t'&&s[i+1]=='h'&&s[i+2]=='e'&&s[i+3]=='n')
    printf("3 , then ");
    else if(s[i]=='w'&&s[i+1]=='h'&&s[i+2]=='i'&&s[i+3]=='l'&&s[i+4]=='e')
    printf("4 , while ");
    else if(s[i]=='d'&&s[i+1]=='o')
    printf("5 , do ");
    else if(s[i]=='e'&&s[i+1]=='n'&&s[i+2]=='d')
    printf("6 , end ");
    else if(s[i]=='l'&&s[i+1]=='('&&s[i+2]=='l'&&s[i+3]=='|'&&s[i+3]=='d'&&s[i+3]==')'&&s[i+4]=='*')
    printf("10 , l(l|d)* ");
    else if(s[i]=='d'&&s[i+1]=='d'&&s[i+2]=='*')
    printf("11 , dd* ");
    else if(s[i]=='-')
    printf("14 , - ");
    else if(s[i]=='*')
    printf("15 , * ");
    else if(s[i]=='/')
    printf("16 , / ");
    else if(s[i]==':'&&s[i+1]!='=')
    printf("17 , : ");
    else if(s[i]==':'&&s[i+1]=='=')
    printf("18 , := ");
    else if(s[i]=='<'&&s[i+1]!='='&&s[i+1]!='>')
    printf("20 , < ");
    else if(s[i]=='<'&&s[i+1]=='=')
    printf("21 , <= ");
    else if(s[i]=='<'&&s[i+1]=='>')
    printf("22 , <> ");
    else if(s[i]=='>'&&s[i+1]!='=')
    printf("23 , > ");
    else if(s[i]=='>'&&s[i+1]=='=')
    printf("24 , >= ");
    else if(s[i]=='=')
    printf("25 , = ");
    else if(s[i]==';')
    printf("26 , ; ");
    else if(s[i]=='(')
    printf("27 , ( ");
    else if(s[i]==')')
    printf("28 , ) ");
    else if(s[i]=='#')
    printf("0 , # ");

    }

    }

  • 相关阅读:
    uploadify
    mark down pad2
    yii1.1.3主从(多从)、读写分离配置
    yii多数据库
    Uploadify上传问题
    出现upstream sent too big header while reading response header from upstream错误
    Nginx 启动脚本/重启脚本
    VB6_小林的气象类模块
    进程与线程
    JDK动态代理与CGLib
  • 原文地址:https://www.cnblogs.com/BOXczx/p/5937909.html
Copyright © 2011-2022 走看看