valhallac

Compiler for set-theoretic programming language.
git clone git://git.knutsen.co/valhallac
Log | Files | Refs | README | LICENSE

commit b73354ec6147294a693bf08e5388741a8a16a9d7
parent 955bac5df7d4815b1161916d097df7fe7c96c297
Author: Demonstrandum <moi@knutsen.co>
Date:   Fri, 19 Jul 2019 16:11:14 +0100

Fixed binary op-check.

Diffstat:
M.gitignore | 2--
A.ideas/__MAIN.vh | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
A.ideas/subsets.vh | 3+++
Msrc/syntax/operators.rs | 8++++----
Msrc/syntax/parser.rs | 7+++++--
5 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -9,8 +9,6 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk -# Personal -.ideas/ # OS files .DS_Store diff --git a/.ideas/__MAIN.vh b/.ideas/__MAIN.vh @@ -0,0 +1,51 @@ +import :Prelude +import :puts from :IO as :put + +open Prelude + +div_by_three = [n : Nat => n mod 3 is 0] +div_by_five = [n : Nat => n mod 5 is 0] + +fizz : div_by_three -> String +fizz n = "Fizz" + +fizz : div_by_five -> String +fizz n = "Buzz" + +fizz : div_by_five | div_by_three -> String +fizz n = "FizzBuzz" + +# The order here doesn't matter, that's because if +# a number is part of both those sets, and neither set +# is a subset of eachother, it will give +# the number to the function that has a set that +# is a superset of both. If that function didn't exist, +# it would just run the first function. +# This is quite a unique scenario. + +map fizz 1..100 |> each puts + + +# Type declarations don't have to be directly over +# the implementation of the function. Only the order +# matters. + +int? : Real -> Boolean +int? : Int -> Boolean + +int? x = False +int? x = True + +# The function that it runs is the more specific one. +# (By specific I mean the function that has a domain +# that is a subset of the other functions domain.) + + +# Another way: + +is_int? : Real -> Boolean +is_int x = x <- Int + +# <- is read as "is element of ...?". It returns a bool. + + diff --git a/.ideas/subsets.vh b/.ideas/subsets.vh @@ -0,0 +1,3 @@ +subset I Int + +(n, m) : I^2 diff --git a/src/syntax/operators.rs b/src/syntax/operators.rs @@ -99,9 +99,9 @@ impl PrecedenceTable { op( "if", 20, Side::Neither, 2), op("unless", 20, Side::Neither, 2), op( ",", 10, Side::Right, 2), - op( "=>", 1, Side::Neither, 2), - op( "(", 0, Side::Neither, 1), - op( ")", 0, Side::Neither, 1), + op( "=>", 1, Side::Neither, 2), + op( "(", 0, Side::Neither, 1), + op( ")", 0, Side::Neither, 1), ]}; table @@ -122,7 +122,7 @@ impl PrecedenceTable { } pub fn exists(&self, name : &str) -> bool { - self.table.iter().filter(|o| o.name == name).next().is_some() + self.table.iter().filter(|o| o.name == name).nth(0).is_some() } pub fn precedence(&self, name : &str) -> Option<i32> { diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs @@ -74,9 +74,12 @@ impl ParseEnvironment { let popped = &self.stream.remove(0); let mut left = self.null_den(popped); - if self.stream.is_empty() { return left; } + if self.stream.is_empty() + || self.stream[0].class == TokenType::EOF + || self.stream[0].class == TokenType::Term + { return left; } - if self.optable.exists(&self.stream[0].string) { + if !self.optable.exists(&self.stream[0].string) { return issue!(err::Types::ParseError, self.file, &self.stream[0], "`{}` is not a binary operator.", &self.stream[0].string); }