Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlaberge committed Dec 27, 2017
2 parents 01452f3 + 9b133c4 commit 483a9cd
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 228 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rascal"
version = "1.0.0"
version = "1.1.0"
authors = ["tylerlaberge <[email protected]>"]

[dependencies]
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 tylerlaberge

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 changes: 54 additions & 59 deletions src/analyzer/semantic_analyzer.rs

Large diffs are not rendered by default.

135 changes: 65 additions & 70 deletions src/interpreter/interpreter.rs

Large diffs are not rendered by default.

60 changes: 15 additions & 45 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#[derive(Debug, Clone, PartialEq)]
pub enum Program {
Program(Variable, Block)
}
pub struct Program(pub Variable, pub Block);

#[derive(Debug, Clone, PartialEq)]
pub enum Block {
Block(Vec<Declarations>, Compound)
}
pub struct Block(pub Vec<Declarations>, pub Compound);

#[derive(Debug, Clone, PartialEq)]
pub enum Declarations {
Expand All @@ -17,29 +13,19 @@ pub enum Declarations {
}

#[derive(Debug, Clone, PartialEq)]
pub enum ProcedureDeclaration {
Procedure(String, FormalParameterList, Block)
}
pub struct ProcedureDeclaration(pub String, pub FormalParameterList, pub Block);

#[derive(Debug, Clone, PartialEq)]
pub enum FunctionDeclaration {
Function(String, FormalParameterList, Block, TypeSpec)
}
pub struct FunctionDeclaration(pub String, pub FormalParameterList, pub Block, pub TypeSpec);

#[derive(Debug, Clone, PartialEq)]
pub enum FormalParameterList {
FormalParameters(Vec<FormalParameters>)
}
pub struct FormalParameterList(pub Vec<FormalParameters>);

#[derive(Debug, Clone, PartialEq)]
pub enum FormalParameters {
Parameters(Vec<String>, TypeSpec)
}
pub struct FormalParameters(pub Vec<String>, pub TypeSpec);

#[derive(Debug, Clone, PartialEq)]
pub enum VariableDeclaration {
Variables(Vec<String>, TypeSpec)
}
pub struct VariableDeclaration(pub Vec<String>, pub TypeSpec);

#[derive(Debug, Clone, PartialEq)]
pub enum TypeSpec {
Expand All @@ -51,9 +37,7 @@ pub enum TypeSpec {
}

#[derive(Debug, Clone, PartialEq)]
pub enum Compound {
Statements(Vec<Statement>)
}
pub struct Compound(pub Vec<Statement>);

#[derive(Debug, Clone, PartialEq)]
pub enum Statement {
Expand All @@ -64,9 +48,7 @@ pub enum Statement {
}

#[derive(Debug, Clone, PartialEq)]
pub enum Assignment {
Assign(Variable, Expr)
}
pub struct Assignment(pub Variable, pub Expr);

#[derive(Debug, Clone, PartialEq)]
pub enum IfStatement {
Expand All @@ -76,19 +58,13 @@ pub enum IfStatement {
}

#[derive(Debug, Clone, PartialEq)]
pub enum Variable {
Var(String)
}
pub struct Variable(pub String);

#[derive(Debug, Clone, PartialEq)]
pub enum FunctionCall {
Call(Variable, CallParameters)
}
pub struct FunctionCall(pub Variable, pub CallParameters);

#[derive(Debug, Clone, PartialEq)]
pub enum CallParameters {
Parameters(Vec<Expr>)
}
pub struct CallParameters(pub Vec<Expr>);

#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Expand All @@ -101,9 +77,7 @@ pub enum Expr {
}

#[derive(Debug, Clone, PartialEq)]
pub enum UnaryOpExpr {
UnaryOp(UnaryOperator, Expr)
}
pub struct UnaryOpExpr(pub UnaryOperator, pub Expr);

#[derive(Debug, Clone, PartialEq)]
pub enum UnaryOperator {
Expand All @@ -113,9 +87,7 @@ pub enum UnaryOperator {
}

#[derive(Debug, Clone, PartialEq)]
pub enum BinaryOpExpr {
BinaryOp(Expr, BinaryOperator, Expr)
}
pub struct BinaryOpExpr(pub Expr, pub BinaryOperator, pub Expr);

#[derive(Debug, Clone, PartialEq)]
pub enum BinaryOperator {
Expand All @@ -135,9 +107,7 @@ pub enum BinaryOperator {
}

#[derive(Debug, Clone, PartialEq)]
pub enum GroupedExpr {
Group(Expr)
}
pub struct GroupedExpr(pub Expr);

#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
Expand Down
10 changes: 5 additions & 5 deletions src/parser/parselet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl PrefixParselet {
fn grouping(&self, parser: &mut Parser, token: &Token) -> Result<GroupedExpr, String> {
return match token {
&Token::LPAREN => match (parser.expr(None)?, parser.lexer.next()) {
(expr, Some(Token::RPAREN)) => Ok(GroupedExpr::Group(expr)),
(expr, Some(Token::RPAREN)) => Ok(GroupedExpr(expr)),
(expr, _) => Err(String::from(format!("Grouping Parse Error: Expected token {:?} after {:?}", Token::RPAREN, expr)))
},
_ => Err(String::from(format!("Grouping Parse Error: Expected token {:?}", Token::LPAREN)))
Expand All @@ -64,7 +64,7 @@ impl PrefixParselet {

fn variable(&self, parser: &mut Parser, token: &Token) -> Result<Variable, String> {
return match token {
&Token::ID(ref name) => Ok(Variable::Var(name.clone())),
&Token::ID(ref name) => Ok(Variable(name.clone())),
_ => Err(String::from("Variable Parse Error: Expected token id"))
};
}
Expand All @@ -77,7 +77,7 @@ impl PrefixParselet {
_ => Err(String::from(format!("Unary Op Parse Error: Expected one of {:?}", vec![Token::PLUS, Token::MINUS, Token::NOT])))
}?;

return Ok(UnaryOpExpr::UnaryOp(operator, parser.expr(Some(self.get_precedence()))?));
return Ok(UnaryOpExpr(operator, parser.expr(Some(self.get_precedence()))?));
}
}

Expand Down Expand Up @@ -121,13 +121,13 @@ impl InfixParselet {
)
}?;

return Ok(BinaryOpExpr::BinaryOp(left.clone(), operator, parser.expr(Some(self.get_precedence()))?));
return Ok(BinaryOpExpr(left.clone(), operator, parser.expr(Some(self.get_precedence()))?));
}

fn function_call(&self, parser: &mut Parser, left: &Expr, token: &Token) -> Result<FunctionCall, String> {
return match (left, token) {
(&Expr::Variable(ref name), &Token::LPAREN) => match (parser.call_parameters()?, parser.lexer.next()) {
(parameters, Some(Token::RPAREN)) => Ok(FunctionCall::Call(name.clone(), parameters)),
(parameters, Some(Token::RPAREN)) => Ok(FunctionCall(name.clone(), parameters)),
(parameters, _) => Err(String::from(format!("Function Call Parse Error: Expected token {:?} after {:?}", Token::RPAREN, parameters)))
},
(_, _) => Err(String::from(format!("Function Call Parse Error: Expected variable token and {:?}", Token::LPAREN)))
Expand Down
Loading

0 comments on commit 483a9cd

Please sign in to comment.