Programing > Part1.yaccˤJavascript
ĤäƤߤʤޤȤꤢϡyacc/bisonϥġ(kmyacc)ȤäJavascriptǤäˡܸץߥȤޤǡɤ夭ΤǤ
ץȸϡͤ¤ˤʤäƤ(Ϥ)
ץȸȤեȥϡɤȡ饤֥ϥǡȤ߹碌ơϷ̤ץࡣȤϡ礭ĤʬƤ롣Ϥϡɤʸڤʬ롣ʸϤϡԥ塼ʬ̿Ѵ롣ǡVM(Сޥ)¹Ԥ롣ΤϡꥢCPU¹Ԥ뤿ˡСޥǤϤʤޥѴƤɡǤϡCPUǽꡢCPUؤΰ¸ʤˡʤդˤʤäƤ롣
ǡץȸ뤿ˤϡΣ(ϡʸϡVM)ɬסϤϡȴñ(餷)ͭʪäƤФʤȤʤ()VMϡ¾ΥץߥǤäƤꡢ¾θ켫ΤVMȤƻȤȤ(ĤޤꡢץߥΥȥ졼Ѵˤ)ǡʸϤϡեȡyaccưѴƹʸϥץäƤ롣
Ȥ櫓ǡץȸιʸϥץ뤿ˡyaccλȤǤФƤߤ뤫ʤǤϡkmyaccȤäơJavascriptäƤߤޤ
Ȥꤢɡ
kmyaccΥץեϡǤ˼ϿƤ롣顢¹ԷǤȤ⡢ǤꤷƤۤǤ
kmyaccǡɬפʤΤϰʲ
ʤΤȤȡ3 + 4 * 5פȤȡݤ(*)Τۤ(+)ꡢ̤ͥ⤤Ȥ褦˼꺢ˤʤ뤫顣ʤߤˡkmyaccJavascriptץˤϡϤΥɤޤޤƤ롣
Ǥϡkmyaccǡץե(calc.jsy)ºݤץѴޤWindowsΥޥɥ饤ǡΤ褦˼¹Ԥ롣
> kmyacc calc.jsy
ǡcalc.jsե뤬ޤ
ʤkmyaccϡեγĥҤ顢ʲΥ롼˽äƥۥȸꤷޤ
yaccĥ | ۥȸ | ϥեĥ |
.y | C | y.tab.c |
.jy | Java | .java |
.jsy | JavaScript | .js |
.ply | Perl | .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(123) > 123 sqr(4) > 2 rnd(10) > 6.290423613972962
åˡͤǰĤޤ
2İʾΰδؿȤ߹ޤ(num1, num2)Ȥ(num1 num2)ȤäˡбƤʤǤ
ŪˤϡȤ߹ؿ̾åɤȤƸƤӽФ褦ˤƤޤ