Symbol table accepts variables

This commit is contained in:
greg 2017-10-08 13:51:56 -07:00
parent 62edc7c996
commit 3f9ae5fac3
2 changed files with 40 additions and 11 deletions

View File

@ -392,7 +392,7 @@ macro_rules! expect {
#[derive(Debug, PartialEq)]
pub struct AST(pub Vec<Statement>);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum Statement {
ExpressionStatement(Expression),
Declaration(Declaration),
@ -403,7 +403,7 @@ type TypeName = Rc<String>;
type TraitName = Rc<String>;
type FormalParamList = Vec<(ParamName, Option<TypeName>)>;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum Declaration {
FuncDecl {
name: Rc<String>,
@ -423,20 +423,20 @@ pub enum Declaration {
},
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct TypeBody(pub Vec<Variant>);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum Variant {
Singleton(Rc<String>),
//ArgumentConstructor,
//Record
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Expression(pub ExpressionType, pub Option<TypeAnno>);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum TypeAnno {
Tuple(Vec<TypeAnno>),
Singleton {
@ -445,7 +445,7 @@ pub enum TypeAnno {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum ExpressionType {
IntLiteral(u64),
FloatLiteral(f64),
@ -467,16 +467,16 @@ pub enum ExpressionType {
MatchExpression(Box<Expression>, Vec<MatchArm>)
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct MatchArm {
pat: Pattern,
expr: Expression,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Pattern(Rc<String>);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Operation(pub Rc<String>);
impl Operation {

View File

@ -1,9 +1,14 @@
use std::collections::HashMap;
use std::rc::Rc;
use schala_lang::parsing::{AST, Statement, Declaration, Expression, ExpressionType, Operation, TypeAnno};
#[derive(Debug, PartialEq, Eq, Hash)]
struct PathSpecifier(String);
struct PathSpecifier {
name: Rc<String>,
kind: &'static str,
constant: bool,
}
struct SymbolTable {
map: HashMap<PathSpecifier, Expression>,
@ -15,6 +20,30 @@ impl SymbolTable {
}
fn add_symbols(&mut self, ast: &AST) {
use self::Declaration::*;
for statement in ast.0.iter() {
match statement {
&Statement::ExpressionStatement(_) => (),
&Statement::Declaration(ref d) => {
match d {
&FuncDecl { .. } => (),
&TypeDecl { .. } => (),
&TypeAlias { .. } => (),
&Binding {ref name, ref constant, ref expr} => {
let spec = PathSpecifier {
name: name.clone(),
kind: "binding",
constant: *constant
};
let binding_contents = (*expr).clone();
self.map.insert(spec, binding_contents);
},
&Impl { .. } => (),
}
}
}
}
}
}