대학교/4.컴파일러3 [03] lex.l main.c main.c #include #include #include "lex.h" extern FILE *yyin; /* input stream */ extern int yylval, /* integer value of TK_NUM */ yylen; /* length of TK_ID string */ extern char *yytext; /* point to TK_ID string */ main(argc, argv) register int argc; register char *argv[]; { int n, i; char *c; if (argc != 2) { fprintf(stderr, "usage: scan \n"); exit(1) ; } if ((yyin = fopen(argv[1], "r")) .. 2019. 4. 14. [02] lex.c main.c main.c #include #include #include #include "lex.h" extern int get_tok(); extern int yylval, /* integer value of TK_NUM */ yylen; /* length of TK_ID string */ extern char yytext[]; /* point to TK_ID string */ extern FILE *fin; main(int argc, char *argv[]) { int n, i; char *pc; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); exit(1) ; } if ((fin = fopen(argv[1], "r")) == NULL) { .. 2019. 4. 14. [01] wc main.c#include #include extern void countfile(), printtotal(); main(int argc, char *argv[]) { register FILE *fp; register int i; if (argc == 1) countfile(stdin, ""); else { i = 1; while (i 2) printtotal(); } exit(0); } wc.c #include #define BufSize 16#define Sentinel '\0'static unsigned char buf[BufSize*2+1];static unsigned char *lexeme_beginning, *forward;#define NextChar() ((*forward)? *forwar.. 2019. 3. 20. 이전 1 다음