Commit Graph

657 Commits

Author SHA1 Message Date
greg
71aef379d3 Tokenize number literals
TODO: expand this bit of code to handle 0x12, etc. syntax
2017-09-19 22:10:54 -07:00
greg
8662a3ba0e Make tokenize error-able 2017-09-19 22:10:54 -07:00
greg
5ca98c7d77 Print tokeniziation 2017-09-19 22:10:54 -07:00
greg
13cde3106c Start making tokenizer changes
Hopefully this time iron out all the bugs from the last implementation
2017-09-19 22:10:54 -07:00
greg
09d524c74a Changing how parsing works again
Someone wrote a port of the LLVM kaleidoscope tutorial to rust, namely
https://github.com/jauhien/iron-kaleidoscope

I'm just gonna follow this along
2017-09-19 22:10:54 -07:00
greg
61c36c4def Fix assign parsing
= is a keyword not an identifier
2017-09-19 22:10:54 -07:00
greg
bc4fbe4276 Start implementing definition
WIP, doesn't work
2017-09-19 22:10:54 -07:00
greg
fc11ee753d Add block parsing
Right now evaluating a block reduces it to just the last AST in it, will
fix later with environments
2017-09-19 22:10:54 -07:00
greg
dd2b4893a4 Get rid of Separator token
Have separate newline and semicolon tokens
2017-09-19 22:10:54 -07:00
greg
51745fd800 Make convenience macro for parse errors 2017-09-19 22:10:54 -07:00
greg
8c0ac19fa8 Add full test
Test evaluate, tokenize, parser all at once
2017-09-19 22:10:54 -07:00
greg
971ab9ba21 Implement paren expressions 2017-09-19 22:10:54 -07:00
greg
819fb3f58f Basic evaluator functionality
Interpreter now works for simple arithmetic expressions
2017-09-19 22:10:54 -07:00
greg
1c23329656 Add boilerplate for evaluation
Just wires everything up, doesn't actually evaluate yet
2017-09-19 22:10:54 -07:00
greg
6da20cbfaf Address compiler warnings 2017-09-19 22:10:54 -07:00
greg
f48451125e Parsing arithmetic expressions works
At the expense of an unnecessary move in lookahead()
2017-09-19 22:10:54 -07:00
greg
06c3999430 Add expect_identifier function
For utility
2017-09-19 22:10:54 -07:00
greg
1af1589550 Make Parser class internally use IntoIterator
And wrap the next() and peek() methods
2017-09-19 22:10:54 -07:00
greg
32a90b8103 write expect
and also make the ParseResult type more general so it can be used for
more things.
2017-09-19 22:10:54 -07:00
greg
186c900920 Implement expect macro
Seems like there's no way around passing in self manually
2017-09-19 22:10:54 -07:00
greg
509ab80b9c I can now parse one thing 2017-09-19 22:10:54 -07:00
greg
247638c4db Get parsing REPL working 2017-09-19 22:10:54 -07:00
greg
be98f8387e Add another test 2017-09-19 22:10:54 -07:00
greg
841b38d5b1 Add tokenization test 2017-09-19 22:10:53 -07:00
greg
16dfbb27d5 Use state features from simplerepl 2017-09-19 22:10:53 -07:00
greg
3af7e6a409 Refactoring Schala
Gonna work on Schala in earnest now! Using the simplerepl crate instead
of a build-in REPL, temporarily dropping parsing and evaluation code.
2017-09-19 22:10:53 -07:00
greg
123f388711 Rename language to "Schala" 2017-09-19 22:10:53 -07:00
greg
bb349cda5f Fix newline tokenizing bug
Still need to fix <statements> parsing because of the final newline
2017-09-19 22:10:53 -07:00
greg
caa331ecdc Read from file as well as repl 2017-09-19 22:10:53 -07:00
greg
ae3a030ad8 Use iterative semantics for reduction
Becuase if you try to make reduce() recursive you blow out the stack.

Incidentally, "let a = 0; while a < 999999; let a = a + 1 end" is a neat
thing to try at this stage of the game
2017-09-19 22:10:53 -07:00
greg
ddb09b453d Implement booleans 2017-09-19 22:10:53 -07:00
greg
9a4760d44f Implement while-reduction 2017-09-19 22:10:53 -07:00
greg
eb5ce2ef9e Don't print newline for empty REPL result 2017-09-19 22:10:53 -07:00
greg
b080ea7c81 Add if-statement evaluation 2017-09-19 22:10:53 -07:00
greg
dffab8ae94 Fixed arg list parsing 2017-09-19 22:10:53 -07:00
greg
48ee6c9a75 Add function name to parse 2017-09-19 22:10:53 -07:00
greg
58d399dace More function parsing 2017-09-19 22:10:53 -07:00
greg
57ea1bae30 Preliminary addition of function blocks 2017-09-19 22:10:53 -07:00
greg
e870d8172a Make = a keyword 2017-09-19 22:10:53 -07:00
greg
72b26755a7 Make ParseResult just a normal Result type
No reason for it to be different
2017-09-19 22:10:53 -07:00
greg
1416c9d444 Parse null as simple_expression 2017-09-19 22:10:53 -07:00
greg
5c79563e53 Reduce binop args before reducing full expr 2017-09-19 22:10:53 -07:00
greg
c27c900e7f Add operators % and **
semantics for these are hard with floats handle later
2017-09-19 22:10:53 -07:00
greg
50c5dbe96d Evaluate simple binops
Woo this is kind of a neat milestone! I can now compute with this
language!
2017-09-19 22:10:53 -07:00
greg
be8c8b3343 Add paren test 2017-09-19 22:10:53 -07:00
greg
b856023072 Fixed paren parsing
also made error reporting a bit nicer
2017-09-19 22:10:53 -07:00
greg
868373f409 use match syntax in simple_parse 2017-09-19 22:10:53 -07:00
greg
582a7fd6dc Make parse and tokens optional 2017-09-19 22:10:53 -07:00
greg
a947ec3cb2 Add simple parsing test 2017-09-19 22:10:53 -07:00
greg
79619025ea Add directive to print precedence chart 2017-09-19 22:10:53 -07:00