Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This is a Java implementation of Thorsten Ball's Monkey Programming Language from his great book Writing An Interpreter in Go.

NotificationsYou must be signed in to change notification settings

leogtzr/monkeylangj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buildtests

This is a Java implementation of Thorsten Ball's Monkey Programming Language from his great bookWriting An Interpreter in Go.

Features

  • Tokenizer
  • Lexer
  • Parser
  • AST
  • Builtin Functions
  • if/else
  • Arrays & Maps
  • Function Literals
  • Closures
  • REPL ([Read Eval Print Loop](Read Eval Print Loop))

Examples

Precedence and Operators

5*5+10;3+4*5==3*1+4*5;5*10>40+5;((10+2)*30)==(300+20*3);(10+2)*30==300+20*3;500/2!=250;

Bool type

puts(true==true);puts(false==true);

if

if(5*5+10>34){puts(99)}else{puts(100)}
leta=5;letb=a>3;letc=a*99;if(b){10}else{1};letd=if(c>a){99}else{100};d*c*a;

String type

You can also see how function literals can be used.

lethello="Hello there, fellow Monkey users and fans!"letgiveMeHello=fn(){"Hello!"}giveMeHello();

Arrays

letmyArray=["one","two","three"];len(myArray);first(myArray);rest(myArray);last(myArray);push(myArray,"four")

Hash

letmyHash={"name":"Jimmy","age":72,"band":"Led Zeppelin"};myHash["name"];myHash["age"];myHash["band"];

Functions

lettwo="two";leth={"one":10-9,two:1+1,"thr"+"ee":6/2,4:4,true:5,false:6};h["one"];
letaddTwo=fn(x){x+2;};addTwo(2);letmultiply=fn(x,y){x*y};multiply(50/2,1*2);fn(x){x==10}(5);false;fn(x){x==10}(10);true;

Requirements

  • Java, this project uses the JDK 16.
  • Maven.

Build

To build the .jar file, just type:

$ make

or you could just run:

$ mvn clean package

Run

To run the REPL (Read Evaluate Print Loop):

make run

or:

java --enable-preview -jar target/monkeyj-jar-with-dependencies.jar

Running the examples

There are a few code examples of the language in theexamples directory. To run them, youcan use the following command:

$ java --enable-preview -jar target/monkeyj-jar-with-dependencies.jar< examples/strings/concat1.mnk

Donation / Sponsorship ❤️ 👍

This code was brought to you byLeo Gutiérrez in his free time. If you want to thank me and support the development of this project, please make a small donation onPayPal. In case you also like my other open source contributions and articles, please consider motivating me by becoming a sponsor/patron onPatreon. Thank you! ❤️

About

This is a Java implementation of Thorsten Ball's Monkey Programming Language from his great book Writing An Interpreter in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp