LoginSignup
13

More than 5 years have passed since last update.

TrumpScriptでHello World

Last updated at Posted at 2016-01-24

TrumpScriptとは

HackRiceというハッカソンで作られたプログラミング言語らしい。アメリカ大統領選挙候補のトランプ氏っぽさをイメージしているそうだ。

公式

面白そうなので遊んでみることにした。
試した環境:OS X 10.11

特徴

  • No floating point numbers, only integers. America never does anything halfway.
  • All numbers must be strictly greater than 1 million. The small stuff is inconsequential to us.
  • There are no import statements allowed. All code has to be home-grown and American made.
  • Instead of True and False, we have fact and lie.
  • Only the most popular English words, Trump's favorite words, and current politician names can be used as variable names.
  • Error messages are mostly quotes directly taken from Trump himself.
  • All programs must end with America is great.
  • Our language will automatically correct Forbes' $4.5B to $10B.
  • In its raw form, TrumpScript is not compatible with Windows, because Trump isn't the type of guy to believe in PC.
  • The language is completely case insensitive.
  • If the running computer is from China or Mexico, TrumpScript will not compile. We don't want them stealing our American technological secrets.
  • Warns you if you have any Communists masqeurading as legitimate "SSL Certificates" from China on your system.
  • Won't run in root mode because America doesn't need your help being great. Trump is all we need.
  • 浮動小数点型は使えない。整数のみ。アメリカは半端なことはしないから。
  • 全ての数値は100万より大きくなくてはならない。小さいことはどうでもいいのだ。
  • importは使えない。コードは全て自家製、アメリカ製でなければならない。
  • True,Falseの代わりにはfact,lieを使う。
  • 変数名に使えるのは最も一般的な英単語、トランプ氏の好きな単語、現在の政治家の名前のみ。
  • エラーメッセージはトランプ氏自身の言葉からの引用。
  • 全てのプログラムはAmerica is greatで終わらなければならない。
  • 45億は自動的に100億に修正される。
  • そのままの状態ではWindowsでは動かない。なぜならトランプ氏はPCを気にするような人ではないから。(politically correct と windows PCをかけているらしい)
  • 大文字と小文字は区別されない。
  • 中国やメキシコからTrumpScriptを実行してもコンパイルされない。それらの国にアメリカの技術的な秘密事項を盗まれたくはないから。
  • 中国製のSSL証明書(共産主義のなりすまし)がコンピューターにあると警告される。
  • root権限では動かない。アメリカがサイコーになるにはトランプ氏だけで十分だ。

文法

The grammar of the language is fairly convoluted, but here's a taste of the enlightened decisions we've made.

Arithmetic operators:

  • + and plus do addition
  • - and minus do subtraction
  • * and times do multiplication
  • / and over do division
  • <, less, fewer, and smaller all evaluate to 'less than'
  • >, more, greater, and larger all evaluate to 'greater than'

Control flow:

  • Use , and ; to treat compound statements as a single evaluation, similar to how () are used in other languages
  • Use : and ! to define the scope of loops and if statements, similar to how {} is used in Java
  • if, else if, and else do what you think they do
  • not, and, and or do what you expect

The exciting parts:

  • Strings are denoted by double quotes ("I love Trump")
  • The is and are keywords are used both to check for equality, and for assignment. To use for assignment, say something like Trump is great or Democrats are dumb. To use to check for equality, do the same but append a ?. For example, you may need to ask yourself Trump is "the best"? (although we all know that would evaluate to fact anyway)
  • Assignment can also be done via the make keyword. E.g. Make America great assigns the value of the variable great to America
  • Printing to stdout can be done via tell or say
  • While loops are denoted via as long as. And that's the only type of loop you need anyway
  • If a 'word' (so anything that could be a variable name) is deemed unnecessary by the compiler, it's simply thrown away. So you can make truly self documenting code, or code that appear to read very very similarly to real speeches by the big man himself. You can find some interesting examples in our test/test_files directory

But most importantly, Trump doesn't like to talk about his failures. So a lot of the time your code will fail, and it will do so silently. Just think of debugging as a fun little game.

  • +plusで加算
  • -minusで減算
  • *timesで乗算
  • /overで除算
  • <,less,fewer,smallerは全て同じ意味
  • >,more,greater,largerは全て同じ意味
  • ,;で式をはさんで評価する
  • :!でブロックをつくる
  • if,else if,else,not,and,orは文字通りに使える
  • 文字列は"で囲う
  • is,areは式が同じ値かどうかをチェックするキーワード。式を評価するには、最後に?を追加する
  • makeで変数に値を代入できる
  • 標準出力はtellsay
  • whileループはas long as
  • 余計な単語は全て無視される ※ただしallowed_words.pyに入っていない単語を使用すると怒られる

インストール

bash
git clone https://github.com/samshadwell/TrumpScript.git

pathを編集する。

`~/.bash_profile`
# パスを適当に書き換えて追記する
export PATH=$PATH:/path/to/TrumpScript/bin

ターミナルを再起動して確認

bash
$ which TRUMP
/path/to/TrumpScript/bin/TRUMP

遊んでみる

ファイルの拡張子は.txtでいいっぽい。

Hello,Trump!

hello_trump.txt
tell "Hello,Trump!"
America is great.
bash
$ TRUMP hello_trump.txt
Compiled, starting execution
-------------------

hello,trump!

できた。

計算

2012年のアメリカの歳入は約2兆4650億ドルらしい。また2012年の軍事費は6820億ドルくらい。

america.txt
make budget 2465000000000
make army    680000000000

make result ,army  / budget;
tell result
America is great.
bash
$ TRUMP america.txt 
Compiled, starting execution
-------------------

0

make budget 2465000000000で変数budgetに2465000000000を代入する。
小数は切り捨てられて0になってしまった模様。

america.txt
make budget 2465000000000
make army    680000000000

make result ,army  / budget * 100;
tell result
America is great.
bash
$ TRUMP america.txt 
Parsing error:
What are you doing on line 4?
.
.
.
trumpscript.utils.SystemException: I'm really rich.

ああもうヽ(`Д´)ノ
100だと小さすぎるのでトランプ氏がお怒りのようです。

if

if.txt
make trump "the best"
if, Trump is "the best"?; :
    say "America is Awesome!"
!
America is great.
bash
$ TRUMP if.txt 
Compiled, starting execution
-------------------

america is awesome!

:!でブロックを作る。

余計な単語は無視される

speech.txt
if ,yes we can was fact; :
  say "日本語も出力できる"!
America is great.
bash
$ TRUMP speech.txt 
Compiled, starting execution
-------------------

日本語も出力できる

yesとかweとかは無視されるので実質if , fact; :と同じ?
ただし何でもかんでも余計な単語が無視されるのではなく、allowed_words.pyにない単語が含まれているとトランプ氏に怒られる。

""内の文字列に関してはトランプ氏も大目に見てくれるようだ。

まとめ

America is great.

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
13