*정*
개인
판매자 정보
- 학교정보
-
입력된 정보가 없습니다.
- 직장정보
-
입력된 정보가 없습니다.
- 자격증
-
판매지수
-
- 판매중 자료수
- 4개
-
- 전체 판매량
- 178개
-
- 최근 3개월 판매량
- 0개
-
- 자료후기 점수
- 평균B
-
- 자료문의 응답률
- 0%
전체자료 4개
-
-
[컴파일러] c언어로 구현한 MINI-c 어휘분석기
평가B괜찮아요
-
■ Source Codescanner.c 실제 어휘 분석을 담당하는 코드#include #include #include #include #define ID_LENGTH 12#define NUMKEYWORD 7//키워드의 개수#define MAX_BYTE 1000//출력결과를 저장하기 위한 크기 제한//토큰번호와 토큰값을 저장struct tokentype {int number; //토큰의 번호union {char id[ID_LENGTH];int num;} value;};int index=0;//예약어 테이블char *keyword[] ={"const", "else", "if", "int", "return", "void", "while", "lbrace" , "or", "rbrace"};char tmpStr[MAX_BYTE];//출력결과를 저장하기 위한 크기 제한//MINI C 의 각 심벌 및 연산자 및 예약어enum tsymbol {tnull=-1,tnot,tnotequ, tmod,tmodAssign,tident,tnumber,// 012345tand,tlparen,trparen,tmul,tmulAssign, tplus,// 67891011tinc,taddAssign,tcomma,tminus,tdec,tsubAssign,// 121314151617tdiv,tdivAssign,tsemicolon,tless,tlesse,tassign,// 181920212223tequal,tgreattgreate,tlbracket,trbracket,teof,// 242526272829//////////////................KEY WORD SYMBOL......//////////////////tconst,telse,tif,tint,treturn,tvoid,// 303132333435twhile,tlbrace,tor,trbrace// 36373839};//MINI C의 예약어 심볼enum tsymbol tnum[] = {tconst,telse,tif,tint,treturn,tvoid,twhile,tlbrace,tor,trbrace};void lexicalError(int n){//에러를 핸들링하기 위한 함수구현printf("****Lexical Error : ");switch (n){case 1 ://식별자길이(12자리) 초과할경우printf("식별자의 길이는 12자 이내로 입력하여 주십시오n");break;case 2 :printf("&다음의 문자는 반드시 공백이나 &를 입력하여 주십시오n");break;case 3 :printf("|다음의 문자는 반드시 공백이나 |를 입력하여 주십시오n");break;case 4 :printf("올바르지 않은 문자입니다!!!!n");break;}}struct tokentype scanner() {struct tokentype token;//토큰 정보를 반환하기 위한 tokentype 변수 선언int i,j,k,num;char ch, id[ID_LENGTH];token.number = tnull;do{while((ch = tmpStr[index]) ==' ') index++;// 공백을 무시하는 루틴if (isalpha(ch)){//알파벳으로 시작하는 식별자 또는 예약어i=0;do{if(i < ID_LENGTH) id[i++] = ch;index++;ch = tmpStr[index]; //다음문자를 반환}while (isalnum(ch)); //알파벳 또는 숫자형이 아닐경우까지 계속//if(i>=ID_LENGTH) lexicalError(1);id[i] = '