プログラミング言語 8 字句解析器(lexer)と構文解析器(parser)
|
|
|
- つかさ すみだ
- 6 years ago
- Views:
Transcription
1 8 (lexer) (parser) 1 / 73
2 (lexer, tokenizer) (parser) Web Page (HTML XML) CSV, SVG, config file... ( )! 2 / 73
3 1 1 OCaml : ocamllex ocamlyacc 2 Python : ply 2! 3 / 73
4 ( ) 字句解析器 構文解析器 ご注文はうさぎさんですか? 文字列 接頭詞名詞助詞名詞名詞助動詞助詞記号ご注文はうさぎさんですか? 字句列 構文 名詞句 文 名詞句 動詞句 動詞句 接頭詞名詞助詞名詞名詞助動詞助詞記号ご注文はうさぎさんですか? 注 : 動詞句 などのラベルは本気にしないでください 4 / 73
5 let_expr expr expr expr expr term term term term term pr pr pr pr pr pr pr LET ID EQ ID PLUS ID PLUS NUM MUL ID IN ID ID let x = a + b + 2 * c in f x let x = a + b + 2 * c in f x 5 / 73
6 ? : : ( ) 6 / 73
7 ocamllex : ocamllex =.mll (OCaml ) (calc lex.mll) 1 { (* : OCaml *) 2 type token = 3 NUM of (int) 4 PLUS 5 EOF 6 } 7 8 (* *) 9 rule lex = parse 10 [ \t \n ] { lex lexbuf } (* *) 11 "+" { PLUS } 12 [ 0-9 ]+ as s { NUM(int_of_string s) } 13 eof { EOF } { (* OCaml *) } 7 / 73
8 .mll { OCaml } (* *) let id =... rule lex = parse { } { }... { } { OCaml } { } : (prefix) ( ) as 1 [ 0-9 ]+ as s { NUM(int_of_string s) } 1 let digit = [ 0-9 ] 1 digit+ as s { NUM(int_of_string s) } 8 / 73
9 ocamllex ( ) 1 ( ) a a [ a b c ] a, b, c [ 0-9 ] 0, 1,..., 9 "abc" abc "abc" "def" abc def "abc"* abc 0 "abc"+ abc 1 ("abc" "def")+ (abc def) 1 eof manual-ocaml-400/manual026.html ( ) manual026.html ( ) 9 / 73
10 : ( ) ( ) A A ( ) ϵ a (a A) a RS (R, S ) R S R S (R, S ) R S R (R ) R 0 ( : (abc def)+) ( ) 10 / 73
11 ocamllex ocamllex (.mll) OCaml (.ml) 1 $ ocamllex calc lex.mll 2 6 states, 267 transitions, table size 1104 bytes 3 $ ls 4 calc lex.ml calc_lex.mll.ml lex (.mll rule lex = parse... ) 1 $ ocaml -init calc_lex.ml 2 OCaml version # lex ;; 5 - : Lexing.lexbuf -> token = <fun> Lexing.lexbuf ( C FILE*) mutable record lex buf buf 11 / 73
12 Lexing.lexbuf 1 Lexing.from string "12+34* 56" 1 Lexing.from channel stdin 1 Lexing.from channel (open_in "exp.txt") 12 / 73
13 $ ocamllex calc_lex.mll 6 states, 267 transitions, table size 1104 bytes $ ocaml -init calc_lex.ml OCaml version # let b = Lexing.from_string " ";; val b : Lexing.lexbuf = {... ( )... } # lex b;; - : token = NUM 12 # lex b;; - : token = PLUS # lex b ;; - : token = NUM 34 # lex b ;; - : token = PLUS # lex b;; - : token = NUM 56 # lex b;; - : token = EOF rule lex = parse [ \t \n ] { lex lexbuf } "+" { PLUS } [ 0-9 ]+ as s { NUM(int_of_string s) } eof { EOF } 13 / 73
14 ocamlyacc : /* + OCaml */ %{ (* OCaml *) %} /* */ %token <int> NUM %token PLUS EOF /* ( ) */ %start program %type <int> program %% /* */ expr : NUM { $1 } expr PLUS NUM { $1 + $3 } program : expr EOF { $1 } %% (* OCaml *) =.mly : %% 3 + OCaml OCaml %token : %start : ( ) %type : ( ) :.mll.mly ( ) 14 / 73
15 ocamlyacc menhir ocamlyacc menhir ocaml ocamlyacc 15 / 73
16 ocamlyacc : 1 expr : expr PLUS NUM {... } : expr ( ) PLUS (1 ) NUM ( ) expr ( ) {...} ( ) : ( ) ( ) expr expr PLUS NUM } } / 73
17 ( ) : T : NT : S NT. a = b 1 b n (n 0, a NT, b i NT T ). : b 1,... bn, a : bi b i 1 ( ) ( ) 17 / 73
18 OCaml $1, $2,... : a = b 1... b n a : 1 expr : expr PLUS NUM { $1 + $3 } : expr PLUS NUM 1 expr( ) 3 NUM( ) 18 / 73
19 ocamlyacc ocamlyacc.mly 2 OCaml (.ml.mli).mli? 1 $ ocamlyacc calc_parse.mly 2 $ ls 3 calc parse.ml calc parse.mli calc_parse.mly.ml.mly %start program program 19 / 73
20 ocamlyacc ( ) 1 $ ocaml -init calc_parse.ml 2 OCaml version # program ;; 5 - : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> int = <fun> Lexing.lexbuf -> token int.mly (%type <int> parse) token token (token ) 20 / 73
21 (lex) (program) 1 # program lex (Lexing.from_string " ") : 1 2 :.mll token.mly token 21 / 73
22 token token.mll 1 $ ocaml -init calc_lex.ml 2 # lex;; 3 - : Lexing.lexbuf -> token = <fun> token calc lex.ml token.mly 1 $ ocaml -init calc_parse.ml 2 # program ;; 3 - : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> int = <fun> calc parse.ml token OCaml 22 / 73
23 token 1:.mll token.mly 2:.mly token.mll 1 23 / 73
24 token calc lex.mll : 1 { 2 (* token *) 3 (* PLUS 4 calc_parse.ml ( ) 5 *) 6 open Calc parse 7 } 8 rule lex = parse 9 [ \t \n ] { lex lexbuf } 10 "+" { PLUS } 11 [ 0-9 ]+ as s { NUM(int_of_string s) } 12 eof { EOF } 24 / 73
25 1 $ ocaml ocaml_lex.ml ocaml_parse.ml # NG 2 $ ocaml -init ocaml_lex.ml -init ocaml_parse.ml # NG : ocaml.ml ocaml.ml ocamlc (.cmo) 25 / 73
26 1 $ ocamllex calc_lex.mll 2 $ ocamlyacc calc_parse.mly 3 # ocamlc 3! 4 # parse, lex 5 $ ocamlc -c calc parse.mli calc parse.ml calc lex.ml 6 # ocaml.cmo 7 $ ocaml calc parse.cmo calc lex.cmo 8 OCaml version # Calc_parse.program;; 11 - : (Lexing.lexbuf -> Calc parse.token) -> Lexing.lexbuf -> int = <fun> 12 # Calc_lex.lex;; 13 - : Lexing.lexbuf -> Calc parse.token = <fun> 1 # Calc_parse.program Calc_lex.lex (Lexing.from_string " ");; 2 - : int = / 73
27 OCaml.ml.ml.cmo ( ) ocaml.cmo ocamlc -c ( ) : calc lex.ml calc parse.ml token calc parse.ml calc lex.ml 27 / 73
28 : ocamlbuild OCaml ( ) 1 $ ocamlbuild calc lex.byte 2 /usr/bin/ocamllex -q calc_lex.mll 3 /usr/bin/ocamldep -modules calc_lex.ml > calc_lex.ml.depends 4 /usr/bin/ocamlyacc calc_parse.mly 5 /usr/bin/ocamldep -modules calc_parse.mli > calc_parse.mli.depends 6 /usr/bin/ocamlc -c -o calc_parse.cmi calc_parse.mli 7 /usr/bin/ocamlc -c -o calc_lex.cmo calc_lex.ml 8 /usr/bin/ocamldep -modules calc_parse.ml > calc_parse.ml.depends 9 /usr/bin/ocamlc -c -o calc_parse.cmo calc_parse.ml 10 /usr/bin/ocamlc calc_parse.cmo calc_lex.cmo -o calc_lex.byte 11 $ ls 12 build/ calc lex.byte calc_lex.mll calc_parse.mly 13 # _build 14 # -I _build 15 $ ocaml -I build _build/*.cmo 16 OCaml version # 28 / 73
29 ocamlmktop *.cmo 1 $ ocaml -I _build _build/*.cmo 2 OCaml version # ocaml 1 $ ocamlmktop -o calc.top _build/*.cmo *.cmo ( calc.top) 1 $./calc.top -I build 2 OCaml version # 29 / 73
30 OCaml ( : abc.ml) ( / etc.) 1: Abc. 2: open Abc ocamlc ocaml ocamlmktop *.cmi *.cmo -I 30 / 73
31 (1) 1 expr : 2 NUM 3 expr PLUS NUM { $1 + $3 }? expr : NUM NUM PLUS expr { $1 + $3 } expr : NUM expr PLUS expr { $1 + $3 } (+) (left associative) : a + b + c = ((a + b) + c) 31 / 73
32 (2) * ( )? 1 expr : 2 NUM 3 expr PLUS NUM { $1 + $3 } 4 expr MUL NUM { $1 * $3 } = (3 + 4) 5 = = 3 + (4 5) = 23 * (term) + (expr) 32 / 73
33 : ocamlyacc %left ( ) %right ( ) 33 / 73
34 3 1 (1 ) 2 OCaml (3 ) 3 OCaml (4 ) ( ) let ( ) 34 / 73
35 ( ) + ( ) + + 0: ( ) 1: (let) 2: 35 / 73
36 1 expr : 2 NUM { $1 } 3 expr PLUS NUM { $1 +. $3 } 1 # parse_string " * 5.6" 2 - : float = ( ) ( ) : : 36 / 73
37 : * 5.6 : + * e 0 +e 1 : e0 の構文木 e1 の構文木 OCaml 1 type expr = Plus of expr * expr 37 / 73
38 ( ). + eval_expr = eval_expr + e0 の構文木 eval_expr e1 の構文木 e0 の構文木 e1 の構文木 : eval expr (e 0 + e 1 ) = (eval expr e 0 ) + (eval expr e 1 ) OCaml : 1 let rec eval_expr e = 2 match e with Plus (e0, e1) -> (eval_expr e0) + (eval_expr e1) 38 / 73
39 x + 1 ( )x NG: : let x = in x : x = 3.3 x : 39 / 73
40 : : {x 3.3, y 4.4} let x = in x : eval expr (let x = in x + 4.4) {} = eval expr (x + 4.4) {x 3.3} = eval expr x {x 3.3} + eval expr 4.4 {x 3.3} = = [ (x, 3.3); (y, 4.4) ] 40 / 73
41 f f x = x * x (f 3) {x 3} x * x eval expr (e 0 e 1 ) e = let f = eval expr e 0 in let v = eval expr e 1 in eval expr (f ) {f v} =, ( ) 41 / 73
42 ? : 1 let make_adder x = 2 let f y = x + y in f 3 ;; 4 let a11 = make_adder 1.1 in 5 a a x + y {y 2.2} (x ) x = 1.1 a11 ( ) (2 ) =, ( ), 42 / 73
43 : 2?? 43 / 73
44 ϵ A = a A = a RS A = RS R S A = R, A = S R A =, A = A R 44 / 73
45 ? ϵ A = a A = a RS A = R S R S A = R, A = S R A =, A = A R? A =, A = AR A =, A = RA (R A ) 45 / 73
46 ? : = A =, A = aab a n b n (n 0) / 73
47 A =, A = aab * ( ) * 1 k a k b k? a ( b) a ( b) aa aaa aabb bb aa aaa aaa aabb bb ab a b a aa aabbb bb aa aabbb aabbb bb 47 / 73
48 OCaml 48 / 73
49 OCaml ( ) : ocamllex, ocamlyacc OCaml (.ml ) OCaml 49 / 73
50 OCaml 3 OCaml 3 1 (ocaml) 2 (ocamlc); 3 (ocamlopt); 50 / 73
51 : (hi.ml) 1 Printf.printf "hello\n" 1 $ ocaml hi.ml 2 hello 1 $ ocaml 2 # #use "hi.ml";; 3 # 1 $ ocaml -init hi.ml 2 # 1 $ ocamlc hi.ml 2 $ ls 3 a.out* hi.cmi hi.cmo hi.ml 4 $./a.out 5 hello 1 $ ocamlopt hi.ml 2 $ ls 3 a.out* hi.cmi hi.cmx hi.ml hi.o 4 $./a.out 5 hello 51 / 73
52 ocamlc ocamlopt.cmi hi.ml ( hi.ml ).cmo hi.ml (.o ).cmx hi.ml (.o ).o a.out 52 / 73
53 -c -o ocamlc, ocamlopt C -o -c ocamlc : {.cmi,.cmo} ocamlopt : {.cmi,.cmx,.o} 53 / 73
54 : 2 msg.ml 1 let greeting = "hello" hi.ml 1 Printf.printf "%s\n" Msg.greeting hi.ml msg.ml greeting ( ) 1: (msg.ml greeting) Msg.greeting. = basename (.ml ) capitalize 54 / 73
55 open open 1 open Msg;; 2 Printf.printf "%s\n" greeting open 55 / 73
56 1: 1 $ ls 2 hi.ml msg.ml 3 $ ocamlc -o greet msg.ml hi.ml 4 $ ls 5 greet* hi.cmi hi.cmo hi.ml msg.cmi msg.cmo msg.ml 2: ( ) 1 $ ls 2 hi.ml msg.ml 3 $ ocamlc -c msg.ml # -> msg.{cmi,cmo} 4 $ ocamlc -c hi.ml # -> hi.{cmi,cmo} 5 $ ocamlc -o greet msg.cmo hi.cmo # -> greet 6 $./greet 7 hello 56 / 73
57 1: 1 $ ocamlc hi.ml msg.ml 2 File "hi.ml", line 1, characters 21-33: 3 Error: Unbound module Msg 2: 1 $ ls 2 hi.ml msg.ml 3 $ ocamlc -c hi.ml 4 File "hi.ml", line 1, characters 14-26: 5 Error: Unbound module Msg 2: ( : hi.ml).cmi ( : msg.cmi) 57 / 73
58 hi.ml msg.ml ( ) OK NG $ ocamlc msg.ml hi.ml $ ocamlc hi.ml msg.ml $ ocamlc -c msg.ml $ ocamlc -c hi.ml $ ocamlc -c hi.ml $ ocamlc -c msg.ml ( ) OK NG $ ocamlopt msg.ml hi.ml $ ocamlopt hi.ml msg.ml $ ocamlopt -c msg.ml $ ocamlopt -c hi.ml $ ocamlopt -c hi.ml $ ocamlopt -c msg.ml 58 / 73
59 (ocaml) 1: ocamlc.cmo ( ) 2: 1 $ ocaml msg.cmo hi.cmo 2 # NG 1 $ ocaml hi.cmo msg.cmo 2 File "_none_", line 1: 3 Error: Reference to undefined global Msg ocamlc.ml 59 / 73
60 ocamlmktop ocamlmktop.cmo 1 $ ocamlmktop -o greet msg.cmo hi.cmo 2 $./greet 3 hello 4 OCaml version #.cmo 60 / 73
61 : OCaml 2 (.ml.mli).ml : ( C.c).mli : ( C.h).mli.ml ( ) ( ) : msg.ml 1 let real_mind = "you a** h*le" 2 let greeting = "glad to see you" msg.mli (real mind ) 1 val greeting : string 61 / 73
62 .mli? ocamlyacc.mli 62 / 73
63 .mli.mli.cmi.ml.cmo 1 $ ocamlc a.ml 1 a.mli a.cmi, a.cmo a.cmi a.ml 2 a.mli a.cmi ( a.mli!).ml.cmi 3: ( : msg.ml) ( : msg.mli) ( : msg.cmi) 63 / 73
64 .mli : 6 a.{mli,ml}, b.{mli,ml}, c.ml, d.ml 1: 1 $ ocamlc -o program b.mli a.mli b.ml a.ml d.ml c.ml 2: 1 $ ocamlc -c b.mli 2 $ ocamlc -c a.mli 3 $ ocamlc -c b.ml 4 $ ocamlc -c a.ml 5 $ ocamlc -c d.ml 6 $ ocamlc -c c.ml 7 $ ocamlc -o program b.cmo a.cmo d.cmo c.cmo 1 $ ocaml b.cmo a.cmo d.cmo c.cmo 1 $ ocamlmktop -o program b.cmo a.cmo d.cmo c.cmo 64 / 73
65 ocamlbuild 1 $ ocamlbuild name.byte name.ml... (ocamldep) name.byte 1 $ ocamlbuild name.native 65 / 73
66 token 1:.mll token.mly.mll token 1: open Calc parse Calc parse ( ) 1 : token Calc parse.plus Calc parse.minus 2:.mly token.mll 2: ocamlyacc menhir menhir --external-tokens 1 $ menhir --external-tokens Calc_lex calc_parse.mly 66 / 73
67 : 1 ( ) calc lex.mll : Calc parse open calc parse.ml 1 { 2 open Calc_parse 3 } 4 rule lex = parse 5 [ \t \n ] { lex lexbuf } 6 "+" { PLUS } 7 "-" { MINUS } 8 [ 0-9 ]+ as s { NUM(int_of_string s) } 9 eof { EOF } 67 / 73
68 : 1 calc lex.mll calc parse.ml Calc parse.plus 1 { 2 } 3 rule lex = parse 4 [ \t \n ] { lex lexbuf } 5 "+" { Calc_parse.PLUS } 6 "-" { Calc_parse.MINUS } 7 [ 0-9 ]+ as s { Calc_parse.NUM(int_of_string s) } 8 eof { Calc_parse.EOF } 68 / 73
69 : 2 : 1 $ menhir --external-tokens Calc_lex calc_parse.mly.mll.mly token 69 / 73
70 : 1, 1 1 $ ocamllex calc_lex.mll 2 $ menhir calc_parse.mly 3 # lex parse parse, lex 4 $ ocamlc -c calc_parse.mli calc_parse.ml calc_lex.ml 5 $ ocaml calc_parse.cmo calc_lex.cmo 6 OCaml version # Calc_parse.program;; 9 - : (Lexing.lexbuf -> Calc parse.token) -> Lexing.lexbuf -> int = <fun> 10 # Calc_lex.lex;; 11 - : Lexing.lexbuf -> Calc parse.token = <fun> 70 / 73
71 : 2 1 $ ocamllex calc_lex.mll 2 6 states, 267 transitions, table size 1104 bytes 3 # calc_parse.ml token calc_lex.ml 4 $ menhir --external-tokens Calc_lex calc_parse.mly 5 # lex, parse 6 $ ocamlc -c calc_lex.ml calc_parse.mli calc_parse.ml 7 $ ocaml calc_lex.cmo calc_parse.cmo 8 OCaml version # Calc_parse.program;; 11 - : (Lexing.lexbuf -> Calc lex.token) -> Lexing.lexbuf -> int = <fun> 12 # Calc_lex.lex;; 13 - : Lexing.lexbuf -> Calc lex.token = <fun> 71 / 73
72 ocamlbuild 1, 1 calc lex.mly calc parse.mll calc lex.byte calc parse.cmo 1 $ ocamlbuild -use-menhir calc lex.byte 2 /usr/bin/ocamllex -q calc_lex.mll 3 /usr/bin/ocamldep -modules calc_lex.ml > calc_lex.ml.depends 4 menhir --raw-depend --ocamldep /usr/bin/ocamldep -modules calc_parse.mly > calc_parse.mly.depends 5 menhir --ocamlc /usr/bin/ocamlc --infer calc_parse.mly 6 /usr/bin/ocamldep -modules calc_parse.mli > calc_parse.mli.depends 7 /usr/bin/ocamlc -c -o calc_parse.cmi calc_parse.mli 8 /usr/bin/ocamlc -c -o calc_lex.cmo calc_lex.ml 9 /usr/bin/ocamldep -modules calc_parse.ml > calc_parse.ml.depends 10 /usr/bin/ocamlc -c -o calc_parse.cmo calc_parse.ml 11 /usr/bin/ocamlc calc_parse.cmo calc_lex.cmo -o calc_lex.byte 12 $ ocaml -I _build _build/*.cmo 13 OCaml version # 72 / 73
73 ocamlbuild 2 calc parse.mly calc lex.mll calc parse.byte calc lex.cmo 1 $ ocamlbuild -use-menhir -yaccflags --external-tokens,calc lex calc parse.byte 2 menhir --raw-depend --ocamldep /usr/bin/ocamldep -modules calc_parse.mly > calc_parse.mly.depends 3 menhir --ocamlc /usr/bin/ocamlc --external-tokens Calc_lex --infer calc_parse.mly 4 /usr/bin/ocamldep -modules calc_parse.mli > calc_parse.mli.depends 5 /usr/bin/ocamllex -q calc_lex.mll 6 /usr/bin/ocamldep -modules calc_lex.ml > calc_lex.ml.depends 7 /usr/bin/ocamlc -c -o calc_lex.cmo calc_lex.ml 8 /usr/bin/ocamlc -c -o calc_parse.cmi calc_parse.mli 9 /usr/bin/ocamldep -modules calc_parse.ml > calc_parse.ml.depends 10 /usr/bin/ocamlc -c -o calc_parse.cmo calc_parse.ml 11 /usr/bin/ocamlc calc_lex.cmo calc_parse.cmo -o calc_parse.byte 12 $ ocaml -I _build _build/*.cmo 13 OCaml version # 73 / 73
: 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
ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1
More Logic More Types ML/OCaml GADT Jacques Garrigue ( ) Jacques Le Normand (Google) Didier Rémy (INRIA) @garriguejej ocamlgadt ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1 ( ) ML type nebou and
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
ML 演習 第 4 回
ML 演習第 4 回 おおいわ Mar 6, 2003 今回の内容 補足 Ocaml のモジュールシステム structure signature functor Ocaml コンパイラの利用 2 識別子について 利用可能文字 先頭文字 : A~Z, a~z, _ ( 小文字扱い ) 2 文字目以降 : A~Z, a~z, 0~9, _, 先頭の文字の case で 2 つに区別 小文字 : 変数,
# let rec sigma (f, n) = # if n = 0 then 0 else f n + sigma (f, n-1);; val sigma : (int -> int) * int -> int = <fun> sigma f n ( : * -> * ) sqsum cbsu
II 4 : 2001 11 7 keywords: 1 OCaml OCaml (first-class value) (higher-order function) 1.1 1 2 + 2 2 + + n 2 sqsum 1 3 + 2 3 + + n 3 cbsum # let rec sqsum n = # if n = 0 then 0 else n * n + sqsum (n - 1)
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)
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);}
# 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
1
0 1 2 OK NG 3 ID 4 CMS 5 CMS 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [PDF 7KB] [ ] 22 23 (HP ( pt) ) () ( 24 25 ( ) 26 27 28 29 #() URL # # 30 [PDF 7KB] [ ] 31 32 33 34 35 HTML HTML 36 37 38 39 40
Terminal ocaml $ ocaml Objective Caml version # 1+2;;<ret> # 1+2;; - : int = 3 ;; OCaml <ret> - : int = 3 OC
Jacques Garrigue, 2013 8 8-9 OCaml 1 OCaml OCaml ML ML Haskell ML Haskell ML 70 Edinburgh LCF Robin Milner 1 Caml ML OCaml OCaml OCaml-Nagoya OCaml 2007 in OCaml 2007 (Computer Science Library 3) 2007
Microsoft PowerPoint - 03BNFScanner-print.ppt
コンパイラ理論 3 BNF と EBNF の復習そして構文解析へ 3 章問題の把握ステップ 1 櫻井彰人 と文法 と EBNF 言語仕様 プログラムと言語仕様との関係 コンパイラ入門 C# で学ぶ理論と実践 より 3.2 BNF(Backus Naur Form) 文法 を記述する表記法 コンピュータ言語を表す為に使われることが多い 英文法 単語と単語の構成 関係を表す 5 文型は単語の品詞から英文の型を表現している
54 144 144 144 144 144 80 152 84 122 HTML
54 144 144 144 144 144 80 152 84 122 HTML P20 P24 P28 P40 P54 P84 P122 P138 P144 P152 P220 P234 P240 P242 1 1-1 1-2 1-3 1-4 1-5 1 1-6 1 2 2-1 2-2 A C D E F 2 G H I 2-3 2-4 C D E E A 2
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
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
Dive into Algebraic Effects
Dive into Algebraic Effects びしょ じょ ML Days #2 September 16, 2018 やること Algebraic Effects を伝道 Algebraic Effects is 何 Algebraic Effects が使える言語 Algebraic Effects の活用事例 研究のご紹介先日 JSSST でポスター発表した内容を紹介シマス 目次 自己紹介
文法と言語 ー文脈自由文法とLR構文解析2ー
文法と言語ー文脈自由文法とLR 構文解析 2 ー 和田俊和資料保存場所 http://vrl.sys.wakayama-u.ac.jp/~twada/syspro/ 前回までの復習 最右導出と上昇型構文解析 最右導出を前提とした場合, 上昇型の構文解析がしばしば用いられる. 上昇型構文解析では生成規則の右辺にマッチする部分を見つけ, それを左辺の非終端記号に置き換える 還元 (reduction)
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
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 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,
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
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 ---
200608094-101
94 A O D 1 A 1 A A 1 AO 1 95 A OA 1 a r A A 1 r A R 1 A R 1 A R 1 a a A OA R 1 96 F AO 1 A O 1 A 1 A O 1 A 1 O A 1 97 b O AO 1 O AO 1 A 1 A OA 1 AO 1 AA 1 98 A AO 1 A AO 1 b b 1 b b B B A 1 Q 1 rr 1 99
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
101NEO資料
Version 1.5 Tutorial PDF ... 1. PDF... 2 -.... 2 -. PDF... 2 -.... 4 -. HTML... 4 -. PDF... 5 -.... 7 -.... 8 Tutorial PDF Tutorial PDF - Page 1 Tutorial PDF - Page 2 Tutorial PDF - Page 3 Tutorial PDF
Ⅰ Report#1 Report#1 printf() /* Program : hello.c Student-ID : 095740C Author UpDate Comment */ #include int main(){ : Yuhi,TOMARI : 2009/04/28(Thu) : Used Easy Function printf() 10 printf("hello,
1 I EViews View Proc Freeze
EViews 2017 9 6 1 I EViews 4 1 5 2 10 3 13 4 16 4.1 View.......................................... 17 4.2 Proc.......................................... 22 4.3 Freeze & Name....................................
Emacs ML let start ::= exp (1) exp ::= (2) fn id exp (3) ::= (4) (5) ::= id (6) const (7) (exp) (8) let val id = exp in
Emacs, {l06050,sasano}@sic.shibaura-it.ac.jp Eclipse Visual Studio Standard ML Haskell Emacs 1 Eclipse Visual Studio variable not found LR(1) let Emacs Emacs Emacs Java Emacs JDEE [3] JDEE Emacs Java 2
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
Python Speed Learning
Python Speed Learning 1 / 76 Python 2 1 $ python 1 >>> 1 + 2 2 3 2 / 76 print : 1 print : ( ) 3 / 76 print : 1 print 1 2 print hello 3 print 1+2 4 print 7/3 5 print abs(-5*4) 4 / 76 print : 1 print 1 2
10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV
[email protected] [email protected] http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/sem3/ 2002 11 20 p.1/34 10/16 1. 10/23 2. 10/30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20
Page () &
() () Page () & Page 110kg 67kg 138kg Page Page Page Page, Page () (S3)(S1 (S2) (S1) (S2)(S1) (S3) (S1) (A2)(A1) (A3)(S1) (S3)(S1) (A2)(A1) (A3)(A1) (A3) (A1) (S2) (S1) Page () 10 () () () () () () ()
WebOS aplat WebOS WebOS 3 XML Yahoo!Pipes Popfry UNIX grep awk XML GUI WebOS GUI GUI 4 CUI
7 XML Week Web WebOS WebShell WebOS WebOS GUI WebOS WebOS 2 WebOS aplat WebOS WebOS 3 XML Yahoo!Pipes Popfry UNIX grep awk XML GUI WebOS GUI GUI 4 CUI CUI JavaScript I/O CommandClass WebShell webshell
Microsoft Word - Javacc.docx
JavaCC 実習レポート課題について以下の実習のために コンパイラのページ http://www.info.kindai.ac.jp/compiler/ から javacc.zip をダウンロードしてください javacc.zip は以下のファイルから成ります javacc/ sample0.k, sample1.k, samplell2.k : k 言語の例プログラム sample0.asm,
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) +
fp.gby
1 1 2 2 3 2 4 5 6 7 8 9 10 11 Haskell 12 13 Haskell 14 15 ( ) 16 ) 30 17 static 18 (IORef) 19 20 OK NG 21 Haskell (+) :: Num a => a -> a -> a sort :: Ord a => [a] -> [a] delete :: Eq a => a -> [a] -> [a]
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
2
1 2 2005 15 17 21 22 24 25 67 95 3 1 2 3 4 17 4 5 6 7 8 9 PR PR PR 10 11 12 PR 419 844 1,490 950 590 20 12 50 13 12/20 2/28 3/30 14 17 349 666 15 59 6 11 15 17 14 15 15 17 3,525,992 15 59 15 17 18 910
listings-ext
(6) Python (2) ( ) [email protected] 5 Python (2) 1 5.1 (statement)........................... 1 5.2 (scope)......................... 11 5.3 (subroutine).................... 14 5 Python (2) Python 5.1
LSM5Pascal Ver 3.2 GFP 4D Image VisArt Carl Zeiss Co.,Ltd.
LSM5Pascal Ver 3.2 GFP 4D Image VisArt 2004.03 LSM5PASCAL V3.2 LSM5PASCAL SW3.2Axiovert200M 1 1 2 3 3 4 4 5 SingleTrack 9 Multi Track 10,18 5 / 21 6 3 27 7 35 8 ( OFF) 40 LSM5PASCAL V3.2 LSM5PASCAL 65
haskell.gby
Haskell 1 2 3 Haskell ( ) 4 Haskell Lisper 5 Haskell = Haskell 6 Haskell Haskell... 7 qsort [8,2,5,1] [1,2,5,8] "Hello, " ++ "world!" "Hello, world!" 1 + 2 div 8 2 (+) 1 2 8 div 2 3 4 map even [1,2,3,4]
d-00
283-0105 298 TEL. 0475-76-0839 FAX. 0475-76-0838 400g 300 4950399167708 14 220g 300 4950399066780 Page 1 300g 200 4950399066766 100 400g 300 4950399167722 350g 160 4950399066735 100 600g 350 4950399167685
/ 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 [email protected] / SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming
損保ジャパンの現状2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 62 63 64 65 66 67 68 69
Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for
Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for embedded systems that use microcontrollers (MCUs)
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] { /*
26 2 3 4 5 8 9 6 7 2 3 4 5 2 6 7 3 8 9 3 0 4 2 4 3 4 4 5 6 5 7 6 2 2 A B C ABC 8 9 6 3 3 4 4 20 2 6 2 2 3 3 4 4 5 5 22 6 6 7 7 23 6 2 2 3 3 4 4 24 2 2 3 3 4 4 25 6 2 2 3 3 4 4 26 2 2 3 3 27 6 4 4 5 5
