미니 컴파일러 구현(소스 및 실행화면 다큐먼트)
- 최초 등록일
- 2005.05.13
- 최종 저작일
- 2005.05
- 29페이지/ 한컴오피스
- 가격 1,000원
소개글
컴파일러 단골 숙제인 미니 컴파일러 렉스 분석기입니다. 입력을 직접 입력 또는 파일 입력으로 받아 토큰을 나눠 주고 토큰의 번호와 토큰의 값을 출력해주는 완전 프로그램입니다. 인터페이스 깔끔하고요, 실행 최적화 되어 있습니다. (하시다가 않되시면 inthemix@naver.com으로 문의 주시면 답변해드립니다.)
컴파일 실행환경
비쥬얼 스트디오 또는 C언어를 인식할수 있는 컴파일러
본문내용
tokenType scanner(){
tokenType token;
int i, index;
char ch, id[ID_LENGTH];
token.number = tnull;
do{
while (isspace(ch = getchar()))
{
if(ch==`n`)
line++; // 라인을 출력하기 위한 라인 검색 부분
}; // steate 1 : skip blanks
if(superLetter(ch)){ // identifier or keyword
i = 0;
do{
if (i < ID_LENGTH) id[i++] = ch;
ch = getchar();
} while (superLetterOrDigit(ch)); //do while문 끝
if (i >= ID_LENGTH) lexicalError(1);
id[i] = ``;
ungetc(ch,stdin); // retract
// find the identifier in the keyword table
for(index = 0; index < NO_KEYWORDS; index++)
if (!strcmp(id, keyword[index])) break;
if (index < NO_KEYWORDS) // found, keyword exit
{
token.number = tnum[index];
token.value.id[0] = `0`; // 키워드 value // `0`을 넣어준다.
token.value.id[1] = ``;
} // if 문 끝
else { // not found, identifier exit
token.number = tident;
strcpy(token.value.id, id);
}
} // end of iden
참고 자료
없음