C语言词法分析器

本文深入探讨了C语言词法分析器的工作原理,详细解释了如何识别和处理C语言源代码中的关键字、标识符、常量、运算符和分隔符。通过实例展示了词法分析器的实现过程,帮助读者理解编译原理中的关键步骤。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _KEY_WORD_END "waiting for your expanding"
typedef struct
{
   
    int ConstL;
    char *NameL;
}WORD;
char input[255];
char token[255]="";
int p_input;
int p_token;
char ch;
char* rwtab[] = {
   "if", "else", "for", "while", "break", "return", "continue", "float", "int","char",_KEY_WORD_END};
WORD * scaner();

int main()
{
   
    int over = 1;
    WORD* oneword = new WORD;
    printf("Enter Your words(end with #):");
    scanf("%[^#]s",input);
    p_input = 0;
    printf("Your words:\n%s\n",input);
    while(over < 38 && input[p_input]!='\0')//over !=-1
    {
   
        oneword = scaner();
        if(oneword->ConstL <38)
            printf("( %d,%s )\n",oneword->ConstL,oneword->NameL);
        over = oneword->ConstL;
    }
    printf("\npress # to exit:");
    scanf("%[^#]s",input);
    return 0;
}
char m_getch()//从输入缓冲区读取一个字符到ch中
{
   
    ch = input[p_input];
    p_input = p_input+1;
    return(ch);
}
void getbc()//去掉空白符号
{
   
    while(ch == ' ' || ch == 10)
    {
   
        ch = input[p_input];
        p_input++;
    }
}
void concat
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值