Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/speed1313/monkey-repl

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/speed1313/monkey-repl

  • v0.0.0-20220824032946-0081a25fb94e
  • Source
  • Go
  • Socket score

Version published
Created
Source

monkey-repl

this is a toy interpreter for lerning.

Note

Lexer

Lexer reads the source code and returns the token sequense. Lexer is easy to implement because it simply converts words into tokens one by one, ignoring white space.

  • attention Sometimes you have to look at the next character, like == and =.

Parser

Parser reads token sequenses and construct the AST. AST is the data structure that represents the source code. While reading, parser checks if the token sequense is valid. If the current token or the next token is the same as the expected token, then the parser can step forward.

expression

parsing expression is difficult because expression has priority.

Pratt syntax parser

Points of Parser

  • If an infinite loop occurs, it may be because next() is not called

  • the important point is that the parser is able to step forward if the current token or the next token is valid. To check this, expect(), that check if the next token is expected and step forward is used.

Evaluator

parserから生成されたASTを, 上から再帰的に評価していく. eval(node)は評価した値を返し, 親nodeは子ノードの評価値を用いて新たに値を計算して返す.

束縛と環境

letによる変数への値の束縛は, 環境によって実現される. 環境は変数名と値をmapのラッパーで保存するもの.

文字列や配列など

goのデータ型をラップする形で表現すればできる.

FAQs

Package last updated on 24 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc