II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

Size: px
Start display at page:

Download "II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y"

Transcription

1 II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word tmp2 tmp2->next yytext 50 1

2 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define MAXSIZE struct LIST { 7 struct LIST * next; 8 char *word; 9 }; main(){ 12 char buf[maxsize]; 13 struct LIST *h, *t, *tmp; /* for making dummy leading node */ 16 h = (struct LIST*) malloc(sizeof(struct LIST)); 17 if (h == NULL){ 18 perror("memory allocation error"); 19 exit(exit_failure); 20 } t = h; 23 h->next = NULL; while(1){ 26 printf("input a word: "); 27 fgets(buf, MAXSIZE, stdin); 28 if (strcmp(buf, "owari\n") == 0){ 29 break; 30 } tmp = (struct LIST*) malloc(sizeof(struct LIST)); 33 if (tmp == NULL){ 34 perror("memory allocation error"); 35 exit(exit_failure); 36 } tmp->word = (char*)malloc(strlen(buf)+1); 39 if (tmp == NULL){ 40 perror("memory allocation error"); 41 exit(exit_failure); 42 } 43 strcpy(tmp->word, buf); t->next = tmp; 46 tmp->next = NULL; 47 t = tmp; 48 } for(tmp = h->next; tmp!= NULL; tmp = tmp->next){ 51 printf("%s", tmp->word); 52 } 53 } 1: tmp2 (for ) for tmp2 yytext 2 (c) 4 3 tmp2 word yytext , (77 96 ) ( ) main

3 1 %{ 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 #define MAXSIZE struct LIST { 8 struct LIST * next; 9 char *word; 10 }; int lineno=1; 13 struct LIST *h, *t, *tmp; 14 %} %% [_A-Za-z][_A-Za-z0-9]* { 51 tmp = (struct LIST*) malloc(sizeof(struct LIST)); 52 if (tmp == NULL){ 53 perror("memory allocation error"); 54 exit(exit_failure); 55 } tmp->word = (char*) malloc(strlen(yytext)+1); 58 if (tmp == NULL){ 59 perror("memory allocation error"); 60 exit(exit_failure); 61 } 62 strcpy(tmp->word, yytext); t->next = tmp; 65 tmp->next = NULL; 66 t = tmp; 67 } 68. { /* do nothing */ } 69 "\n" { lineno++; } %% 72 main(){ /* for making dummy leading node */ 75 h = (struct LIST*) malloc(sizeof(struct LIST)); 76 if (h == NULL){ 77 perror("memory allocation error"); 78 exit(exit_failure); 79 } t = h; 82 h->next = NULL; while(yylex()!=0){ 85 } for(tmp = h->next; tmp!= NULL; tmp = tmp->next){ 88 printf("%s\n", tmp->word); 89 } 90 } 2: 2(a) ( ) 4 Yacc 5 Lex if Pascal-S C Pascal-S TEHN ELSE ELSE if stmt : if_stmt... ; if_stmt : ; else_stmt : ELSE stmt /* empty */ ; IF expr THEN stmt else_stmt expr stmt 1 BEGIN END (C 3

4 if_stmt if_stmt if expr then stmt else_stmt if expr then if_stmt else st2 else_stmt if expr then st1 if expr then st1 else st2 7: if { }) ELSE ELSE ELSE if expr THEN if expr THEN st1 ELSE st2 ELSE if (??) 2 if if_stmt stmt if_stmt if expr THEN st1 stmt ELSE if if 1 ELSE if ELSE if expr THEN st1 stmt ELSE if expr THEN st1 ELSE st2 stmt ( 7) Yacc Shift Reduce Conflict ( ) ELSE ( 7 ) 2 if st1 ( 7 ) ELSE ELSE Yacc ELSE if ELSE IF 1+2*3 2*3 Yacc ( ) 4

5 50 { for(tmp2=h; 51 tmp2->next!= NULL; 52 tmp2 = tmp2->next){ 53 if (strcmp(tmp2->next->word, yytext)>0){ 54 break; 55 } 56 } tmp = (struct LIST*) malloc(sizeof(struct LIST 59 if (tmp == NULL){ 60 perror("memory allocation error"); 61 exit(exit_failure); 62 } tmp->word = (char*)malloc(strlen(yytext)+1); 65 if (tmp == NULL){ 66 perror("memory allocation error"); 67 exit(exit_failure); 68 } 69 strcpy(tmp->word, yytext); tmp->next = tmp2->next; 72 tmp2->next = tmp; 73 } 3: 2(b) ( ) 2 a = 1+2 a 3 2*a a = *3-a { 51 for(tmp2=h; 52 tmp2->next!= NULL; 53 tmp2 = tmp2->next){ 54 if (strcmp(tmp2->next->word, yytext)>0){ 55 break; 56 } 57 } if (strcmp(yytext, tmp2->word)!=0){ 60 tmp = (struct LIST*) malloc(sizeof(struct LIST)); 61 if (tmp == NULL){ 62 perror("memory allocation error"); 63 exit(exit_failure); 64 } tmp->word = (char*) malloc(strlen(yytext)+1); 67 if (tmp == NULL){ 68 perror("memory allocation error"); 69 exit(exit_failure); 70 } 71 strcpy(tmp->word, yytext); tmp->next = tmp2->next; 74 tmp2->next = tmp; 75 } 76 } 4: 2(c) ( ) Lex a = Es E E 9 Es 5

6 1 %token NUM 2 %token NL 3 %% 4 LIST : LIST E NL { printf("%d\n", $2); } 5 /* empty */ 6 ; 7 8 E : E + T { $$ = $1 + $3; } 9 E - T { $$ = $1 - $3; } 10 T { $$ = $1; } 11 ; T : T * F { $$ = $1 * $3; } 14 T / F { $$ = $1 / $3; } 15 F { $$ = $1; } 16 ; F : NUM { $$ = $1; } 19 ( E ) { $$ = $2; } 20 ; %% #include "lex.yy.c" main(){ 27 yyparse(); 28 } 5: 4 (Yacc hw2 4.y) 1 E 1 10 A 1 13 Lex 1 IDENT (3 ) Yacc Lex ( ) a=2*3 a*b 1 asignment 1 %% 2 [0-9]+ { yylval = atoi(yytext); return NUM; } 3 "+" { return + ; } 4 "*" { return * ; } 5 "-" { return - ; } 6 "/" { return / ; } 7 "(" { return ( ; } 8 ")" { return ) ; } 9 [ \t] { /* do nothing */ } 10 "\n" { return NL; } 11. { return yytext[0]; } 6: 4 (Lex hw2 4.l) a=3 b=6 26 (C ) (26 ) ( 10) Yacc Lex [a-z] { yylval = yytext[0]; return IDENT; }

7 1 %{ 2 int ident[26]; 3 %} 4 5 %token NUM 6 %token IDENT 7 %token NL 8 %% 9 LIST : LIST Es NL { printf("%d\n", $2); } 10 /* empty */ 11 ; Es : E { $$ = $1 } 14 A { /* 1 $$=$1 */ } 15 ; A : IDENT = E { 18 $$ = ident[$1 - a ] = $3; 19 } 20 ; E : E + T { $$ = $1 + $3; } 23 E - T { $$ = $1 - $3; } 24 T { $$ = $1; } 25 ; T : T * F { $$ = $1 * $3; } 28 T / F { $$ = $1 / $3; } 29 F { $$ = $1; } 30 ; F : NUM { $$ = $1; } 33 IDENT { $$ = ident[$1 - a ]; } 34 ( E ) { $$ = $2; } 35 ; %% #include "lex.yy.c" main(){ 42 int i = 0; /* the initialization of ident */ 45 for(i=0; i<26; i++){ 46 ident[i] = 0; 47 } yyparse(); 50 } 10: 26 (Yacc ex7.y) 26 int 26 ( 10 2 ) ASCII C a a ASCII ident[0] a ident[1] b ident[25] z a a - a 0 z z - a 25 ident ( ) Lex yylval 1 ASCII Yacc 33 ident 33 $1 yylval $1 - a ident $$ 17 E $3 ident E $$ 2 ex7.y ex7.l a=3 b=a*2 7

8 1 %token NUM 2 %token IDENT 3 %token NL 4 %% 5 LIST : LIST Es NL { printf("%d\n", $2); } 6 /* empty */ 7 ; 8 9 Es : E 10 A 11 ; A : IDENT = E { /* some actions */ } 14 ; E : E + T { $$ = $1 + $3; } 17 E - T { $$ = $1 - $3; } 18 T { $$ = $1; } 19 ; T : T * F { $$ = $1 * $3; } 22 T / F { $$ = $1 / $3; } 23 F { $$ = $1; } 24 ; F : NUM { $$ = $1; } 27 IDENT { /* some actions */ } 28 ( E ) { $$ = $2; } 29 ; %% #include "lex.yy.c" main(){ 36 yyparse(); 37 } 8: (ex6.y) 26 C Lex C [_a-za-z][_a-za-z0-9]* { /* action */ } 1 %% 2 [0-9]+ { yylval = atoi(yytext); return NUM; } 3 [a-z] { return IDENT; } 4 "+" { return + ; } 5 "*" { return * ; } 6 "-" { return - ; } 7 "/" { return / ; } 8 [ \t] { /* do nothing */ } 9 "\n" { return NL; } 10. { return yytext[0]; } 9: 8 Lex (ex6.l) (a) (b) 3. ( ) int (??) yylval 2(a) 2(b) 1 Yacc yylval int yylval Yacc yylval YYSTYPE int double Yacc 8

9 %{ #define YYSTYPE double... %} int char* C int 4 double 8 8 struct ST { }; int val; double dval; union UNI { }; int val; double dval; struct ST union UNI val dval int double yylval Yacc %union { } char *name; int val; C typedef union { char *name; int val; } YYSTYPE; extern YYSTYPE yylval; lex yylval yylval val yylval.val =... 3 yytext yytext yytext yylval.name =... 3 C atoi yytext atoi((char*)yytext) 9

10 0 10 ex8.y Yacc 9 ex8.l Lex stdin freopen man 4 ex8.y main 1 main(int argc, char* argv[]){ 2 extern FILE *yyin; 3 4 if (argc>1){ 5 if((yyin = freopen(argv[argc-1],"r",stdin)) == NULL){ 6 fprintf(stderr, "Can not open file %s\n", argv[argc-1]); 7 exit(1); 8 } 9 } : C Lex yyin 4 C Lex Yacc Lex lex.yy.c Yacc y.tab.c 10

11 1 %{ 2 #include <stdlib.h> 3 4 char *tname; 5 %} 6 7 %% 8 [0-9]+ { yylval.val = atoi((char*)yytext); 9 return NUM; } 10 [_a-za-z][_a-za-z0-9]* { tname = (char*)malloc(strlen(yytext)+1); } 11 if (tname==null){ 12 perror("memory allocation"); 13 exit(exit_failure); 14 } 15 strcpy(tname, yytext); 16 yylval.name = tname; return IDENT; } 17 "+" { return + ; } 18 "*" { return * ; } 19 "-" { return - ; } 20 "/" { return / ; } 21 [ \t] { /* do nothing */ } 22 "\n" { return NL; } 23. { return yytext[0]; } 11: 12 Lex #include 1 12 Yacc 2 %% main 3 main.c #include %token Yacc -d y.tab.h 1. hoge.l 1 %{ #include "y.tab.h"... %} 2. yacc -d hoge.y 3. lex hoge.l 4. cc -c y.tab.c (y.tab.o ) 5. cc -c lex.yy.c (lex.yy.o ) 6. cc main.c y.tab.o lex.yy.o -ly -ll make make Makefile :( ) 14 Yacc Lex Makefile clean make clean 14 make hoge.l hoge.y a.out 11

12 1 %union { 2 char *name; 3 int val; 4 } 5 6 %{ 7 #include <stdio.h> 8 #include <stdlib.h> 9 10 struct VALS { 11 int val; 12 char *name; 13 struct VALS *next; 14 }; struct VALS *h, *t; int getval(char*); 19 int setval(char*, int); 20 %} %token <val> NUM 23 %token <name> IDENT 24 %token NL %type <val> Es 27 %type <val> A 28 %type <val> E 29 %type <val> T 30 %type <val> F %% 33 LIST : LIST Es NL { printf("%d\n", $2); } 34 /* empty */ 35 ; Es : E { $$ = $1; } 38 A { $$ = $1; } 39 ; A : IDENT = E { 42 $$ = setval($1, $3); 43 } 44 ; E : E + T { $$ = $1 + $3; } 47 E - T { $$ = $1 - $3; } 48 T { $$ = $1; } 49 ; T : T * F { $$ = $1 * $3; } 52 T / F { $$ = $1 / $3; } 53 F { $$ = $1; } 54 ; F : NUM { $$ = $1; } 57 IDENT { $$ = getval($1); } 58 ( E ) { $$ = $2; } 59 ; 60 %% #include "lex.yy.c" main(){ 65 int i = 0; 66 struct VALS *tmp; h = t = (struct VALS*) malloc(sizeof(struct VALS)); 69 if (h==null){ 70 perror("memory allocation"); 71 exit(exit_failure); 72 } h->next = NULL; yyparse(); 77 } int getval(char* name){ 80 struct VALS *tmp; for(tmp=h->next; tmp!= NULL; tmp = tmp->next){ 83 if (strcmp(tmp->name, name)==0){ 84 return tmp->val; 85 } 86 } return 0; 89 } int setval(char* name, int val){ 92 struct VALS *tmp; for(tmp=h->next; tmp!= NULL; tmp = tmp->next){ 95 if (strcmp(tmp->name, name)==0){ 96 break; 97 } 98 } if(tmp == NULL){ 01 tmp = (struct VALS*) malloc(sizeof(struct VALS)); 02 if (tmp == NULL){ 03 perror("memory allocation"); 04 exit(exit_failure); 05 } 06 tmp->name = name; 07 tmp->val = val; t->next = tmp; 10 tmp->next = NULL; 11 t = tmp; 12 } 13 else { 14 tmp->val = val; 15 } return val; 18 } 12: Yacc (ex8.y) 12

13 CC a.out = cc : lex.yy.o y.tab.o main.o $(CC) lex.yy.o y.tab.o main.o -ly -ll lex.yy.o : lex.yy.c $(CC) -c lex.yy.c y.tab.o : y.tab.c $(CC) -c y.tab.c lex.yy.c : hoge.l lex hoge.l y.tab.c : hoge.y yacc hoge.y 5 (tree) 5.1 C 1 main.o : main.c $(CC) -c main.c clean : rm -rf *~ *.o y.tab.c lex.yy.c 5 14: Makefile ex8.y ex8.l make hoge ex8 Makefile 2. ex8.l 2 #include "y.tab.h" 3. ex8.y 2 %% #include "lex.yy.c" main.c (ex8.y ) 4. ex8.y %{ %} main.c (ex8.y ) 5. make clean make lex yacc a.out ex8.l 4 make 4 touch 15 E E T + T T * F F F * : 1+2*3 ( ) ( ) 13

14 (traverse) C 2 (subexpression) C struct NODE { int opcode; /* the number of operator */ int val; struct NODE *left_child, *right_child; }; opcode 1 0 val left_child right_child 1 makenode struct NODE* makenode (struct NODE *l, struct NODE *r, int no, int val); ( ) 5.2 Yacc Yacc LIST : E NL ; yylval Yacc 1 yylval 14

15 %union 5 18 $$ 8, 9, 13, 14 ($1 $3 ) 1 Yacc struct NODE *root; root = $2; E () ( 16) 1 void traverse(struct NODE *n){ 2 if (n->lc!= NULL){ 3 traverse(n->lc); 4 } 5 if (n->rc!= NULL){ 6 traverse(n->rc); 7 } 8 if (n->nodecode == 0){ 9 printf(" %d ", n->val); 10 } 11 else { 12 printf(" %c ", n->nodecode); 13 } 14 } 6 ( ) 1 Ctrl-d () 1. ~nakai/ipp2/post 2. ~nakai/ipp2/pre 3. C C 1) int 2) int a; 1 1 3) 4) 5) C 6) 16: 15

16 1 %{ 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 #define MAXSIZE struct LNUM { 8 int lineno; 9 struct LNUM *next; 10 }; struct LIST { 13 struct LIST * next; 14 char *word; struct LNUM *h; 17 struct LNUM *t; 18 }; int lineno=1; 21 struct LIST *h, *t, *tmp, *tmp2; 22 struct LNUM *tmp3; 23 %} %% 59 [_A-Za-z][_A-Za-z0-9]* { 60 for(tmp2=h; 61 tmp2->next!= NULL; 62 tmp2 = tmp2->next){ 63 if (strcmp(tmp2->next->word, yytext)>0){ 64 break; 65 } 66 } tmp3 = (struct LNUM*) malloc(sizeof(struct LNUM)); 69 if (tmp3 == NULL){ 70 perror("memory allocation error"); 71 exit(exit_failure); 72 } tmp3->lineno = lineno; 75 tmp3->next = NULL; if (strcmp(yytext, tmp2->word)!=0){ 78 tmp = (struct LIST*) malloc(sizeof(struct LIST)); 79 if (tmp == NULL){ 80 perror("memory allocation error"); 81 exit(exit_failure); 82 } tmp->word = (char*) malloc(strlen(yytext)+1); 85 if (tmp == NULL){ 86 perror("memory allocation error"); 87 exit(exit_failure); 88 } 89 strcpy(tmp->word, yytext); tmp->h = tmp3; 92 tmp->t = tmp3; tmp->next = tmp2->next; 95 tmp2->next = tmp; 96 } 97 else { 98 tmp2->t->next = tmp3; 99 tmp2->t = tmp3; 100 } 101 } 102. { /* do nothing */ } 103 "\n" { lineno++; } %% main(){ /* for making dummy leading node */ 110 h = (struct LIST*) malloc(sizeof(struct LIST)); 111 if (h == NULL){ 112 perror("memory allocation error"); 113 exit(exit_failure); 114 } t = h; 117 h->next = NULL; 118 h->word == ""; while(yylex()!=0){ 121 } for(tmp = h->next; tmp!= NULL; tmp = tmp->next){ 124 printf("%s : ", tmp->word); 125 for(tmp3 = tmp->h; tmp3!= NULL; tmp3 = tmp3->next){ 126 printf("%5d", tmp3->lineno); 127 } 128 printf("\n"); 129 } 130 } 17: 3 16

untitled

untitled II 4 Yacc Lex 2005 : 0 1 Yacc 20 Lex 1 20 traverse 1 %% 2 [0-9]+ { yylval.val = atoi((char*)yytext); return NUM; 3 "+" { return + ; 4 "*" { return * ; 5 "-" { return - ; 6 "/" { return / ; 7 [ \t] { /*

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

(ver. 1.3 (2018) ) yacc 1 1 yacc yacc (Yet Another Compiler Compiler) UNIX yacc yacc y *.y yacc ) yacc *.tab.h *.tab.c C C yacc yacc UNIX yacc bison 2

(ver. 1.3 (2018) ) yacc 1 1 yacc yacc (Yet Another Compiler Compiler) UNIX yacc yacc y *.y yacc ) yacc *.tab.h *.tab.c C C yacc yacc UNIX yacc bison 2 (ver. 1.3 (2018) ) yacc 1 1 yacc yacc (Yet Another Compiler Compiler) UNIX yacc yacc y *.y yacc ) yacc *.tab.h *.tab.c C C yacc yacc UNIX yacc bison 2 yacc yacc lex %token yacc yacc token *.tab.h #define

More information

1.

1. 3 ( ) 1. n Tiny C n yacc (bison) lex (flex) n IA n n n n n n (lex ) 50 (yacc ) 400 200 550 n n yacc/lex TA Tiny C n C n int n (if, while) int fact(int n) {! if (n == 1) return 1;! else return n * fact(n-1);!

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2018 2018 08 02 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF N N y N x N xy yx : yxxyxy N N x, y N (parse tree) (1) yxyyx (2) xyxyxy (3) yxxyxyy (4) yxxxyxxy N y N x N yx

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2017 2017 08 03 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF X [ S ] a S S ; X X X, S [, a, ], ; BNF X (parse tree) (1) [a;a] (2) [[a]] (3) [a;[a]] (4) [[a];a] : [a] X 2 222222

More information

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* ( 2016 2016 07 28 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF : 11011 N N 0 N N 11 1001 N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) 1100100 (2) 1111011 (3) 1110010 (4) 1001011

More information

yacc.dvi

yacc.dvi 2017 c 8 Yacc Mini-C C/C++, yacc, Mini-C, run,, Mini-C 81 Yacc Yacc, 1, 2 ( ), while ::= "while" "(" ")" while yacc 1: st while : lex KW WHILE lex LPAREN expression lex RPAREN statement 2: 3: $$ = new

More information

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * * 2015 2015 07 30 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) +

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

() () (parse tree) ( (( ) * 50) ) ( ( NUM 10 + NUM 30 ) * NUM 50 ) ( * ) ( + ) NUM 50 NUM NUM (abstract syntax tree, AST) ( (( ) * 5

() () (parse tree) ( (( ) * 50) ) ( ( NUM 10 + NUM 30 ) * NUM 50 ) ( * ) ( + ) NUM 50 NUM NUM (abstract syntax tree, AST) ( (( ) * 5 3 lex yacc http://www.cs.info.mie-u.ac.jp/~toshi/lectures/compiler/ 2018 6 1 () () (parse tree) ( ((10 + 30) * 50) ) ( ( NUM 10 + NUM 30 ) * NUM 50 ) ( * ) ( + ) NUM 50 NUM NUM 10 30 (abstract syntax tree,

More information

( ) ( ) lex LL(1) LL(1)

( ) ( ) lex LL(1) LL(1) () () lex LL(1) LL(1) http://www.cs.info.mie-u.ac.jp/~toshi/lectures/compiler/ 29 5 14 1 1 () / (front end) (back end) (phase) (pass) 1 2 1 () () var left, right; fun int main() { left = 0; right = 10;

More information

parser.y 3. node.rb 4. CD-ROM

parser.y 3. node.rb 4. CD-ROM 1. 1 51 2. parser.y 3. node.rb 4. CD-ROM 1 10 2 i 0 i 10 " i i+1 3 for(i = 0; i

More information

() / (front end) (back end) (phase) (pass) 1 2

() / (front end) (back end) (phase) (pass) 1 2 1 () () lex http://www.cs.info.mie-u.ac.jp/~toshi/lectures/compiler/ 2018 4 1 () / (front end) (back end) (phase) (pass) 1 2 () () var left, right; fun int main() { left = 0; right = 10; return ((left

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

橡Pro PDF

橡Pro PDF 1 void main( ) char c; /* int c; */ int sum=0; while ((c = getchar())!= EOF) if(isdigit(c) ) sum += (c-'0'); printf("%d\n", sum); main()int i,sum=0; for(i=0;i

More information

新・明解C言語 ポインタ完全攻略

新・明解C言語 ポインタ完全攻略 2 1-1 1-1 /* 1-1 */ 1 int n = 100; int *p = &n; printf(" n %d\n", n); /* n int */ printf("*&n %d\n", *&n); /* *&n int */ printf(" p %p\n", p); /* p int * */ printf("&*p %p\n", &*p); /* &*p int * */ printf("sizeof(n)

More information

Taro-リストⅢ(公開版).jtd

Taro-リストⅢ(公開版).jtd リスト Ⅲ 0. 目次 2. 基本的な操作 2. 1 リストから要素の削除 2. 2 リストの複写 2. 3 リストの連結 2. 4 問題 問題 1 問題 2-1 - 2. 基本的な操作 2. 1 リストから要素の削除 まず 一般的な処理を書き つぎに 特別な処理を書く 一般的な処理は 処理 1 : リスト中に 削除するデータを見つけ 削除する場合への対応 特別な処理は 処理 2 : 先頭のデータを削除する場合への対応

More information

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D II 8 2003 11 12 1 6 ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 Daisuke 8 =>. 73 Daisuke 35 Hiroshi 64 Ichiro 87 Junko

More information

Taro-リストⅠ(公開版).jtd

Taro-リストⅠ(公開版).jtd 0. 目次 1. 再帰的なデータ構造によるリストの表現 1. 1 リストの作成と表示 1. 1. 1 リストの先頭に追加する方法 1. 1. 2 リストの末尾に追加する方法 1. 1. 3 昇順を保存してリストに追加する方法 1. 2 問題 問題 1 問題 2-1 - 1. 再帰的なデータ構造によるリストの表現 リストは データの一部に次のデータの記憶場所を示す情報 ( ポインタという ) を持つ構造をいう

More information

ex14.dvi

ex14.dvi 1,, 0, b (b b 2 b ) n k n = n j b j, (0 n j b 1), n =(n k n k 1...n 1 n 0 ) b, n j j j +1, 0,...,b 1 (digit). b b, n b 1 ñ, ñ = k (b 1 n j )b j b N, n b n, n = b N n, n =ñ+1 b N, n m n + m (mod b N ),

More information

file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

filea fileb fp = fopen(a, r); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen(b, r); while(fgets(line, BUFSIZ, fp)) {... fclose I117 9 2 School of Information Science, Japan Advanced Institute of Science and Technology file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line,

More information

情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤

情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤 情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤 2017.12.7 前回の演習問題の解答例 1. 四則演算のできる計算機のプログラム ( 括弧も使える ) 2. 実数の扱える四則演算の計算機のプログラム ( 実数 も というより実数 が が正しかったです ) 3. 変数も扱える四則演算の計算機のプログラム ( 変数と実数が扱える ) 演習問題 1 で行うべきこと

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

文法と言語 ー文脈自由文法とLR構文解析2ー

文法と言語 ー文脈自由文法とLR構文解析2ー 文法と言語ー文脈自由文法とLR 構文解析 2 ー 和田俊和資料保存場所 http://vrl.sys.wakayama-u.ac.jp/~twada/syspro/ 前回までの復習 最右導出と上昇型構文解析 最右導出を前提とした場合, 上昇型の構文解析がしばしば用いられる. 上昇型構文解析では生成規則の右辺にマッチする部分を見つけ, それを左辺の非終端記号に置き換える 還元 (reduction)

More information

18/12/06 情報工学実験 C コンパイラ (2018 年度 ) 担当 : 笹倉 佐藤 その 3 yacc の構造 定義部 %% 定義部の終了 規則部 %% 規則部の終了 ユーザ定義サブルーチン部 :C のプログラムを書く 形は lex と同じ 1

18/12/06 情報工学実験 C コンパイラ (2018 年度 ) 担当 : 笹倉 佐藤 その 3 yacc の構造 定義部 %% 定義部の終了 規則部 %% 規則部の終了 ユーザ定義サブルーチン部 :C のプログラムを書く 形は lex と同じ 1 情報工学実験 C コンパイラ (2018 年度 ) 担当 : 笹倉 佐藤 2018.12.6 その 3 yacc の構造 定義部 定義部の終了 規則部 規則部の終了 ユーザ定義サブルーチン部 :C のプログラムを書く 形は lex と同じ 1 yacc yacc のキモは規則部 規則部には文法規則を書く左辺 : 右辺 yacc は入力されたプログラムを右辺から左辺に 還元 していく この規則にアクションが書かれていたら還元するときにアクションも実行する.

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

lexex.dvi

lexex.dvi (2018, c ) http://istksckwanseiacjp/ ishiura/cpl/ 4 41 1 mini-c lexc,, 2 testlexc, lexc mini-c 1 ( ) mini-c ( ) (int, char, if, else, while, return 6 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,

More information

変数を使えるようにする arithr.y を拡張して変数を使えるようにする 変数はアルファベット小文字一文字だけからなるものとする 変数の数はたかだか 26 なので,26 個の要素をもつ配列 vbltable に格納する 一行だけで計算が終わるのではなく数式を連続で計算できるようにし,$ が入力され

変数を使えるようにする arithr.y を拡張して変数を使えるようにする 変数はアルファベット小文字一文字だけからなるものとする 変数の数はたかだか 26 なので,26 個の要素をもつ配列 vbltable に格納する 一行だけで計算が終わるのではなく数式を連続で計算できるようにし,$ が入力され 情報工学実験 C コンパイラ第 2 回説明資料 (2016 年度 ) 担当 : 笹倉 佐藤 変数を使えるようにする arithr.y を拡張して変数を使えるようにする 変数はアルファベット小文字一文字だけからなるものとする 変数の数はたかだか 26 なので,26 個の要素をもつ配列 vbltable に格納する 一行だけで計算が終わるのではなく数式を連続で計算できるようにし,$ が入力されたら終了するようにする

More information

comment.dvi

comment.dvi ( ) (sample1.c) (sample1.c) 2 2 Nearest Neighbor 1 (2D-class1.dat) 2 (2D-class2.dat) (2D-test.dat) 3 Nearest Neighbor Nearest Neighbor ( 1) 2 1: NN 1 (sample1.c) /* -----------------------------------------------------------------

More information

gcc C C tcc lex yacc flex bison [ ] Tiny C 2 Lex [ 2.6 ] 2.1 lex yacc [ ] lex flex yacc bison yacc yyparse() C yyparse() yylex() yylex() yylex() flex

gcc C C tcc lex yacc flex bison [ ] Tiny C 2 Lex [ 2.6 ] 2.1 lex yacc [ ] lex flex yacc bison yacc yyparse() C yyparse() yylex() yylex() yylex() flex 3 1 C Tiny C Tiny C int if while Tiny C 4 C Tiny C % cat test.tc int f(int x) while(x > 1) x = x - 2; return x; Tiny C NASM [3] tcc C % tcc < test.tc GLOBAL f f push ebp mov ebp, esp L1 mov eax, [ebp+8]

More information

I void* School of Information Science, Japan Advanced Institute of Science and Technology

I void* School of Information Science, Japan Advanced Institute of Science and Technology I117 25 void* School of Information Science, Japan Advanced Institute of Science and Technology sdict ( ) idict ; long long double void* Japan Advanced Institute of Science and Technology 2008 1-2 1 idict

More information

main

main 14 1. 12 5 main 1.23 3 1.230000 3 1.860867 1 2. 1988 1925 1911 1867 void JPcalendar(int x) 1987 1 64 1 1 1 while(1) Ctrl C void JPcalendar(int x){ if (x > 1988) printf(" %d %d \n", x, x-1988); else if(x

More information

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf(hello World\n); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o 18 C ( ) 1 1 1.1 hello world.c 5 printf("hello World\n"); 6 } [ ] [ ] #include % cc hello_world.c %./a.out Hello World [a.out ] % cc hello_world.c -o hello_world [ ( ) ] (K&R 4.1.1) #include

More information

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D 6 2019 5 14 6.1 Minimum C....................... 6 1 6.2....................................... 6 7 6.1 Minimum C Minimum C BNF T okenseq W hite Any Digit ::= 0 1 2... 9. Number ::= Digit Digit. Alphabet

More information

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1 () 2006 2 27 1 10 23 () 30 () 27 [1] p.97252 7 2 2.1 2.1.1 1 LIFO(last in first out, ) (push) (pup) 1 1: 2.1.2 1 List 4-1(p.100) stack[] stack top 1 2 (push) (pop) 1 2 void stack push(double val) val stack

More information

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

tuat1.dvi

tuat1.dvi ( 1 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 6 23 ( 1 ) 1 / 58 C ( 1 ) 2 / 58 2008 9 2002 2005 T E X ptetex3, ptexlive pt E X UTF-8 xdvi-jp 3 ( 1 ) 3 / 58 ( 1 ) 4 / 58 C,... ( 1 ) 5 / 58 6/23( )

More information

program.dvi

program.dvi 2001.06.19 1 programming semi ver.1.0 2001.06.19 1 GA SA 2 A 2.1 valuename = value value name = valuename # ; Fig. 1 #-----GA parameter popsize = 200 mutation rate = 0.01 crossover rate = 1.0 generation

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

XMPによる並列化実装2

XMPによる並列化実装2 2 3 C Fortran Exercise 1 Exercise 2 Serial init.c init.f90 XMP xmp_init.c xmp_init.f90 Serial laplace.c laplace.f90 XMP xmp_laplace.c xmp_laplace.f90 #include int a[10]; program init integer

More information

Microsoft Word - C.....u.K...doc

Microsoft Word - C.....u.K...doc C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ

More information

Microsoft Word - Cプログラミング演習(12)

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information

ex12.dvi

ex12.dvi 1 0. C, char., char, 0,. C, ("),., char str[]="abc" ; str abc.,, str 4. str 3. char str[10]="abc" ;, str 10, str 3., char s[]="abc", t[10] ;, t = s. ASCII, 0x00 0x7F, char., "abc" 3, 1. 1 8 256, 2., 2

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó  ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡ (2018) 2018 5 24 ( ) while ( ) do while ( ); for ( ; ; ) while int i = 0; while (i < 100) { printf("i = %3d\n", i); i++; while int i = 0; i while (i < 100) { printf("i = %3d\n", i); i++; while int i =

More information

untitled

untitled C -1 - -2 - concept lecture keywords FILE, fopen, fclose, fscanf, fprintf, EOF, r w a, typedef gifts.dat Yt JZK-3 Jizake tsumeawase 45 BSP-15 Body soap set 3 BT-2 Bath towel set 25 TEA-2 Koutya

More information

memo

memo 数理情報工学演習第一 C プログラミング演習 ( 第 5 回 ) 2015/05/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 課題 : 疎行列 2 プロトタイプ宣言 3 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology I117 8 1 School of Information Science, Japan Advanced Institute of Science and Technology : CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and

More information

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B A/B (2018/10/19) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2018 10 19 A/B 1 2018 10 19 2 1 1 1.1 OHP.................................... 1

More information

情報工学実験 C コンパイラ第 2 回説明資料 (2018 年度 ) 担当 : 笹倉 佐藤

情報工学実験 C コンパイラ第 2 回説明資料 (2018 年度 ) 担当 : 笹倉 佐藤 情報工学実験 C コンパイラ第 2 回説明資料 (2018 年度 ) 担当 : 笹倉 佐藤 2018.12.13 コンパイラ作成実験 非常に難しい. まず コンパイラを実装すること自体が難しい. コンパイラを指して 人工知能 と呼んだ時代もあった. 難しさは 抽象的なアイデアを元に具体的な実装を行うことにある. クヌースはこれを 計算機科学的な考え方 と呼び できる人の存在比率は 1/50 だと述べている.

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧) CM-3G 周辺モジュール拡張技術文書 MS5607 センサ ( 温度 気圧 ) ( 第 1 版 ) Copyright (C)2016 株式会社コンピューテックス 目次 1. はじめに... 1 2. MS5607 について... 1 3. 接続図... 1 4. アプリケーション ソース... 2 5. アプリケーションのコンパイル方法... 7 6. アプリケーションの実行... 8 1. はじめに

More information

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >= II 14 2018 7 26 : : proen@mm.ics.saitama-u.ac.jp 14,, 8 2 12:00 1 O(1) n O(n) O(log n) O(1) 32 : 1G int 4 250 M 2.5 int 21 2 0 100 0 100 #include #define HASHSIZE 100 /* */ #define NOTFOUND 0

More information

Taro-2分探索木Ⅱ(公開版).jtd

Taro-2分探索木Ⅱ(公開版).jtd 2 分探索木 Ⅱ 0. 目次 5. 2 分探索木の操作 5. 1 要素の探索 5. 2 直前の要素の探索 5. 3 直後の要素の探索 5. 4 要素の削除 5. 5 問題 問題 1-1 - 5. 2 分探索木の操作 5. 1 要素の探索 要素 44 の探索 (1) 要素 と 44 を比較して 左部分木をたどる (2) 要素 33 と 44 を比較して 右部分木をたどる (3) 要素 44 を見つけた

More information

1.ppt

1.ppt /* * Program name: hello.c */ #include int main() { printf( hello, world\n ); return 0; /* * Program name: Hello.java */ import java.io.*; class Hello { public static void main(string[] arg)

More information

O(N) ( ) log 2 N

O(N) ( ) log 2 N 2005 11 21 1 1.1 2 O(N) () log 2 N 1.2 2 1 List 3-1 List 3-3 List 3-4? 3 3.1 3.1.1 List 2-1(p.70) 1 1 10 1 3.1.2 List 3-1(p.70-71) 1 1 2 1 2 2 1: 1 3 3.1.3 1 List 3-1(p.70-71) 2 #include stdlib.h

More information

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1 I117 II I117 PROGRAMMING PRACTICE II 2 MEMORY MANAGEMENT 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp / SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming

More information

Condition DAQ condition condition 2 3 XML key value

Condition DAQ condition condition 2 3 XML key value Condition DAQ condition 2009 6 10 2009 7 2 2009 7 3 2010 8 3 1 2 2 condition 2 3 XML key value 3 4 4 4.1............................. 5 4.2...................... 5 5 6 6 Makefile 7 7 9 7.1 Condition.h.............................

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó  ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡ (2018) 2018 5 17 0 0 if switch if if ( ) if ( 0) if ( ) if ( 0) if ( ) (0) if ( 0) if ( ) (0) ( ) ; if else if ( ) 1 else 2 if else ( 0) 1 if ( ) 1 else 2 if else ( 0) 1 if ( ) 1 else 2 (0) 2 if else

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング応用演習 第 5 回演習 前回までのお話 ポインタ ポインタを用いた文字列処理 構造体 ファイル 再帰的構造体 リスト構造 動的メモリ管理 今日のお題 ポインタやファイルなど これまでの内容の練習 教材 以前 以下に単語を収録したファイルがあることを紹介した : /usr/share/dict/words この中からランダムに単語を取り出したファイルを用意した http://sun.ac.jp/prof/yamagu/2019app/

More information

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2  2 B R b I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

More information

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v 1 http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html kota@fbs.osaka-u.ac.jp /* do-while */ #include #include int main(void) double val1, val2, arith_mean, geo_mean; printf( \n );

More information

Taro-スタック(公開版).jtd

Taro-スタック(公開版).jtd 0. 目次 1. 1. 1 配列によるの実現 1. 2 再帰的なデータ構造によるの実現 1. 3 地図情報処理 1. 4 問題 問題 1 グラフ探索問題 - 1 - 1. は データの出し入れが一カ所で行われ 操作は追加と削除ができるデータ構造をいう 出入口 追加 削除 操作 最初 111 追加 111 222 追加 111 222 333 追加 111 222 333 444 追加 111 222

More information

スライド タイトルなし

スライド タイトルなし ファイル入出力 (2) これまでのおさらい ( 入出力 ) これまでの入出力は 入力 scanf 出力 printf キーボードと画面 ( 端末 ) scanf/printf は 書式つき入出力 フォーマットを指定する 標準入出力を対象とする 何もしなければ 標準入出力は キーボードと画面 ストリームという考え方 ストリーム (stream) = データの列 キーボードから打つ文字列 画面に出力される文字列

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

分割コンパイル (2018 年度 ) 担当 : 笹倉 佐藤 分割コンパイルとは 一つのプログラムのソースを複数のソースファイルに分けてコンパイルすること ある程度大きなプログラムの場合ソースファイルをいくつかに分割して開発するのが普通 1

分割コンパイル (2018 年度 ) 担当 : 笹倉 佐藤 分割コンパイルとは 一つのプログラムのソースを複数のソースファイルに分けてコンパイルすること ある程度大きなプログラムの場合ソースファイルをいくつかに分割して開発するのが普通 1 分割コンパイル (2018 年度 ) 担当 : 笹倉 佐藤 2018.12.20 分割コンパイルとは 一つのプログラムのソースを複数のソースファイルに分けてコンパイルすること ある程度大きなプログラムの場合ソースファイルをいくつかに分割して開発するのが普通 1 なぜ分割コンパイルするのか 1. コンパイル時間を短縮するため 2. ソースコードを見やすくするため 3. ソースコードを再利用しやすくするため

More information

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() 2 double *a[ ]; double 1 malloc() double 1 malloc() free() 3 #include #include

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru 43 6 MPI MPI(Message Passing Interface) MPI 1CPU/1 PC Cluster MPICH[5] 6.1 MPI MPI MPI 1 : #include 2 : #include 3 : #include 4 : 5 : #include "mpi.h" 7 : int main(int argc,

More information

超初心者用

超初心者用 3 1999 10 13 1. 2. hello.c printf( Hello, world! n ); cc hello.c a.out./a.out Hello, world printf( Hello, world! n ); 2 Hello, world printf n printf 3. ( ) int num; num = 100; num 100 100 num int num num

More information

第5回お試しアカウント付き並列プログラミング講習会

第5回お試しアカウント付き並列プログラミング講習会 qstat -l ID (qstat -f) qscript ID BATCH REQUEST: 253443.batch1 Name: test.sh Owner: uid=32637, gid=30123 Priority: 63 State: 1(RUNNING) Created at: Tue Jun 30 05:36:24 2009 Started at: Tue Jun 30 05:36:27

More information

プログラミング及び演習 第1回 講義概容・実行制御

プログラミング及び演習 第1回 講義概容・実行制御 プログラミング及び演習 第 12 回大規模プログラミング (2015/07/11) 講義担当情報連携統轄本部情報戦略室大学院情報科学研究科メディア科学専攻教授森健策 本日の講義 演習の内容 大きなプログラムを作る 教科書第 12 章 make の解説 プログラミングプロジェクト どんどんと進めてください 講義 演習ホームページ http://www.newves.org/~mori/15programming

More information

I J

I J I 065763J 8 7 7 31 jikken/ +----- accumulation_demupa.c +----- accumulation_rain.c +----- frequency_demupa.c +----- frequency_rain.c +----- go.sh +----- graph_maker.sh +----- mesure-ryudai/ 2007/4/1 2007/6/30

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

I httpd School of Information Science, Japan Advanced Institute of Science and Technology

I httpd School of Information Science, Japan Advanced Institute of Science and Technology I117 17 4 httpd School of Information Science, Japan Advanced Institute of Science and Technology httpd HTTP httpd log file access log access.log CERN httpd common format lighttpd common format 2 1000

More information

file:///D|/C言語の擬似クラス.txt

file:///D|/C言語の擬似クラス.txt 愛知障害者職業能力開発校 システム設計科 修了研究発表会報告書 題名 : C 言語の擬似クラス あらまし : C 言語でクラスを作れるという噂の真偽を確かめるために思考錯誤した まえがき : VC++ や Java その他オブジェクト指向の言語にはクラスが存在して クラスはオブジェクトの設計図である 手法 : C++ のクラスを解析して C++ のクラスを作成して C 言語に翻訳する class struct

More information

Microsoft Word - no206.docx

Microsoft Word - no206.docx 3.2 双方向リスト 今までのリストは 前から順にたどることしかできませんでした 今度は逆にもたどることができる 双方向リストを扱います この場合は 構造体には次を表すポインタの他に前を表すポインタを持つ ことになります 今回は最初と最後をポインタを使うと取り扱いが面倒になるので 最初 (start) と最後 (end) を どちらとも構造体 ( 値は意味を持たない ) を使うことにします こうすることによって

More information

Taro-2分探索木Ⅰ(公開版).jtd

Taro-2分探索木Ⅰ(公開版).jtd 2 分探索木 Ⅰ 0. 目次 1. 2 分探索木とは 2. 2 分探索木の作成 3. 2 分探索木の走査 3. 1 前走査 3. 2 中走査 3. 3 問題 問題 1 問題 2 後走査 4. 2 分探索木の表示 - 1 - 1. 2 分探索木とは 木はいくつかの節点と節点同士を結ぶ辺から構成される 2 つの節点 u,v が直接辺で結ばれているとき 一方を親節点 他方を子節点という ある節点の親節点は高々

More information

卒 業 研 究 報 告.PDF

卒 業 研 究 報 告.PDF C 13 2 9 1 1-1. 1-2. 2 2-1. 2-2. 2-3. 2-4. 3 3-1. 3-2. 3-3. 3-4. 3-5. 3-5-1. 3-5-2. 3-6. 3-6-1. 3-6-2. 4 5 6 7-1 - 1 1 1-1. 1-2. ++ Lisp Pascal Java Purl HTML Windows - 2-2 2 2-1. 1972 D.M. (Dennis M Ritchie)

More information

slide5.pptx

slide5.pptx ソフトウェア工学入門 第 5 回コマンド作成 1 head コマンド作成 1 早速ですが 次のプログラムを head.c という名前で作成してください #include #include static void do_head(file *f, long nlines); int main(int argc, char *argv[]) { if (argc!=

More information

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology I117 7 School of Information Science, Japan Advanced Institute of Science and Technology time time t long typedef long time_t; 1970/01/01 0:00:00 time t = time(null); Japan Advanced Institute of Science

More information

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() malloc 2 #include #include #include enum LENGTH = 10 ; int

More information

Prog1_15th

Prog1_15th 2012 年 7 月 26 日 ( 木 ) 実施構造体と typedef typedef 宣言によって,struct 構造体タグ名という表記を再定義し, データ型名のように扱うことができる 構文は typedef struct 構造体タグ名 再定義名 ; となり, この場合の構造体変数の宣言は, 再定義名を用いて行うことができる なお, ここでは 構造体タグ名は省略可能である 構造体を指すポインタ

More information

memo

memo 数理情報工学演習第一 C ( 第 8 回 ) 206/06/3 DEPARTMENT OF MATHEMATICAL INFORMATICS 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 プライオリティキュー ヒープ 課題 : ヒープソート 2 プロトタイプ宣言 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

1 4 2 EP) (EP) (EP)

1 4 2 EP) (EP) (EP) 2003 2004 2 27 1 1 4 2 EP) 5 3 6 3.1.............................. 6 3.2.............................. 6 3.3 (EP)............... 7 4 8 4.1 (EP).................... 8 4.1.1.................... 18 5 (EP)

More information

C

C C 1 2 1.1........................... 2 1.2........................ 2 1.3 make................................................ 3 1.4....................................... 5 1.4.1 strip................................................

More information

Microsoft Word - Cプログラミング演習(10)

Microsoft Word - Cプログラミング演習(10) 第 10 回 (6/25) 3. ファイルとその応用 (3) ファイルの更新 シーケンシャルファイルの更新 シーケンシャルファイルでは, 各レコードが可変長で連続して格納されており, その中の特定のレコードを変更することができない そこで一般的には, マスタファイルからデータを取り出し, 更新処理を行ったあとに新マスタファイルに書き込む 注 ) マスタファイル : 主ファイル, 基本ファイルと呼ばれるファイルで内容は比較的固定的であり,

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) { double

More information

C B

C B C 095707B 2010 6 8 1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2..............................................

More information

P06.ppt

P06.ppt p.130 p.198 p.208 2 1 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i < NUM; i++ ) if ( weight[i] > max ) max = weight[i]: if ( weight[i] < min ) min = weight[i]: weight 3 maxof(a,

More information

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1 2008 ( 13 ) C LAPACK LAPACK p. 1 Q & A Euler http://phase.hpcc.jp/phase/mppack/long.pdf KNOPPIX MT (Mersenne Twister) SFMT., ( ) ( ) ( ) ( ). LAPACK p. 2 C C, main Asir ( Asir ) ( ) (,,...), LAPACK p.

More information

BW BW

BW BW Induced Sorting BW 11T2042B 2015 3 23 1 1 1.1................................ 1 1.2................................... 1 2 BW 1 2.1..................................... 2 2.2 BW.................................

More information

プログラミング及び演習 第1回 講義概容・実行制御

プログラミング及び演習 第1回 講義概容・実行制御 プログラミング及び演習 第 9 回列挙型 構造体 ( 教科書第 11 章 ) (2014/06/14) 講義担当 情報連携統括本部情報戦略室 森健策 本日の講義 演習の内容 列挙型 / 構造体 第 11 章 講義 演習ホームページ http://www.newves.org/~mori/14programming ところで,. だんだん難しくなってきました ポインタは2 回目で理解できましたか? 列挙型

More information

DA100データアクイジションユニット通信インタフェースユーザーズマニュアル

DA100データアクイジションユニット通信インタフェースユーザーズマニュアル Instruction Manual Disk No. RE01 6th Edition: November 1999 (YK) All Rights Reserved, Copyright 1996 Yokogawa Electric Corporation 801234567 9 ABCDEF 1 2 3 4 1 2 3 4 1 2 3 4 1 2

More information