1014 Compilation Principle Second job (modified version)

Source: Internet
Author: User

#include <stdio.h> #include <string.h> #define MAX 100int n=0,i=0;char *keyshuru[6]={"Begin", "if", "then", " While "," Do "," End "};    void KEYword (char Shuru[max]) {int k=0,key=0,q=1;    Char Token[max]; while (shuru[i]!= ' # ') {while ((shuru[i]>= ' a ' &&shuru[i]<= ' z ') | | (shuru[i]>= ' A ' &&shuru[i]<= ' Z ') | |    (shuru[i]>= ' 0 ' && shuru[i]<= ' 9 ')) {if (shuru[i]>= ' a ' &&shuru[i]<= ' z ') | | (shuru[i]>= ' A ' &&shuru[i]<= ' Z ') | |        (shuru[i]>= ' 0 ' && shuru[i]<= ' 9 '))            {Token[n]=shuru[i];            n++;            token[n]= ' + '; i++;        if (shuru[i]>= ' 0 ' && shuru[i]<= ' 9 ') q++;        } for (k=0;k<6;k++) {key=0;            if (strcmp (Keyshuru[k],token) ==0) {printf ("%s%d\n", keyshuru[k],k+1);            Key=1;        Break }}}if ((shuru[i-q]>= ' a ' &&shuru[i-q]<= ' z ') | | (shuru[i-q]>= ' A ' &&shuru[i-q]<= ' Z ')) {if (key==0) {printf ("%s 10\n", token);}}    Key=1;    i=i+1;    n=0;    }}void character (char Shuru[max]) {int p=0,sign=0;            for (p=0;p<max;p++) {switch (Shuru[p]) {case ' + ': printf ("+ 13\n");        Break            Case '-': printf ("-14\n");        Break            Case ' * ': printf ("* 15\n");        Break            Case '/': printf ("/16\n");        Break                Case ': ': ' if (shuru[p+1]== ' = ') {printf (": = 18\n");            p++;            } else printf (": 17\n");        Break                Case ' < ': if (shuru[p+1]== ' = ') {printf ("<= 21\n");                Sign=1;            p++;                } else if (shuru[p+1]== ' > ') {printf ("<> 22\n");                Sign=1;            p++; } else IF (sign==0) printf ("< 20\n");        Break                Case ' > ': if (shuru[p+1]== ' = ') {printf (">= 24\n");            p++;            } else printf ("> 23\n");        Break            Case ' = ': printf ("= 25\n");        Break    Case '; ': printf (";            26\n ");        Break            Case ' (': printf ("(27\n)";        Break            Case ') ': printf (") 28\n");        Break            Case ' # ': printf ("# 29\n");        Break    }}} void number (char Shuru[max]) {int p=0,j=0,t=0,key=0,q=1;    Char Num[max];    while (shuru[p]!= ' # ') {key=0;j=0;        while (shuru[p]>= ' 0 ' && shuru[p]<= ' 9 ') {num[j]=shuru[p];        p++;        j + +;    key=1;q++; }if ((shuru[p-q]>= ' a ' &&shuru[p-q]<= ' z ') | |    (shuru[p-q]>= ' A ' &&shuru[p-q]<= ' Z ')) {Key=0;    Q=1;        } if (Key==1) {for (t=0;t<j;t++) {printf ("%c", num[t]);        } printf ("11\n");    j=0;    } p++;    }} main () {char A;     Char Shuru[max];     int p=0,j=0,m=0;    printf ("Please enter the source program, #键为结束标志:");        do{scanf ("%c", &a);        Shuru[p]=a;    p++; }while (a!= ' # ');    KEYword (Shuru);    Character (Shuru); Number (Shuru);}

  

1014 Compilation Principle Second job (modified version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.