Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7101f8d
AST Reset
LunaStev Jan 11, 2025
cca1c7d
AST & Parser Reset
LunaStev Jan 11, 2025
f6b6660
path function and token variable
LunaStev Jan 12, 2025
9c1137b
Passing Vec<Token> to Variable Reference
LunaStev Jan 12, 2025
62d7e44
Delete while syntax
LunaStev Jan 12, 2025
1f58705
Delete print and if syntax
LunaStev Jan 12, 2025
72e6813
Delete variable syntax
LunaStev Jan 12, 2025
d79348e
Delete function syntax
LunaStev Jan 12, 2025
24bbb2e
Delete advance syntax
LunaStev Jan 12, 2025
71a9547
Delete ast syntax
LunaStev Jan 12, 2025
c42b501
Delete match self.current_token.token_type syntax
LunaStev Jan 12, 2025
46883c7
Delete EOF syntax
LunaStev Jan 12, 2025
d4acab2
Delete parse syntax
LunaStev Jan 12, 2025
989c87b
Delete Parser Impl syntax
LunaStev Jan 12, 2025
0d42aa4
Delete Parser syntax
LunaStev Jan 12, 2025
979a3ed
None
LunaStev Jan 12, 2025
f9c03f8
Delete AST syntax
LunaStev Jan 12, 2025
9578300
Delete impl AST and new and add_node syntax
LunaStev Jan 12, 2025
c3df901
None
LunaStev Jan 12, 2025
0fd623a
Comment
LunaStev Jan 12, 2025
352c0fb
Comment
LunaStev Jan 12, 2025
c615f84
comment
LunaStev Jan 12, 2025
e3e39f1
Delete existing code because it is currently unavailable
LunaStev Jan 12, 2025
b85e882
Functional Test
LunaStev Jan 12, 2025
8242eb0
Remove node file
LunaStev Jan 12, 2025
a41f185
Parse Add
LunaStev Jan 12, 2025
12a1ec2
Remove parser var
LunaStev Jan 12, 2025
ea074a5
Remove node file
LunaStev Jan 12, 2025
9127315
Comment processing
LunaStev Jan 12, 2025
d5186a5
Comment processing
LunaStev Jan 12, 2025
b270beb
Only Function nodes left
LunaStev Jan 12, 2025
8b3f235
New Function Node Related Code
LunaStev Jan 12, 2025
21e178d
Comment Block
LunaStev Jan 12, 2025
8337c3d
Comment Block
LunaStev Jan 12, 2025
11782f1
Comment Block
LunaStev Jan 12, 2025
95f2145
Comment Block
LunaStev Jan 12, 2025
915d227
Comment
LunaStev Jan 12, 2025
cfda99b
Comment
LunaStev Jan 12, 2025
11077bd
Comment
LunaStev Jan 12, 2025
d527fd3
Remove
LunaStev Jan 12, 2025
d04ee8f
Remove
LunaStev Jan 12, 2025
5997cb3
Remove
LunaStev Jan 12, 2025
6234d96
Remove
LunaStev Jan 12, 2025
7f355c1
Comment Remove
LunaStev Jan 12, 2025
98470f0
Comment Remove
LunaStev Jan 12, 2025
14fb994
New Function Node Related Code
LunaStev Jan 12, 2025
a20a385
New Function Node Related Code
LunaStev Jan 12, 2025
ddca4a8
Content-free function
LunaStev Jan 12, 2025
70aac13
Delete node files
LunaStev Jan 12, 2025
1cc7d57
Merge branch 'feature/ast' into feature/temporary-ast
LunaStev Jan 12, 2025
99919d9
Merge pull request #35 from LunaStev/feature/temporary-ast
LunaStev Jan 12, 2025
ab53b8f
Merge pull request #36 from LunaStev/feature/ast
LunaStev Jan 12, 2025
3b0466b
Rollback
LunaStev Jan 12, 2025
41e2aaa
Rollback
LunaStev Jan 12, 2025
5a0aff4
Rollback
LunaStev Jan 12, 2025
f4302f2
Rollback
LunaStev Jan 12, 2025
b205eed
Merge pull request #38 from LunaStev/feature/temporary-ast
LunaStev Jan 12, 2025
056357d
Merge pull request #39 from LunaStev/feature/ast
LunaStev Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod lexer;
mod parser;
mod error;
mod node;

use std::fs;
use lexer::{Lexer, Token};
use parser::Parser;
use parser::ast::AST;
use crate::lexer::TokenType;
use crate::parser::ast::create_function_ast;
// use crate::node::function_node;

fn format_tokens(tokens: &Vec<Token>) -> String {
Expand All @@ -22,6 +21,7 @@ fn format_tokens(tokens: &Vec<Token>) -> String {
result
}

/*
fn format_parser(parser: &Parser) -> String {
format!(
"{{\n lexer: {{\n source: {:?},\n current: {},\n line: {}\n }},\n current_token: {{\n token_type: {:?},\n lexeme: {:?},\n line: {}\n }}\n}}",
Expand All @@ -40,39 +40,22 @@ fn format_ast(ast: &AST) -> String {
ast.nodes
)
}
*/

fn main() {
let code = fs::read_to_string("test/test4.wave").expect("Failed to read the file");

// Create a Lexer
let mut lexer = Lexer::new(code.as_str());

// Tokenize the source code
let tokens = lexer.tokenize();
eprintln!("Tokens: {}", format_tokens(&tokens));

// Create a Parser
let mut parser = Parser::new(lexer);

// Parse the AST
let ast = parser.parse();
/*
let mut asta = AST::new();

let node = ASTNode::Variable {
name: String::from("x"),
var_type: String::from(":i32"),
value: Value::Int(42),
is_immutable: false,
};
let function_name = tokens.iter()
.find(|token| matches!(token.token_type, TokenType::IDENTIFIER(_)))
.map(|token| token.lexeme.clone())
.unwrap_or_default();

asta.add_node(node);
*/
let ast = create_function_ast(function_name);

// a formalized output
eprintln!("Tokens: {}", format_tokens(&tokens));
eprintln!("\nParser: {}", format_parser(&parser));
eprintln!("\nAST: {}", format_ast(&ast));
// println!("\nTEST AST: {}", format_ast(&asta));
// println!("{:?}", function_node());
// println!("{:#?}", function_node());
eprintln!("AST: {:?}", &ast)
}
23 changes: 0 additions & 23 deletions src/node.rs

This file was deleted.

66 changes: 25 additions & 41 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,31 @@ pub enum Value {

#[derive(Debug, Clone)]
pub enum ASTNode {
Function {
name: String,
params: Vec<String>,
body: Vec<ASTNode>,
},
Variable {
name: String,
var_type: String,
value: Value,
is_immutable: bool,
},
IfStatement {
condition: String,
body: Vec<ASTNode>,
else_body: Option<Vec<ASTNode>>,
},
WhileLoop {
condition: String,
body: Vec<ASTNode>,
},
ForLoop {
init: Box<ASTNode>,
condition: String,
increment: Box<ASTNode>,
body: Vec<ASTNode>,
},
Import {
module_name: String,
},
Print {
message: String,
newline: bool,
},
Literal {
value: String,
},
Expression {
operator: String,
left: Box<ASTNode>,
right: Box<ASTNode>,
},
Function(FunctionNode),
}

#[derive(Debug, Clone)]
pub struct FunctionNode {
pub name: String,
pub parameters: Vec<ParameterNode>,
pub body: Vec<ASTNode>,
}

#[derive(Debug, Clone)]
pub struct ParameterNode {
pub name: String,
pub param_type: String, // For simplicity, assuming type as string.
}

pub fn create_function_ast(function_name: String) -> ASTNode {
ASTNode::Function(FunctionNode {
name: function_name,
parameters: vec![], // No parameters
body: vec![], // Empty body
})
}

/*
#[derive(Debug, Clone)]
pub struct AST {
pub nodes: Vec<ASTNode>,
Expand All @@ -66,3 +48,5 @@ impl AST {
self.nodes.push(node);
}
}

*/
3 changes: 3 additions & 0 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
use crate::lexer::{FloatType, IntegerType, Lexer, Token, TokenType};
use crate::parser::ast::{AST, ASTNode, Value};

Expand Down Expand Up @@ -545,3 +546,5 @@ impl<'a> Parser<'a> {
});
}
}

*/
4 changes: 1 addition & 3 deletions test/test4.wave
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fun main() {
println("Hello World");
}
fun main() { }
Loading