LoginSignup
1
0

More than 3 years have passed since last update.

"Writing An Interpreter In Go " を JavaScriptで実装してみる その2 Parser

Posted at

Writing An Interpreter In Go " を JavaScriptで実装してみる その1 Lexer
に引き続き 夏休みの個人的課題を進めています
Writing An Interpreter In Goの103ページまで読み進めました
ほぼ動いてないけど(特定の構文は理解できず無限ループするようです^^;)
かなりバギー
[parser 部分のcode]
https://github.com/freddiefujiwara/saru/blob/master/src/parser.js

現時点のコードカバレッジ

-------------------------|----------|----------|----------|----------|-------------------|
File                     |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-------------------------|----------|----------|----------|----------|-------------------|
All files                |    96.02 |    82.38 |    95.24 |    95.95 |                   |
 block_statement.js      |      100 |       50 |      100 |      100 |                12 |
 boolean_literal.js      |      100 |        0 |      100 |      100 |                19 |
 call_expression.js      |       80 |        0 |       60 |    77.78 |              9,15 |
 expression.js           |      100 |      100 |      100 |      100 |                   |
 expression_statement.js |      100 |      100 |      100 |      100 |                   |
 function_literal.js     |      100 |        0 |      100 |      100 |                15 |
 identifier.js           |      100 |      100 |      100 |      100 |                   |
 if_expression.js        |    78.57 |       50 |       40 |    76.92 |          10,16,22 |
 infix_expression.js     |      100 |    16.67 |      100 |      100 |             28,33 |
 integer_literal.js      |      100 |      100 |      100 |      100 |                   |
 let_statement.js        |      100 |      100 |      100 |      100 |                   |
 lexer.js                |      100 |      100 |      100 |      100 |                   |
 node.js                 |      100 |      100 |      100 |      100 |                   |
 parser.js               |    93.75 |    83.91 |      100 |    93.75 |... 39,342,349,384 |
 prefix_expression.js    |      100 |        0 |      100 |      100 |                26 |
 program.js              |      100 |      100 |      100 |      100 |                   |
 return_statement.js     |      100 |      100 |      100 |      100 |                   |
 statement.js            |      100 |      100 |      100 |      100 |                   |
 token.js                |      100 |      100 |      100 |      100 |                   |
-------------------------|----------|----------|----------|----------|-------------------|   

インストール方法はこちら

npm i -g saru

新しい使い方はこちら

  $ saru
Hello fumikazu! This is the Monkey programming language!
Feel free to type in commands
* Please type 'bye' if you want to exit
>>>

こんな構文が理解できます

>>> 1 + 2 * 3
(1 + (2 * 3))
>>>
1 * 2 - 3
((1 * 2) - 3)
>>>
false == 1
(false == 1)

またLexerだけを使いたい場合は -l オプションつければLexerモードで起動します

  $ saru -l
Hello fumikazu! This is the Monkey programming language!
Feel free to type in commands
* Please type 'bye' if you want to exit
>>>

さて次はいよいよ Evaluation 18日までに終わるかな

1
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
1
0