0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vbsの作法 その100

Posted at

概要

vbsの作法、調べてみた。
練習問題やってみた。

練習問題

forthインタープリタを書け。
数9を4個つかって1から15までの数を表す式を実行せよ。

サンプルコード


function add()
	t0 = t1 + t0
	t1 = t2
end function

function mul()
	t0 = t1 * t0
	t1 = t2
end function

function subu()
	t0 = t1 - t0
	t1 = t2
end function

function div()
	t0 = t1 / t0
	t1 = t2
end function

function dup()
	t2 = t1
	t1 = t0
end function

function drop()
	t0 = t1
	t1 = t2
end function

function push(n)
	t2 = t1
	t1 = t0
	t0 = Cint(n)
end function

function print()
	WScript.StdOut.WriteLine t0
end function

function run(line)
	Dim s
	Dim m
	s = SPLIT(line, " ")
	For i = 0 To UBOUND(s)
		m = s(i)
		'msgbox m
		if m = "+" then
			add()
		elseif m = "*" then
			mul()
		elseif m = "-" then
			subu()
		elseif m = "/" then
			div()
		elseif m = "dup" then
			dup()
		elseif m = "drop" then
			drop()
		elseif m = "." then
			print()
		else
			push(m) 
		end if
	
	Next
end function

Dim t0
Dim t1
Dim t2
t0 = 0
t1 = 0
t3 = 0
run("9 9 - 9 9 / .")
run("9 9 / 9 9 / + .")
run("9 9 + 9 + 9 / .")
run("9 9 9 + 9 / dup + .")
run("9 9 9 + 9 / dup + - .")
run("9 dup 9 + 9 + 9 / - .")
run("9 9 9 + 9 / - .")
run("9 9 9 drop 9 / - .")  
run("9 9 - 9 * 9 + .")  
run("9 9 / 9 dup 9 / + .")  
run("9 9 9 + 9 / + .")  
run("9 dup 9 9 + + 9 / + .") 
run("9 9 9 + 9 / dup + + .")  
run("9 dup 9 9 + 9 / dup + - + .")  
run("9 dup dup 9 + 9 + 9 / - + .")  





>cscript forth.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?