Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e0a057

Browse files
committed
Implements binding time analysis
1 parent 60a96e1 commit 8e0a057

File tree

8 files changed

+213
-91
lines changed

8 files changed

+213
-91
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "group3"
2+
name = "spl-compiler"
33
version = "0.1.0"
44
edition = "2021"
55

@@ -11,3 +11,5 @@ regex = "1.5.4"
1111
nom = "^7.1.0"
1212
num-bigint = "^0.4.3"
1313
pretty-trait="0.1.2"
14+
log = { version = "0.4" }
15+
simple_logger = { version = "2.1.0", default-features = false }

examples/binding_time_analysis.spl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var f = 123;
2+
3+
f(f) {
4+
var f = 3;
5+
var f = True;
6+
return f;
7+
}

examples/fun_glob_var_unique.spl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var x = 1;
2+
3+
// Disallowed
4+
// var x = 2;
5+
6+
id(a) {
7+
return a;
8+
}
9+
10+
// Disallowed
11+
//id(a) {
12+
// return a;
13+
//}

examples/var_decl_in_statement.spl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
f(a) {
2+
if (a) {
3+
var b = a;
4+
} else {
5+
var b = !a;
6+
}
7+
}

src/ast/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod pp;
22

33
use num_bigint::BigUint;
44

5+
use std::fmt;
56
use std::ops::{Deref, DerefMut};
67

78
#[derive(PartialEq, Debug)]
@@ -29,6 +30,12 @@ pub enum Decl {
2930
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3031
pub struct Id(pub String);
3132

33+
impl fmt::Display for Id {
34+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35+
write!(f, "{}", self.0)
36+
}
37+
}
38+
3239
impl From<String> for Id {
3340
fn from(s: String) -> Self {
3441
Self(s)

src/main.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
use group3::ast::pp::PrettyPrintable;
2-
use group3::parser::*;
3-
use group3::scanner::Scanner;
4-
use group3::tc::*;
5-
use group3::token::{Token, Tokens};
1+
use spl_compiler::ast::pp::PrettyPrintable;
2+
use spl_compiler::parser::*;
3+
use spl_compiler::scanner::Scanner;
4+
use spl_compiler::tc::*;
5+
use spl_compiler::token::{Token, Tokens};
66

77
use pretty_trait::to_string;
88

9+
use simple_logger::SimpleLogger;
10+
911
use std::error::Error;
12+
use std::fs::File;
13+
use std::io::prelude::*;
1014
use std::{env, fs};
1115

1216
pub fn main() -> Result<(), Box<dyn Error>> {
17+
SimpleLogger::new().init().unwrap();
18+
1319
let mut args = env::args();
1420
let binary = args.next().ok_or("No binary available")?;
1521
let input_filename = args
@@ -31,8 +37,8 @@ pub fn main() -> Result<(), Box<dyn Error>> {
3137
let max_line = Some(40);
3238
let tab_size = 4;
3339

34-
println!("// Successfully parsed and type checked input file.");
35-
println!("{}", to_string(&program.to_pretty(), max_line, tab_size));
40+
let mut file = File::create("out.spl")?;
41+
file.write_all(&to_string(&program.to_pretty(), max_line, tab_size).as_bytes())?;
3642
}
3743
Err(e) => {
3844
println!("{:?}", e);

0 commit comments

Comments
 (0)