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

Size: px
Start display at page:

Download "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"

Transcription

1 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] cmp eax, 1 setg al movzx eax, al cmp eax, 0 je L2 mov eax, [ebp+8] sub eax, 2 mov [ebp+8], eax jmp L1 L2 mov eax, [ebp+8] mov esp, ebp pop ebp ret 1

2 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 *1 2.2 lex calc.l %option noyywrap % int yylval; % digit [0-9] %% digit+ yylval = atoi(yytext); printf("int = %d\n", yylval); "+" "*" printf("opr = %s\n", yytext); [ \t\n] ; /* */. ; %% main() *1 yacc C yylex() 2

3 yylex(); lex flex yylex() lex.yy.c % flex calc.l % gcc -o calc lex.yy.c % cat sample 1* %./calc < sample INT = 1 OPR = * INT = 23 OPR = + INT = lex lex calc.l 3 %% % % lex.yy.c name definition name calc.l digit digit ([0-9]) pattern action pattern 1 action pattern C yylex() pattern lex action yytext yytext action yylex() pattern yylex() 3

4 1 pattern pattern abc abc abc* ab, abc, abcc, abccc,... abc+ abc, abcc, abccc,... a(bc)+ abc, abcbc, abcbcbc,... a(bc)? a, abc [abc] a, b, c [a-z] a, b, c,..., x, y, z [a\-z] a, -, z [-az] -, a, z [A-Za-z0-9]+ 1 [ \t\n]+ 1 whitespace [ˆab] a b [aˆb] a, ˆ, b [a b] a,, b a b a b "[a-z]+" [a-z]+. newline C lex.yy.c 2.4 calc.l yacc etc. yacc yylval yylex() yacc ASCII char yacc yacc lex yylex() yacc yylval return return yylex() yylex() yylex() 4

5 int calc.l yacc Integer calc.tab.h yylex() lex %option noyywrap % #include "calc.tab.h" % digit [0-9] %% digit+ yylval = atoi(yytext); return Integer; "+" "*" return *yytext; [ \t\n] ; /* */. yyerror("error: invalid character"); %% yylval Integer +, * yylval yyerror() yylex() C 3 Yacc [ ] calc.l yacc program: expression expression: multiplicative-expr multiplicative-expr + expression multiplicative-expr: constant constant * multiplicative-expr program yacc calc.y 5

6 *2 % #include <stdio.h> % %token Integer %% program: expr printf("%d\n", $1); ; expr: mult_expr $$ = $1; mult_expr + expr $$ = $1 + $3; ; mult_expr: Integer $$ = $1; Integer * mult_expr $$ = $1 * $3; ; %% int yyerror(char *s) fprintf(stderr, "%s\n", s); return 0; main() yyparse(); bison calc.tab.h C calc.tab.c calc.tab.h lex calc.l bison -d % bison -d calc.y % flex calc.l % gcc -o calc lex.yy.c calc.tab.c % cat sample 1+2*3+4 %./calc < sample 11 [ ] 1+2* yacc yacc yacc lex %% 3 *2 yacc mult-expr - 6

7 3.2.1 lex % % C calc.y %token Integer Integer %token yacc ASCII int yacc calc.tab.h lex Integer lex [ ] Integer yacc yylex() yacc c c c %token yacc ASCII 2 "+" "*" return *yytext; yacc + * nonterminal: rule 1 action 1 rule 2 action 2 ; nonterminal BNF ε rule i rule i c action i nonterminal C / rule i A: B... $1... C... $3... A: B X C... $3... X:... $0... $n X rule yacc LALR(1) lex expr: 7

8 Integer $$ = $1; expr + Integer $$ = $1 + $3; expr - Integer $$ = $1 - $3; ; Integer -2+3 expr -2+3 expr- 2+3 expr-integer +3 expr +3 expr+ 3 expr+integer expr $$ $n rule i n n $n yylval expr: expr + Integer $$ = $1 + $3; ; expr $1 Integer $3 expr expr $3 Integer yylval 2 yylex() yylval C yacc C yacc C yyerror() 1 calc.l calc.y % bison -d calc.y % flex calc.l % gcc -o calc calc.tab.c lex.yy.c % cat sample 1+2*3+4 %./calc < sample yacc expr expr: mult_expr $$ = $1; mult_expr + expr $$ = $1 + $3; mult_expr - expr $$ = $1 - $3; 8

9 ; [ ] (1-2)-3 3 Tiny C else C if identifier _ constant lex yylval program: external-declaration program external-declaration external-declaration: declaration function-definition declaration: int declarator-list ; declarator-list: declarator declarator-list, declarator declarator: identifier function-definition: int declarator ( parameter-type-list opt ) compound-statement parameter-type-list: parameter-declaration parameter-type-list, parameter-declaration parameter-declaration: int declarator statement: ; expression ; compound-statement if ( expression ) statement if ( expression ) statement else statement while ( expression ) statement return expression opt ; compound-statement: declaration-list opt statement-list opt declaration-list: declaration 9

10 declaration-list declaration statement-list: statement statement-list statement expression: assign-expr expression, assign-expr assign-expr: logical-or-expr identifier = assign-expr logical-or-expr: logical-and-expr logical-or-expr logical-and-expr logical-and-expr: equality-expr logical-and-expr && equality-expr equality-expr: relational-expr equality-expr == relational-expr equality-expr!= relational-expr relational-expr: add-expr relational-expr < add-expr relational-expr > add-expr relational-expr <= add-expr relational-expr >= add-expr add-expr: mult-expr add-expr + mult-expr add-expr - mult-expr mult-expr: unary-expr mult-expr * unary-expr mult-expr / unary-expr unary-expr: postfix-expr - unary-expr postfix-expr: primary-expr identifier ( argument-expression-list opt ) primary-expr: identifier constant ( expression ) argument-expression-list: assign-expr argument-expression-list, assign-expr 10

11 lex : %option noyywrap %option yylineno % #include "filename.tab.h" % %% %% yacc : % % %error_verbose %token Integer Identifer... %% program: %% extern int yylineno; int yyerror(char *s) fprintf(stderr, "%d: %s\n", yylineno, s); return 0; main() yyparse(); conflict yacc % bison -d calc.y calc.y contains 1 shift/reduce conflict. shift/reduce conflict reduce/reduce conflict 2 yacc shift/reduce conflict 3 else if-else else else if 2 C if else if conflict reduce/reduce conflict yacc reduce/reduce conflict conflict yacc (bison) -v filename.output

12 : % cat test.tc int fact(int x) int z; z = 1; while (x >= 1) z = z * x; x = x - 1; return z; %./tcc < test.tc % 5 [ ] yacc error 3 4 error shift/reduce conflict reduce/reduce conflict 4 (Syntax tree) [ 4.1 ] (syntax tree) 4.1 N (N-tuple) [ ] yacc lex yacc lex : typedef struct c /* constant node */ int op; int v; *constant; 12

13 typedef struct tk /* token node */ int op; char *name; *token; typedef struct tp /* n-tuple (n=4) */ int op; union nd *a[4]; *tuple; typedef union nd /* tree */ struct int op; n; struct tp tp; struct tk tk; struct c c; *tree; : tree make_tuple(int, tree, tree, tree, tree); tree make_token_node(char *); tree make_constant_node(int); struct tp a op int union nd op C op n op t tree switch(t->n.op) case Integer: case Identifier: op Integer + op CONS yacc %token [ ] filename.tab.h N int f(int x, int y) int a, b, c; statement-list statement 13

14 FUNDEF INT CONS CMPD_STM Identifier INT INT INT CONS "f" Identifier Identifier CONS statement_list statement "x" "y" CONS Identifier Identifier Identifier "c" "a" "b" 1 1 N op a[n] N 4 NULL CONS 2 Tiny C external-declaration program CONS CONS 2 program program external-declaration CONS program CONS statement statement-list CONS add-expr add_expr: mult_expr $$ = $1; add_expr + mult_expr $$ = make_tuple( +, $1, $3, NULL, NULL); add_expr - mult_expr $$ = make_tuple( -, $1, $3, NULL, NULL); ; yylval yacc $$ $n int YYSTYPE #define YYSTYPE int YYSTYPE yacc % % add_expr tree tree 14

15 % #define YYSTYPE tree % tree Identifier Integer $1 char * int primary_expr: Identifier $$ = make_token_node($1); Integer $$ = make_constant_node($1); ( expression ) $$ = $2; ; add_expr YYSTYPE %union %union YYSTYPE %union yylval %union int i; char *str; tree n; %union yacc yacc /* add_expr mult_expr tree */ %type <n> add_expr mult_expr yacc /* Identifier char * */ %token <str> Identifier lex yylval yylval.i = atoi(yytext); /* yylval int */ yylval.str = strdup(yytext); /* yylval char * */ [ ] identifier yylval.str yytext yylval.str yytext char *strdup(char *) *3 *3 string.h 15

16 4.3 program main: program ; if (yynerrs == 0) print_program($1); yynerrs yacc print_program() void print_program(tree p) if (p->n.op!= CONS) print_external_declaration(p); printf("\n"); else print_program(p->tp.a[0]); print_external_declaration(p->tp.a[1]); printf("\n"); expression % cat test1.tc int gcd(int a, int b) if (a == b) return a; else if (a > b) return gcd(a-b, b); else return gcd(a, b-a); %./tcc < test1.tc ((int gcd) ((int a)(int b)) ( (IF (== a b) (RETURN a) (IF (> a b) (RETURN (FCALL gcd (- a b) b)) (RETURN (FCALL gcd a (- b a))) ) ) )) 16

17 [ ] 5 [ 5 ] 6... Tiny C int yacc 5.1 Tiny C [1] 5.4 struct tk token typedef struct tk int op; struct tk *next; char *name; int lev; enum FRESH, VAR, FUN, PARM, UNDEFFUN kind; int offset; *token; lev lev

18 3 int cur_lev make_token_node() cur_lev lev cur_lev (compound-statement) 1 1 compound_statement: cur_lev++; declaration_list statement_list cur_lev--; ; [ ] $n n declaration_list $ kind kind FRESH: make_token_node() VAR: FUN: PARM: UNDEFFUN: VAR C Tiny C Tiny C kind FUN offset offset ; ebp token 5.4(c) 2 symtab token token make_token_node() 3 1 cur_lev-- 18

19 symtab Identifier Identifier Identifier Identifier Identifier y x foo VAR PARM FUN (c) symtab Identifier Identifier Identifier Identifier x foo Identifier PARM FUN 8 1 y 2 FRESH symtab Identifier Identifier Identifier Identifier Identifier y x foo FRESH PARM FUN symtab / tree lookup_sym(char *) tree NULL lookup_sym() if (!(yylval.n = lookup_sym(yytext))) yylval.n = make_token_node(yytext); return Identifier; lookup_sym() tree Identifier char * 19

20 5.3 *4 lookup_sym kind FRESH kind VAR 0 kind VAR kind VAR *5 kind VAR make_decl() declarator-list make_decl() : tree make_decl(tree n) switch (n->tk.kind) case VAR: /* */ if (n->tk.lev == cur_lev) /* */ error("redeclaration of %s ", n->tk.name); n = make_token_node(n->tk.name); break; case FUN: /* */ case UNDEFFUN: /* */ if (n->tk.lev == cur_lev) /* */ error(" %s redeclared as different kind of symbol", n->tk.name); n = make_token_node(n->tk.name); break; *4 *5 20

21 case PARM: /* */ warn("declaration of %s shadows a parameter", n->tk.name); n = make_token_node(n->tk.name); break; case FRESH: break; n->tk.kind = VAR; return n; make_decl() : declarator_list: declarator $$ = make_decl($1); /* $1 yylval.n */ error() warn() #include <stdio.h> #include <stdarg.h> int semnerrs; extern int yylineno; void error(char *fmt,...) va_list argp; va_start(argp, fmt); semnerrs++; fprintf(stderr, "%d: ", yylineno); vfprintf(stderr, fmt, argp); fprintf(stderr, "\n"); va_end(argp); void warn(char *fmt,...) va_list argp; va_start(argp, fmt); fprintf(stderr, "%d: warning: ", yylineno); vfprintf(stderr, fmt, argp); fprintf(stderr, "\n"); va_end(argp); error() warn() semnerrs semnerrs 1 error() warn() warn() make_decl() make_token_node() 21

22 tree make_parm_decl(tree n) switch (n->tk.kind) case VAR: case FUN: case UNDEFFUN: n = make_token_node(n->tk.name); break; case PARM: error("redeclaration of %s ", n->tk.name); return n; case FRESH: break; n->tk.kind = PARM; return n; tree make_fun_def(tree n) switch (n->tk.kind) case VAR: error(" %s redeclared as different kind of symbol", n->tk.name); break; case FUN: error("redefinition of %s ", n->tk.name); break; case UNDEFFUN: case FRESH: n->tk.kind = FUN; break; return n; lookup_sym() 22

23 kind FRESH kind VAR ref_var() ref_var() : tree ref_var(tree n) switch (n->tk.kind) case VAR: case PARM: break; case FUN: case UNDEFFUN: error("function %s is used as variable", n->tk.name); break; case FRESH: error(" %s undeclared variable", n->tk.name); n->tk.kind = VAR; /* */ break; return n; ref_var() : primary_expr: Identifier $$ = ref_var($1); globalize_sym() 4 ref_fun() : tree ref_fun(tree n) switch (n->tk.kind) casevar: case PARM: error("variable %s is used as function", n->tk.name); break; case FUN: 23

24 symtab Identifier Identifier Identifier Identifier Identifier Identifier z 3 VAR -8 f 2 UNDEFFUN -1 y x foo VAR -4 PARM 8 FUN 1 symtab Identifier Identifier Identifier Identifier Identifier Identifier z 3 VAR -8 y x foo VAR -4 PARM 8 FUN 1 f 0 UNDEFFUN -1 4 case UNDEFFUN: break; case FRESH: warn(" %s undeclared function", n->tk.name); n->tk.kind = UNDEFFUN; if (n->tk.lev > 0) globalize_sym(n); break; return n; ref_fun() : postfix_expr Identifier ( opt_argument_expression_list ) ref_fun($1) 7 6 Tiny C [ ] 24

25 : main: program ; symtab = NULL; cur_lev = 0; if (yynerrs == 0 && semnerrs == 0) print_program($2); % cat test.c int x; int f(int x, int y) int x; int x, y; x+y; int x, z; x+y+z; int w; x+y+w; x+y; int g(int y) int z; f(x, y); g(z); %./tcc < test.c 4: warning: declaration of x shadows a parameter 6: warning: declaration of y shadows a parameter (int x:0) ((int f:0) ((int x:1:8)(int y:1:12)) ( (int x:2:-4) ( (int x:3:-8 y:3:-12) (+ x:3 y:3) ( (int x:4:-16 z:4:-20) (+ (+ x:4 y:3) z:4) ) ) ( (int w:3:-8) (+ (+ x:2 y:1) w:3) ) (+ x:2 y:1) )) 25

26 ((int g:0) ((int y:1:8)) ( (int z:2:-4) (FCALL f:0 x:0 y:1) (FCALL g:0 z:2) )) [ ] 6 6 NASM [ 6 ] Pentium NASM (Netwide Assembler)[3] NASM [1] p. 160 foo NASM GLOBAL foo foo push ebp mov ebp, esp sub esp, 4 mov eax, [ebp+8] imul eax, [ebp+8] mov [ebp-4], eax mov eax, [ebp-4] add eax, 2 mov esp, ebp pop ebp ret NASM GLOBAL GLOBAL GLOBAL EXTERN Tiny C EXTERN abs abs EXTERN abs call abs 2 EXTERN 2 R n [R+n] [R-n] [n+r] / x x (_) COMMON 26

27 COMMON label n n label COMMON n Tiny C COMMON label [label] imul ebx, [x] push dword loc(v) mov dword loc(v), c cmp dword loc(v), c dword 32 (:) ; NASM % cat a.asm foo % cat main.c #include <stdio.h> main() printf("%d\n", foo(3)); % nasm -f elf a.asm % gcc main.c a.o %./a.out 11 foo() NASM main() gcc a.out [ ] int n n 2 foo NASM main.c 7 [ 6 ] NASM 4 27

28 eax *6 7.1 Nlocal p. 166 Nlocal struct code char *cd; struct code *next; ; #include <stdio.h> #include <stdlib.h> #include <string.h> struct code *emit(char *inst, char *op1, char *op2) char buf[80]; struct code *c = (struct code *)malloc(sizeof(struct code)); if (inst == NULL) buf[0] = \0 ; else if (op1 == NULL) sprintf(buf, "\t%s\n", inst); else if (op2 == NULL) sprintf(buf, "\t%s\t%s\n", inst, op1); else sprintf(buf, "\t%s\t%s, %s\n", inst, op1, op2); c->cd = strdup(buf); c->next = NULL; c ; return c; [ ] emit() emit() p. 186 emit() emit("mov", "eax", "1") *7 "\tmov\teax, 1\n" emit() ret *6 edx *7 emit() eax 1 emit() 28

29 emit("ret", NULL, NULL) C emit() struct code * main: program ; symtab = NULL; cur_lev = 0; if (yynerrs == 0 && semnerrs == 0) emit_program($2); print_code(); Lret n Ln char *make_label() [ ] 7.2 GLOBAL f f push ebp mov ebp, esp sub esp, Nlocal (*) top_alloc Lret mov esp, ebp pop ebp ret Nlocal (*) sub esp, Nlocal struct code *c = emit(null, NULL, NULL); top_alloc 0 Nlocal 0 ; if (top_alloc) char buf[80]; sprintf(buf, "\tsub\tesp, %d\n", -top_alloc); c->cd = strdup(buf); 29

30 emit("mov", "esp", "ebp"); /* */ top_alloc while case WHILE: ; ; ; emit("cmp", "eax", "0"); emit("je",, NULL); ; emit("jmp",, NULL); ; break; 7.4 eax RSL RSL RSL ; ; emit("mov",, "eax"); ; emit(, "eax", ); ; eax [ ] 30

31 RSL Nlocal allocate_loc release_loc idiv idiv edx eax 64 edx eax eax edx e 1 eax edx RSL e 2 eax mov temp, eax e 1 eax cdq idiv dword temp / e 2 L e 2 v e 1 eax cdq idiv dword loc(v) L e 2 c e 1 eax cdq mov dword temp, c idiv dword temp cdq eax 32 edx 32 eax ==,!=, >, etc. cmp setc al movzx eax, al ; al 32 eax setc c g, ge, e 1 0 al al eax 8 8 e 1 >= e 2 RSL e 2 eax mov temp, eax e 1 eax cmp eax, temp setge al movzx eax, al 31

32 7.4.3 &&, e 1 && e 2 L: mov dword temp, 0 e 1 L e 2 L mov dword temp, 1 mov eax, temp push call f(e1, e2,..., en) en push kind UNDEFFUN EXTERN [ ] EXTERN UNDEFFUN call EXTERN 8 Tiny C for, continue, break [ ] continue, break / / [ ] & ˆ and, or xor char [ ] CISC [4] 32

33 8 flex, bison, nasm UNIX man Flex Bison NASM emacs info URL[2] info emacs M-x info NASM URL[3] [1] [2] [3] NASM [4] (R) 64 IA

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

(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

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

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

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 II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C 1 6 9 1 main main 1 NULL NULL 1 15 23 25 48 26 30 32 36 38 43 45 47 50 52 for 2 (a) 2 2 1 Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word

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

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

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

( ) ( ) 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

() / (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

: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

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

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

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

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

: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

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

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

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

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

プログラミング言語処理系論 (4) Design and Implementation of Programming Language Processors

プログラミング言語処理系論 (4) Design and Implementation of Programming Language Processors プログラミング言語処理系論 (4) Design and Implementation of Programming Language Processors 佐藤周行 ( 情報基盤センター / 電気系専攻融合情報学コース ) 今回の予定 言語規格を読むことの続き BNF だけでできることは限られてくる 文法の定義 + 制約 という記述の発明 文法から パーサを作る BNF をそのまま解釈する BISON,YACC

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

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

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

compiler-text.dvi

compiler-text.dvi 2018.4 1 2 2.1 1 1 1 1: 1. (source program) 2. (object code) 3. 1 2.2 C if while return C input() output() fun var ( ) main() C (C-Prime) C A B C 2.3 Pascal P 1 C LDC load constant LOD load STR store AOP

More information

C言語によるアルゴリズムとデータ構造

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

コンパイラとは プログラミング言語 ( 高級言語 ) で書かれたプログラムを入力し, コンピュータが実行できる言語 ( 機械語など ) に変換するプログラムのこと例 : gcc コンパイラは対応する言語によって複雑である場合もあるし単純である場合もある 本実験では簡単な言語のコンパイラを作成する

コンパイラとは プログラミング言語 ( 高級言語 ) で書かれたプログラムを入力し, コンピュータが実行できる言語 ( 機械語など ) に変換するプログラムのこと例 : gcc コンパイラは対応する言語によって複雑である場合もあるし単純である場合もある 本実験では簡単な言語のコンパイラを作成する 情報工学実験 C コンパイラ (2016 年度 ) 担当 : 笹倉 佐藤 2016.12.7version コンパイラとは プログラミング言語 ( 高級言語 ) で書かれたプログラムを入力し, コンピュータが実行できる言語 ( 機械語など ) に変換するプログラムのこと例 : gcc コンパイラは対応する言語によって複雑である場合もあるし単純である場合もある 本実験では簡単な言語のコンパイラを作成する

More information

解きながら学ぶJava入門編

解きながら学ぶJava入門編 44 // class Negative { System.out.print(""); int n = stdin.nextint(); if (n < 0) System.out.println(""); -10 Ÿ 35 Ÿ 0 n if statement if ( ) if i f ( ) if n < 0 < true false true false boolean literalboolean

More information

r1.dvi

r1.dvi 2014 1 2014.4.10 0 / 1 / 2 / 3 Lisp 4 5 ( ) 1 (5 1 ) 5 1 1.1? 0 1 (bit sequence) 5 101 3 11 2 (binary system) 2 1000 8 1 ( ) ( )? ( 1) r1 1000 1001 r2 1002... r3 1: (memory) (address) CPU (instruction)

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

‚æ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

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

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat C () 14 5 23 C () C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C 1.1 3 7 mandata mandata () name age income mandata () mandata1 1 #include struct mandata char name[51];

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

Jacques Garrigue

Jacques Garrigue Jacques Garrigue Garrigue 1 Garrigue 2 $ print_lines () > for i in $1; do > echo $i > done $ print_lines "a b c" a b c Garrigue 3 Emacs Lisp (defun print-lines (lines) (dolist (str lines) (insert str)

More information

今回の予定 文法から パーサを作る BNF をそのまま解釈する BISON,YACC を動かしてみます 電卓 ( もどき ) を離れ本格的なプログラミング言語を記述するのに必要な構成要素を考えます 正常系だけを相手にするなら ( エラー処理を考えないなら ) 言語の実装はとても簡単 ( 課題ではない

今回の予定 文法から パーサを作る BNF をそのまま解釈する BISON,YACC を動かしてみます 電卓 ( もどき ) を離れ本格的なプログラミング言語を記述するのに必要な構成要素を考えます 正常系だけを相手にするなら ( エラー処理を考えないなら ) 言語の実装はとても簡単 ( 課題ではない プログラミング言語処理系論 (5) Design and Implementation of Programming Language Processors 佐藤周行 ( 情報基盤センター / 電気系専攻融合情報学コース ) 今回の予定 文法から パーサを作る BNF をそのまま解釈する BISON,YACC を動かしてみます 電卓 ( もどき ) を離れ本格的なプログラミング言語を記述するのに必要な構成要素を考えます

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

新版明解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

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

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

ohp07.dvi

ohp07.dvi 17 7 (2) 2017.9.13 1 BNF BNF ( ) ( ) 0 ( ) + 1 ( ) ( ) [ ] BNF BNF BNF prog ::= ( stat ) stat ::= ident = expr ; read ident ; print expr ; if ( expr ) stat while ( expr ) stat { prog expr ::= term ( +

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

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

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

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

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

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

ARM gcc Kunihiko IMAI 2009 1 11 ARM gcc 1 2 2 2 3 3 4 3 4.1................................. 3 4.2............................................ 4 4.3........................................

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

listings-ext

listings-ext (6) Python (2) ( ) ohsaki@kwansei.ac.jp 5 Python (2) 1 5.1 (statement)........................... 1 5.2 (scope)......................... 11 5.3 (subroutine).................... 14 5 Python (2) Python 5.1

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

PL : pl0 ( ) 1 SableCC ( sablecc ) 1.1 sablecc sablecc Étienne Gagnon [1] Java sablecc sablecc ( ) Visitor DepthFirstAdapter 1 (Depth

PL : pl0 ( ) 1 SableCC ( sablecc ) 1.1 sablecc sablecc Étienne Gagnon [1] Java sablecc sablecc ( ) Visitor DepthFirstAdapter 1 (Depth PL0 2007 : 2007.05.29 pl0 ( ) 1 SableCC ( sablecc ) 1.1 sablecc sablecc Étienne Gagnon [1] Java sablecc sablecc () Visitor DepthFirstAdapter 1 (Depth First traversal) ( ) (breadth first) 2 sablecc 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

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

LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP : 1

LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP : 1 2007 7 17 2 1 1.1 LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP 2 2 5 5 5 1: 1 2 データの追加 データの取り出し 5 2 5 2 5 2: 1.2 [1] pp.199 217 2 (binary tree) 2 2.1 (three: ) ( ) 秋田高専 校長 準学士課程学生

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

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

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

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

More information

55-2.indb

55-2.indb THE SCIENCE AND ENGINEERING REVIEW OF DOSHISHA UNIVERSITY, VOL. 55, No. 2 July 2014 Design and Development Methodology of C Language Markup Converter Based on XML Takuya TOITA *, Kazuki YOSHIDA ** and

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

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç C (3) if else switch AND && OR (NOT)! 1 BMI BMI BMI = 10 4 [kg]) ( [cm]) 2 bmi1.c Input your height[cm]: 173.2 Enter Input your weight[kg]: 60.3 Enter Your BMI is 20.1. 10 4 = 10000.0 1 BMI BMI BMI = 10

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

新・明解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

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

e.c e.s e.scala /* e.c */ int add(int a, int b) { return a + b; void main() { int a = add(3, 4); printf( %d n, a); ; e.s.text.globl _add _add: pushq %rbp movq %rsp, %rbp movl %edi, -4(%rbp) movl %esi,

More information

B演習(言語処理系演習)第一回

B演習(言語処理系演習)第一回 B 演習 ( 言語処理系演習 ) 第 3 回 字句解析 田浦 今日の予定 字句解析インタフェース 今週の課題 字句の定義 字句解析器の仕組み ( 概要 ) 下請け部品 char_buf, char_stream, int_stack まめ知識 : デバッガ デバッグに関する若干の抽象論 字句解析器とは ) 字句解析器 (tokenizer) d e f f i b ( n ) : ( Identifier

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

untitled

untitled Fortran90 ( ) 17 12 29 1 Fortran90 Fortran90 FORTRAN77 Fortran90 1 Fortran90 module 1.1 Windows Windows UNIX Cygwin (http://www.cygwin.com) C\: Install Cygwin f77 emacs latex ps2eps dvips Fortran90 Intel

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) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (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

Parametric Polymorphism

Parametric Polymorphism ML 2 2011/04/19 Parametric Polymorphism Type Polymorphism ? : val hd_int : int list - > int val hd_bool : bool list - > bool val hd_i_x_b : (int * bool) list - > int * bool etc. let hd_int = function (x

More information

Microsoft PowerPoint - CproNt02.ppt [互換モード]

Microsoft PowerPoint - CproNt02.ppt [互換モード] 第 2 章 C プログラムの書き方 CPro:02-01 概要 C プログラムの構成要素は関数 ( プログラム = 関数の集まり ) 関数は, ヘッダと本体からなる 使用する関数は, プログラムの先頭 ( 厳密には, 使用場所より前 ) で型宣言 ( プロトタイプ宣言 ) する 関数は仮引数を用いることができる ( なくてもよい ) 関数には戻り値がある ( なくてもよい void 型 ) コメント

More information

I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp / SCHEDULE 1. 2011/06/07(Tue) / Basic of

More information

Vol.55 No (Jan. 2014) De-gapper 1,a) 2, , De-gapper De-gapper De-gapper Tool for Support Programming Learners Step-b

Vol.55 No (Jan. 2014) De-gapper 1,a) 2, , De-gapper De-gapper De-gapper Tool for Support Programming Learners Step-b De-gapper 1,a) 2,3 4 3 2013 3 18, 2013 10 9 1 De-gapper De-gapper De-gapper Tool for Support Programming Learners Step-by-step Learning Shinya Cho 1,a) Yayoi Hofuku 2,3 Tomohiro Nishida 4 Susumu Kanemune

More information

main.dvi

main.dvi 1 F77 5 hmogi-2008f@kiban.civil.saitama-u.ac.jp 2013/5/13 1 2 f77... f77.exe f77.exe CDROM (CDROM D D: setupond E E: setupone 5 C:work\T66160\20130422>f77 menseki.f -o menseki f77(.exe) f77 f77(.exe) C:work\T66160\20130422>set

More information

新版明解C言語入門編

新版明解C言語入門編 175cm 60kg ( ) 175cm 175.3cm 175.869758 cm 175cm 60kg p.177 18-1 vx - vy vx vy List -1 List -1 int vx, vy; puts(""); printf(" vx "); scanf("%d", &vx); printf(" vy "); scanf("%d", &vy); printf("vx + vy

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

sdbin /03/30 Program name is xman Now analysing ScrollByL.i. Now analysing handler.i. struct (dot)member not defined 2 directory_height yyer

sdbin /03/30 Program name is xman Now analysing ScrollByL.i. Now analysing handler.i. struct (dot)member not defined 2 directory_height yyer Sapid Bug List 1997 8 21 1 0001 0010 sdbin3-0001 1995/03/30 Error in sdbin X11R5/clients/twm/gram.c gram.i yacc # yacc yacc (gram.y gram.c) # gram.y *.h (1995/11/28, ver. 1.132) sdbin3-0002 1995/03/30

More information

I 2 tutimura/ I 2 p.1/??

I 2   tutimura/ I 2 p.1/?? I 2 tutimura@mist.i.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/ 2002 4 25 I 2 p.1/?? / / Makefile I 2 p.2/?? Makefile make GNU make I 2 p.3/?? Makefile L A T E X I 2 p.4/?? core (1) gcc,

More information

新版 明解C++入門編

新版 明解C++入門編 第 1 章画面 出力 入力 C++ C++ C++ C++ C++ C++ C++ C++ #include using C++ C++ C++ main C++ C++ C++ int double char C++ C++ C++ string C++ C++ C++ 21 1-1 C++ 歴史 C++ C++ 歴史 CC with classes Fig.1-1 C C++ Simula 67

More information

bitvisor-ipc v12b.key

bitvisor-ipc v12b.key PC PC OS PC PC 1 1 2 101 101 enum tre_rpc_direction { TRE_RPC_DIRECTION_REQUEST, TRE_RPC_DIRECTION_RESULT }; struct tre_rpc_request { }; enum tre_rpc_direction direction; ulong id; ulong proc_number;

More information

# let st1 = {name = "Taro Yamada"; id = };; val st1 : student = {name="taro Yamada"; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n

# let st1 = {name = Taro Yamada; id = };; val st1 : student = {name=taro Yamada; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n II 6 / : 2001 11 21 (OCaml ) 1 (field) name id type # type student = {name : string; id : int};; type student = { name : string; id : int; } student {} type = { 1 : 1 ;...; n : n } { 1 = 1 ;...; n = n

More information

: gettoken(1) module P = Printf exception End_of_system (* *) let _ISTREAM = ref stdin let ch = ref ( ) let read () = (let c =!ch in ch := inp

: gettoken(1) module P = Printf exception End_of_system (* *) let _ISTREAM = ref stdin let ch = ref ( ) let read () = (let c =!ch in ch := inp 7 OCaml () 1. 2. () (compiler) (interpreter) 2 OCaml (syntax) (BNF,backus normal form ) 1 + 2; let x be 2-1 in x; ::= ; let be in ; ::= + - ::= * / ::= 7.1 ( (printable characters) (tokens) 1 (lexical

More information

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます.  このサンプルページの内容は, 新装版 1 刷発行時のものです. C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. http://www.morikita.co.jp/books/mid/009383 このサンプルページの内容は, 新装版 1 刷発行時のものです. i 2 22 2 13 ( ) 2 (1) ANSI (2) 2 (3) Web http://www.morikita.co.jp/books/mid/009383

More information

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 1. 1.1. 1.2. 1 PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 2. 2.1. 2 1 2 C a b N: PC BC c 3C ac b 3 4 a F7 b Y c 6 5 a ctrl+f5) 4 2.2. main 2.3. main 2.4. 3 4 5 6 7 printf printf

More information

PowerPoint Template

PowerPoint Template プログラミング演習 Ⅲ Linked List P. Ravindra S. De Silva e-mail: ravi@cs.tut.ac.jp, Room F-413 URL: www.icd.cs.tut.ac.jp/~ravi/prog3/index_j.html 連結リストとは? 一つひとつの要素がその前後の要素との参照関係をもつデータ構造 A B C D 連結リストを使用する利点 - 通常の配列はサイズが固定されている

More information

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL   2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b II 5 (1 2005 5 26 http://www.math.meiji.ac.jp/~mk/syori2-2005/ UNIX (Linux Linux 1 : 2005 http://www.math.meiji.ac.jp/~mk/syori2-2005/jouhousyori2-2005-00/node2. html ( (Linux 1 2 ( ( http://www.meiji.ac.jp/mind/tool/internet-license/

More information

Microsoft Word - Sample_CQS-Report_English_backslant.doc

Microsoft Word - Sample_CQS-Report_English_backslant.doc ***** Corporation ANSI C compiler test system System test report 2005/11/16 Japan Novel Corporation *****V43/NQP-DS-501-1 Contents Contents......2 1. Evaluated compiler......3 1.1. smp-compiler compiler...3

More information

r02.dvi

r02.dvi 172 2017.7.16 1 1.1? X A B A X B ( )? IBMPL/I FACOM PL1 ( ) X ( ) 1.2 1 2-0 ( ) ( ) ( ) (12) ( ) (112) (131) 281 26 1 (syntax) (semantics) ( ) 2 2.1 BNF BNF(Backus Normal Form) Joun Backus (grammer) English

More information

6-1

6-1 6-1 (data type) 6-2 6-3 ML, Haskell, Scala Lisp, Prolog (setq x 123) (+ x 456) (setq x "abc") (+ x 456) ; 6-4 ( ) subtype INDEX is INTEGER range -10..10; type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN);

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

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology I117 28 School of Information Science, Japan Advanced Institute of Science and Technology debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology 2008 1-2 1 a) b)

More information

JEB Plugin 開発チュートリアル 第4回

JEB Plugin 開発チュートリアル 第4回 Japan Computer Emergency Response Team Coordination Center 電子署名者 : Japan Computer Emergency Response Team Coordination Center DN : c=jp, st=tokyo, l=chiyoda-ku, email=office@jpcert.or.jp, o=japan Computer

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

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

kiso2-03.key

kiso2-03.key 座席指定はありません Linux を起動して下さい 第3回 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 計算機基礎実習II 第2回の復習課題(rev02) 第3回の基本課題(base03) 第2回課題の回答例 ex02-2.c include int main { int l int v, s; /* 一辺の長さ */ /* 体積 v

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