c语言编译器 mini,minic - 源码下载|其它|编译器/词法分析|源代码 - 源码中国

expr.cpp

expr.h

expr.o

lex.yy.c

lexer.l

makefile

minic

minic.h

parser.y

README.txt

stmt.cpp

stmt.h

stmt.o

symbol.cpp

symbol.h

symbol.o

test

testfile

testfile2

....\error.tar.gz

....\error1.minic

....\error10.minic

....\error11.minic

....\error12.minic

....\error13.minic

....\error14.minic

....\error2.minic

....\error3.minic

....\error4.minic

....\error5.minic

....\error6.minic

....\error7.minic

....\error8.minic

....\error9.minic

....\Isqrt.asm

....\Isqrt.minic

....\t1.asm

....\t1.minic

....\t10.asm

....\t10.minic

....\t11.asm

....\t11.minic

....\t12.asm

....\t12.minic

....\t2.asm

....\t2.minic

....\t3.asm

....\t3.minic

....\t4.asm

....\t4.minic

....\t5.asm

....\t5.minic

....\t6.asm

....\t6.minic

....\t7.asm

....\t7.minic

....\t8.asm

....\t8.minic

....\t9.asm

....\t9.minic

....\testcases.tar

y.tab.c

y.tab.h

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
minic编译器词法分析器主要用来将源代码文本转换为单词序列,每个单词代表程序中的一个符号。下面是一个简单的minic编译器词法分析器的示例: ```c #include <stdio.h> #include <ctype.h> #define MAX_TOKEN_LEN 100 typedef enum { T_EOF, T_PLUS, T_MINUS, T_MULTIPLY, T_DIVIDE, T_ASSIGN, T_SEMICOLON, T_LPAREN, T_RPAREN, T_IDENT, T_NUMBER } TokenType; typedef struct { TokenType type; char value[MAX_TOKEN_LEN + 1]; } Token; Token get_token() { Token token = {T_EOF, ""}; int i = 0; char c = getchar(); while (isspace(c)) { c = getchar(); } if (c == '+') { token.type = T_PLUS; } else if (c == '-') { token.type = T_MINUS; } else if (c == '*') { token.type = T_MULTIPLY; } else if (c == '/') { token.type = T_DIVIDE; } else if (c == '=') { token.type = T_ASSIGN; } else if (c == ';') { token.type = T_SEMICOLON; } else if (c == '(') { token.type = T_LPAREN; } else if (c == ')') { token.type = T_RPAREN; } else if (isalpha(c)) { token.type = T_IDENT; token.value[i++] = c; c = getchar(); while (isalnum(c) && i < MAX_TOKEN_LEN) { token.value[i++] = c; c = getchar(); } ungetc(c, stdin); } else if (isdigit(c)) { token.type = T_NUMBER; token.value[i++] = c; c = getchar(); while (isdigit(c) && i < MAX_TOKEN_LEN) { token.value[i++] = c; c = getchar(); } ungetc(c, stdin); } token.value[i] = '\0'; return token; } int main() { Token token; do { token = get_token(); printf("Token: type=%d, value=%s\n", token.type, token.value); } while (token.type != T_EOF); return 0; } ``` 该词法分析器根据minic编译器的语法规则,识别出了 +、-、*、/、=、;、(、)、标识符和数字这些单词,并将它们分别以相应的类型和值存储在Token结构体中。这些Token可以进一步被用于minic编译器的语法分析和代码生成等阶段。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值