Programing > Part1.yaccˤJavascript

ĤäƤߤʤޤȤꤢϡyacc/bisonϥġ(kmyacc)ȤäJavascriptǤäˡܸץߥ󥰸Ȥޤǡɤ夭ΤǤ

Ūʤ

ץȸϡͤ¤ˤʤäƤ(Ϥ)

summary2.png

ץȸȤեȥϡɤȡ饤֥ϥǡȤ߹碌ơϷ̤ץࡣȤϡ礭ĤʬƤ롣Ϥϡɤʸڤʬ롣ʸϤϡ򥳥ԥ塼ʬ̿Ѵ롣ǡVM(Сޥ)¹Ԥ롣ΤϡꥢCPU¹Ԥ뤿ˡСޥǤϤʤޥѴƤɡǤϡCPUǽꡢCPUؤΰ¸ʤˡʤդˤʤäƤ롣

ǡץȸ뤿ˤϡΣ(ϡʸϡVM)ɬסϤϡȴñ(餷)ͭʪ򽦤äƤФʤȤʤ()VMϡ¾Υץߥ󥰸ǤäƤꡢ¾θ켫ΤVMȤƻȤȤ(Ĥޤꡢץߥ󥰸Υȥ󥹥졼Ѵˤ)ǡʸϤϡե񤯤ȡyaccưѴƹʸϥץäƤ롣

kmyaccΥץեǤäƤߤ

Ȥ櫓ǡץȸιʸϥץ뤿ˡyaccλȤǤФƤߤ뤫ʤǤϡkmyaccȤäơJavascriptäƤߤޤ

¹ԷǤ

Ȥꤢɡ

Ǥȥץե

kmyaccΥץեϡǤ˼ϿƤ롣顢¹ԷǤȤ⡢ǤꤷƤۤǤ

kmyaccǡɬפʤΤϰʲ

  • kmyacc.exe
  • cygwin1.dll
  • libե켰
  • calc.jsy(JavascriptΥץե롧Ǥ˼Ͽ)

ʤΤȤȡ3 + 4 * 5פȤȡݤ(*)Τۤ­(+)ꡢ̤ͥ⤤Ȥ褦˼꺢ˤʤ뤫顣ʤߤˡkmyaccJavascriptץˤϡϤΥɤޤޤƤ롣

Ѵ

Ǥϡkmyaccǡץե(calc.jsy)ºݤץѴޤWindowsΥޥɥ饤ǡΤ褦˼¹Ԥ롣

> kmyacc calc.jsy

ǡcalc.jsե뤬ޤ

ʤkmyaccϡեγĥҤ顢ʲΥ롼˽äƥۥȸꤷޤ

yaccĥۥȸϥեĥ
.yCy.tab.c
.jyJava.java
.jsyJavaScript.js
.plyPerl.pl

¹ԤƤߤ

Ρcalc.jsץեˤϡJavascriptʳˤ⡢ǤɬפʥɤȤhtmlȤ߹ޤƤΤǡcalc.htmlפȥե̾ѹƥ֥饦dzȡ׻Ǥޤȡ̤ͥ䥫åǧƤ롣

׻ˤϡε椬Ȥޤ

  • + ­
  • -
  • * ݤ
  • / 껻
  • (...) å˷׻

yaccեϡʴϡkmyaccΥץե뤽Τޤ(ѥ֥åɥᥤ)ʸˡϤhtmlեjavascriptޤޤƤޤ

ʤɤϡͤˤʤޤ

嵭ΥץɤơäƤߤޤ

եݡɵˡ

嵭Bison 1.28ޥ˥奢˵ܤƤ륵ץ륳ɤ򸵤ˤơեݡɵˡ(reverse polish notation)äƤߤ

㡧1 5 + 2 3 + *
> 30

ϡ(1+5)*(2+3)Ʊˤʤޤ

٤Ⱦ;ɲ

ǽΥץˡ٤(߾衧^)Ⱦ;(껻;ꡧ%)ɲá

2 ^ 3 => 8
7 % 2 => 1

ʣ

(٤Ⱦ;դ)ʣιԤƱ˷׻Ǥ褦ˤƤߤޤ

ꥢܥǡ׻ȷ׻̤äޤ

ѿդʣ

ˡѿȤ褦ˤƤߤ!

ѿ̾ˤϡƬȾѱѻ(a-zA-Z)2ʸܰʹߤȾѱѿ(a-zA-Z0-9)Ȥޤ

Ϥ⾯

a = 10
b = 20
a * b => 200

Ȥ߹ߴؿɲä

ޤȤ߹ߴؿɲäޤ

  • test()򤽤Τޤ֤
  • sqr()ʿ֤
  • rnd() ܤ֤

Ȥϡʴ

test(123) > 123
sqr(4) > 2
rnd(10) > 6.290423613972962

åˡͤǰĤ񤱤ޤ

2İʾΰδؿȤ߹ޤ(num1, num2)Ȥ(num1 num2)ȤäˡбƤʤǤ

ŪˤϡȤ߹ؿ̾᥽åɤȤƸƤӽФ褦ˤƤޤ


Part2.yaccˤWebץȸ³

ͻ


  ȥå   ʬ Хåå   ñ측 ǽ   إ   ǽRSS
źեե: filesummary2.png 1437 [ܺ]
Last-modified: 2014-07-20 () 22:12:50 (1702d)