소개글
정익사 `컴파일러 입문`에 나오는 MiniC 예제 소스를 바탕으로 하여 보완, 완성한것입니다.
컴파일 실행환경
MiniC 어휘분석기 프로그램 소스(Visual C++ 6.0 콘솔)
실행화면 캡춰
본문내용
아래의 프로그램 소스는 교재‘컴파일러 입문’의 예제 소스를 바탕으로 하여 보완, 완성한 것이다.
--------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define NO_KEYWORDS 7
#define ID_LENGTH 12
enum tsymbol { tnull = -1,
tnot, tnotequ, tmod, tmodAssign, tident, tnumber,
// 0 1 2 3 4 5
tand, tlparen, trparen, tmul, tmulAssign, tplus,
// 6 7 8 9 10 11
tinc, taddAssign, tcomma, tminus, tdec, tsubAssign,
// 12 13 14 15 16 17
tdiv, tdivAssign, tsemicolon, tless, tlesse, tassign,
// 18 19 20 21 22 23
tequal, tgreat, tgreate, tlbracket, trbracket, teof,
// 24 25 26 27 28 29
// ................word symbols .......................
tconst, telse, tif, tint, treturn, tvoid,
// 30 31 32 33 34 35
twhile, tlbrace, tor, trbrace
// 36 37 38 39
};
struct tokenType {
int number;
union {
char id[ID_LENGTH];
int num;
}value; // token value
참고 자료
정익사 `컴파일러 입문`