티스토리 툴바

from 루비/Ruby로 만드는 기묘한 프로그래밍 언어 2011/04/21 23:14
function helloSyntaxHighlighter()
{
	return "hi!";
}
#coding:utf-8
require "pp"

class Brainf_ck
	class ProgramError < StandardError
	end

	def initialize(src)
		@tokens = src.chars.to_a
		@jumps = analyze_jumps(@tokens)
		pp @jumps
	end

	def run
		tape = []
		pc = 0
		cur = 0

		while pc < @tokens.size
			case @tokens[pc]
			when "덤"
				tape[cur] == nil ? tape[cur] = 1 : tape[cur] += 1
			when "빼"
				tape[cur] == nil ? tape[cur] = 0 : tape[cur] -= 1
			when "우"
				cur += 1
			when "좌"
				cur -= 1
				raise ProgramError, "시작인덱스가 최소치보다 작습니다." if cur < 0
			when "뿌"
				n = (tape[cur] || 0) # nil를 무시
				print n.chr
			when "쉬"
				tape[cur] = $stdin.getc.ord
			when "왼"
				pc = @jumps[pc] if tape[cur] == 0
			when "오"
				pc = @jumps[pc] if tape[cur] != 0
			end

			pc += 1
		end
	end

	private

	def analyze_jumps(tokens)
		jumps = {}
		starts = []

		tokens.each_with_index { |c,i|
			if c == "왼"
				starts.push(i)
			elsif c == "오"
				raise ProgramError, "오 가 더 많습니다." if starts.empty?
				from = starts.pop
				to = i
				jumps[from] = to
				jumps[to] = from
			end
		}

		jumps
	end
end

begin
	Brainf_ck.new(ARGF.read).run
rescue Brainf_ck::ProgramError
	puts "Brainf_ck ProgramError"
end
저작자 표시

Trackback Address >> http://gosoochaja.tistory.com/trackback/18 관련글 쓰기

댓글을 달아 주세요


: secret


from seasar 2011/02/18 12:37

http://d.hatena.ne.jp/basyura/20100924/p1



net.sourceforge.vrapper.vim.modes.InsertMode を編集

public boolean handleKey(KeyStroke stroke) {

if (stroke.equals(key(SpecialKey.ESC))) {
editorAdaptor.changeMode(NormalMode.NAME);
// ↓追加
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell().setImeInputMode(SWT.NULL);
return true;
} else if (!allowed(stroke)) {
저작자 표시

Trackback Address >> http://gosoochaja.tistory.com/trackback/17 관련글 쓰기

댓글을 달아 주세요


: secret


from seasar 2010/02/10 01:10
원문 :: http://hacks-web.blogspot.com/2009/11/ubuntugo.html

그냥 번역했습니다.

■ Ubuntu에서 GO Install 순서

vi .bashrc
# -------------------------------------
export GOROOT=$HOME/go
export GOBIN=$GOROOT/bin
export GOARCH=386
export GOOS=linux
export PATH=$PATH:$GOBIN
# -------------------------------------

source .bashrc

wget http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
# apt-get install python-setuptools 이걸로도 가능할지도 (공식홈페이지는 이쪽)
# debian 모르겠음

sudo apt-get update
sudo apt-get install python-dev

sudo easy_install mercurial
# 소스코드 다운
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
# 의존 라이브러리 인스톨
sudo apt-get install bison gcc libc6-dev ed make
cd $GOROOT/
mkdir bin
cd src
./all.bash

# 코드작성
vi hello.go
# -------------------------------------
package main
import "fmt"
func main() {
fmt.Printf("안녕하세요, 세계!")
}
# -------------------------------------
# X386계의 컴파일에서 컴파일
8g hello.go
# X386계의 링커에서 링커
8l hello.8
# 실행
./8.out
안녕하세요, 세계!


■ 참고URL
Ubuntu
http://babukuma.com/2009/11/ubuntugo.html

RedHat계
http://d.hatena.ne.jp/kidd-number5/20091111/1257939793
http://www.h-fj.com/blog/archives/2009/11/12-165449.php
저작자 표시

Trackback Address >> http://gosoochaja.tistory.com/trackback/16 관련글 쓰기

댓글을 달아 주세요


: secret