0917 Experimental One lexical analysis program

Source: Internet
Author: User
Tags strcmp

#include <stdio.h> #include <string.h> #include <ctype.h> #define M 1000struct Key{char g[20];}; typedef struct Key Key;int main () {key k[6];int I=0,j=0;char a[m],b[m];strcpy (K[0].G, "Begin"), strcpy (K[1].G, "if"); strcpy (K[2].G, "then"), strcpy (K[3].G, "while"), strcpy (K[4].G, "do"), strcpy (K[5].G, "End");p rintf ("Please enter source program: \ n"); (a); while (a[i]!= ') {j=0;if ((Isalpha (a[i))) | | (a[i]== ' _ ')) {while ((a[i]!= ') && (a[i]!= ')) {if ((Isalpha (a[i))) | | (IsDigit (A[i])))     {B[j]=a[i];     j + +; i++;} Elsebreak;} if ((a[i]== ') | | (a[i]== '))    {b[j]= ' + ';                if (strcmp (B,K[0].G) ==0) printf ("Begin\t species Code 1\n");    else if (strcmp (B,K[1].G) ==0) printf ("if \ T species code 2\n");    else if (strcmp (B,K[2].G) ==0) printf ("then \ T species code 3\n");    else if (strcmp (B,K[3].G) ==0) printf ("While\t species Code 4\n");    else if (strcmp (B,K[4].G) ==0) printf ("Do t \ Species code 5\n");    else if (strcmp (B,K[5].G) ==0) printf ("End \ T species code 6\n"); else printf ("%s \ T species code 10\n", b);}Else{b[j]= ';p rintf ("%s \ T species code 10\n", b); i--;}}     else if (IsDigit (A[i])) {J=0;while (IsDigit (A[i])) {b[j]=a[i];     j + +; i++;} B[j]= ';p rintf ("%s \ T species code 11\n", b); i--;} Else{switch (A[i]) {case ' + ':p rintf ("%c \ Species Code 13\n", A[i]); Break;case '-':p rintf ("%c \ T species code 14\n", A[i]); Break;case ' * ' :p rintf ("%c \ Species Code 15\n", A[i]), break;case '/':p rintf ("%c \ T species code 16\n", A[i]); Break;case ': ': if (a[i+1]== ' = ') {printf (": = \ t Species code 18\n "); i++;break;} else{printf ("%c \ T species code 17\n", A[i]); Case ' < ': if (a[i+1]== ' = ') {printf ("<= \ T species code 21\n"); i++;break;} if (a[i+1]== ' > ') {printf ("<> \ T species code 22\n"); i++;break;} else printf ("%c \ Species Code 20\n", A[i]); Break;case ' > ': if (a[i+1]== ' = ') {printf (">= \ T species code 24\n"); i++;break;}   else printf ("%c \ Species Code 23\n", A[i]), break;case ' = ':p rintf ("= \ t species code 25\n"); Break;case '; ':p rintf ("; \ t species code 26\n ") break;case ' (':p rintf (" (\ t species code 27\n); Break;case ') ':p rintf (") \ T species code 28\n"); Break;case ' # ':p rintf (  "# \ t species code 0\n "); break;default:printf ("%c \ t syntax error!\n ", A[i]); break;}}    i++;}}

  

0917 Experimental One lexical analysis program

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.