Commit Graph

59 Commits

Author SHA1 Message Date
40de215f70 Built-in functions:
len() added

git-svn-id: https://svn.tlawal.org/svn/monkey@59 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-11-11 20:30:15 +00:00
b028741d75 - String Concatenation is now possible.
- Added test to ensure only '+' will work for concatenating strings
- Likkle reformatting.


git-svn-id: https://svn.tlawal.org/svn/monkey@58 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-11-03 15:01:40 +00:00
2c2c936b29 String Implementation is done. Still has TODO that would make for good excercise.
git-svn-id: https://svn.tlawal.org/svn/monkey@57 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-11-03 14:23:07 +00:00
2791a27f1f Built-in datatypes: Added String
The parser now understands what a strings is and can take a string literal and curn out an Stringliteral AST
nodes.



git-svn-id: https://svn.tlawal.org/svn/monkey@56 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-11-03 11:11:42 +00:00
05d2c32b38 Formatting.
Monk also supports first-class functions


git-svn-id: https://svn.tlawal.org/svn/monkey@55 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-26 19:01:31 +00:00
cdf36e8211 Monk now fully supports Functions, Function calls and closures.
git-svn-id: https://svn.tlawal.org/svn/monkey@54 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-26 19:00:32 +00:00
6f00316b43 Typo
git-svn-id: https://svn.tlawal.org/svn/monkey@53 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-19 07:49:24 +00:00
7fcea2117f Implemented environments which is just a hash map to keep track of values in the language.
git-svn-id: https://svn.tlawal.org/svn/monkey@52 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-19 07:18:37 +00:00
d38f4dec8a Tests
- Ensure value producing expression in a let statement and also identifiers bound to a 
variable name.
- Tests to ensure valid errors with unbound identifiers

git-svn-id: https://svn.tlawal.org/svn/monkey@51 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-18 14:32:13 +00:00
44612f0756 Error handling
git-svn-id: https://svn.tlawal.org/svn/monkey@50 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-11 06:55:07 +00:00
5456f60038 Infix Expression, Prefix Expression, Return Statement.
git-svn-id: https://svn.tlawal.org/svn/monkey@49 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-11 05:04:44 +00:00
ec01fd1a31 Turn off parser tracing
git-svn-id: https://svn.tlawal.org/svn/monkey@48 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-08 11:35:06 +00:00
a170eb4450 Infix evaluation operation now supported.
git-svn-id: https://svn.tlawal.org/svn/monkey@47 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-08 11:01:32 +00:00
4b67c7d6e1 Implement the "!" evaluation operator
git-svn-id: https://svn.tlawal.org/svn/monkey@46 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-08 10:14:14 +00:00
886a16e706 Spelling corrections
Interpreter can now evaluate Booleans

git-svn-id: https://svn.tlawal.org/svn/monkey@45 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-07 14:58:35 +00:00
1b97196361 Evaluation - Integer evaluation now works, got basically a REPL going on.
git-svn-id: https://svn.tlawal.org/svn/monkey@44 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-07 14:44:11 +00:00
7a319dc03b not needed, at least for now
git-svn-id: https://svn.tlawal.org/svn/monkey@43 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-07 14:43:06 +00:00
97059abeee Added tracing.
git-svn-id: https://svn.tlawal.org/svn/monkey@42 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-01 16:27:33 +00:00
3b013cd917 Formatting changes.
REPL can now use the parser.

NOTE: REPL currently outputs the parsed tokens because tracing is still turned on.

git-svn-id: https://svn.tlawal.org/svn/monkey@41 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-01 16:13:40 +00:00
e5d2851c2e Remove TODO's
git-svn-id: https://svn.tlawal.org/svn/monkey@40 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-01 05:26:02 +00:00
7e34164019 CallExpression ast, parser and tests completed.
git-svn-id: https://svn.tlawal.org/svn/monkey@39 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-08-01 04:58:28 +00:00
c421b040d5 Can now parse FunctionLiteral and its parameters. Tests are also included.
git-svn-id: https://svn.tlawal.org/svn/monkey@38 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-31 23:31:43 +00:00
c1d53c5101 git-svn-id: https://svn.tlawal.org/svn/monkey@37 f6afcba9-9ef1-4bdd-9b72-7484f5705bac 2022-07-31 21:57:20 +00:00
1ac48b0cad Test for IfExpressions, and IfElseExpression
git-svn-id: https://svn.tlawal.org/svn/monkey@36 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-31 21:55:09 +00:00
5d1197160d Improved code readability.
Added IfExpressions, BlockStatements, and FunctionLiterals

git-svn-id: https://svn.tlawal.org/svn/monkey@35 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-31 21:44:35 +00:00
a4b75cf9c2 Changes:
- Parsing grouped expressions is now possible
- formatting

git-svn-id: https://svn.tlawal.org/svn/monkey@34 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-14 12:23:22 +00:00
388700441e Changes:
- Added helper functions to test BooleanLiterals
- Formatting

git-svn-id: https://svn.tlawal.org/svn/monkey@33 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-14 12:12:56 +00:00
628a604701 Changes:
- Boolean expression can now be parsed. 
- Formatting

git-svn-id: https://svn.tlawal.org/svn/monkey@32 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-14 07:26:34 +00:00
6597024fff Helper functions to make testing the AST easier and cleaner.
git-svn-id: https://svn.tlawal.org/svn/monkey@31 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-07-14 06:54:26 +00:00
73eeb2001e git-svn-id: https://svn.tlawal.org/svn/monkey@30 f6afcba9-9ef1-4bdd-9b72-7484f5705bac 2022-07-14 06:24:50 +00:00
d1863830af Test helpers should be at the bottom.
git-svn-id: https://svn.tlawal.org/svn/monkey@29 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-06-12 14:50:08 +00:00
2fa35abbc3 add readme
git-svn-id: https://svn.tlawal.org/svn/monkey@28 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-06-01 14:27:07 +00:00
dd030ebd4b This allows tracing information to be displayed. STRICTLY FOR TESTING ONLY, SHOULD BE TURNED OFF IN THE
ACTUAL INTERPRETER.


git-svn-id: https://svn.tlawal.org/svn/monkey@27 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-06-01 14:20:16 +00:00
982efec3d0 - Formatting.
- Tracing information now displayed to better visualize how the program works.


git-svn-id: https://svn.tlawal.org/svn/monkey@26 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-31 17:38:50 +00:00
e5d95dc7b6 - Infix operator parsing is now possible.
git-svn-id: https://svn.tlawal.org/svn/monkey@25 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-31 15:01:43 +00:00
2253d6b02c Parsing prefix expressions, tests passes
git-svn-id: https://svn.tlawal.org/svn/monkey@24 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-31 11:32:43 +00:00
45f6929c14 Started implementing Pratt Parsing, tests now pass that can generate on Infix and Integer expressions.
git-svn-id: https://svn.tlawal.org/svn/monkey@23 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-30 17:40:03 +00:00
e456189c86 ExpressionStatement in the AST to represent the typse of expressions that is supported in monkey.
Hand written test in the AST to test the String() function for accuracy



git-svn-id: https://svn.tlawal.org/svn/monkey@22 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-30 05:51:27 +00:00
fdf6a8a552 - Some minor formatting.
- Parser can now handle return statements.

git-svn-id: https://svn.tlawal.org/svn/monkey@21 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-27 15:07:19 +00:00
58f6bab88f Clarity.
git-svn-id: https://svn.tlawal.org/svn/monkey@20 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-26 19:25:31 +00:00
145d61ba57 - The parser can now check for errors.
- The test now handles checking for errors.

git-svn-id: https://svn.tlawal.org/svn/monkey@19 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-26 19:23:01 +00:00
4a3edec5e6 git-svn-id: https://svn.tlawal.org/svn/monkey@18 f6afcba9-9ef1-4bdd-9b72-7484f5705bac 2022-05-26 19:20:51 +00:00
2e18493a4a Test now passes, wonder what I did wrong.
git-svn-id: https://svn.tlawal.org/svn/monkey@17 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-26 17:19:15 +00:00
b8e8fc8b6e Stubborn bug, could not figure out what causing it. Will just re-write the entire thing.
```panic: runtime error: invalid memory address or nil pointer dereference [recovered] 
        panic: runtime error: invalid memory address or nil pointer dereference     
[signal 0xc0000005 code=0x0 addr=0x10 pc=0xbcf660]                                  
                                                                                    
goroutine 6 [running]:                                                              
testing.tRunner.func1.2({0xbe4c60, 0xce2c10})                                       
        C:/Program Files/Go/src/testing/testing.go:1389 +0x24e                      
testing.tRunner.func1()                                                             
        C:/Program Files/Go/src/testing/testing.go:1392 +0x39f                      
panic({0xbe4c60, 0xce2c10})                                                         
        C:/Program Files/Go/src/runtime/panic.go:838 +0x207                         
monkey/ast.(*LetStatement).TokenLiteral(0xc000022940?)                              
        D:/monkey/ast/ast.go:37                                                     
monkey/parser.testLetStatement(0xc000132000, {0xc32638, 0x0}, {0xc0106a, 0x1})      
        D:/monkey/parser/parser_test.go:43 +0x49                                    
monkey/parser.TestLetStatements(0xc000132000)                                       
        D:/monkey/parser/parser_test.go:36 +0x1ba                                   
testing.tRunner(0xc000132000, 0xc0d940)                                             
        C:/Program Files/Go/src/testing/testing.go:1439 +0x102                      
created by testing.(*T).Run                                                         
        C:/Program Files/Go/src/testing/testing.go:1486 +0x35f                      
FAIL    monkey/parser   0.180s                                                      
FAIL
```

git-svn-id: https://svn.tlawal.org/svn/monkey@16 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-26 16:35:08 +00:00
4f90d0cbd1 Formatting
git-svn-id: https://svn.tlawal.org/svn/monkey@15 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-26 16:33:09 +00:00
c7dbccbe71 Basic structure of the parser, I now understand what is going on. I think ¯\_(?)_/¯
git-svn-id: https://svn.tlawal.org/svn/monkey@14 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-24 17:05:02 +00:00
b78944e3d7 Typo
git-svn-id: https://svn.tlawal.org/svn/monkey@13 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-23 17:35:55 +00:00
4691f6c3e5 Basic AST to represent expressions, statement, identifiers
I now understand how it works.

git-svn-id: https://svn.tlawal.org/svn/monkey@12 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-23 14:26:34 +00:00
d37bdfa644 Don't understand how it works.
git-svn-id: https://svn.tlawal.org/svn/monkey@11 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-23 14:25:45 +00:00
f8f7ec04c7 Basic AST to represent expressions, statement, identifiers
I now understand how it works.

git-svn-id: https://svn.tlawal.org/svn/monkey@10 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-23 14:24:35 +00:00