Skip to content
Snippets Groups Projects
Commit db2259b1 authored by MarvelousAnything's avatar MarvelousAnything
Browse files

Did some work on the parser, ast, and lexer.

parent 0049eab5
No related branches found
No related tags found
No related merge requests found
H
desolation-vm/src/lib.rs,d/2/d223e57cb8e5a300f8967d2aa903ba0ce9bb7fc0
A
src/lex/consts.rs,d/6/d6ac01c8a58d9dff09212d8593829096a491440e
:
Cargo.toml,1/b/1b290eb385892bfd4870c08a785598e98c8691b7
@
src/lex/token.rs,e/f/ef992bfb55ea19c324d0baced9107bb35e7403e4
\ No newline at end of file
// mod node; mod node;
//
// pub enum Program { pub enum Program {
// VarList(Vec<Var>), VarList(Vec<Var>),
// FunList(Vec<Fun>), FunList(Vec<Fun>),
// } }
//
// pub struct ID { pub struct ID {
// pub name: String, pub name: String,
// } }
//
// pub struct Var { pub struct Var {
// pub name: String, pub name: String,
// pub value: Option<Expr>, pub value: Option<Expr>,
// } }
//
// pub struct Fun { pub struct Expr {
// pub name: String,
// pub params: Vec<ID>, }
// pub body: Vec<Stmt>,
// } pub struct Fun {
pub name: String,
pub params: Vec<ID>,
pub body: Vec<Stmt>,
}
pub struct Stmt {
}
...@@ -93,6 +93,12 @@ impl TokenStream { ...@@ -93,6 +93,12 @@ impl TokenStream {
.cloned() .cloned()
.collect::<TokenStream>() .collect::<TokenStream>()
} }
pub fn reverse(&self) -> Self {
let mut tokens = self.tokens.clone();
tokens.reverse();
TokenStream { tokens }
}
} }
impl FromIterator<Token> for TokenStream { impl FromIterator<Token> for TokenStream {
......
use thiserror::Error;
use anyhow::{bail, ensure, Result};
use crate::ast;
use crate::ast::Program;
use crate::lex::lexer::TokenStream; use crate::lex::lexer::TokenStream;
use crate::lex::token::Token;
#[derive(Debug, Error)]
enum ParseError {
#[error("Unexpected token")]
UnexpectedToken,
#[error("Unexpected end of file")]
UnexpectedEOF,
}
pub struct Parser { pub struct Parser {
tokens: TokenStream, tokens: TokenStream,
stack: Vec<Token>
}
pub enum ParserActions {
Shift,
Reduce(usize),
Accept,
} }
impl Parser { impl Parser {
pub fn new(tokens: TokenStream) -> Self {
Self { tokens, stack: vec![] }
}
// This should parse a token stream into an AST. // This should parse a token stream into an AST.
pub fn parse(_tokens: TokenStream) { pub fn parse(&mut self) -> Result<Program> {
todo!("Implement parser"); todo!("Implement parser");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment