mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
zkas: Add skeleton for semantic analyzer.
This commit is contained in:
28
zkas/src/analyzer.rs
Normal file
28
zkas/src/analyzer.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::str::Chars;
|
||||
|
||||
use crate::ast::{Constants, Statements, Witnesses};
|
||||
|
||||
pub struct Analyzer {
|
||||
file: String,
|
||||
lines: Vec<String>,
|
||||
constants: Constants,
|
||||
witnesses: Witnesses,
|
||||
statements: Statements,
|
||||
}
|
||||
|
||||
impl Analyzer {
|
||||
pub fn new(
|
||||
filename: &str,
|
||||
source: Chars,
|
||||
constants: Constants,
|
||||
witnesses: Witnesses,
|
||||
statements: Statements,
|
||||
) -> Self {
|
||||
// For nice error reporting, we'll load everything into a string
|
||||
// vector so we have references to lines.
|
||||
let lines = source.as_str().lines().map(|x| x.to_string()).collect();
|
||||
Analyzer { file: filename.to_string(), lines, constants, witnesses, statements }
|
||||
}
|
||||
|
||||
pub fn analyze(self) {}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
/// Semantic analyzer
|
||||
pub mod analyzer;
|
||||
/// AST
|
||||
pub mod ast;
|
||||
/// Lexer module
|
||||
|
||||
@@ -2,7 +2,7 @@ use anyhow::Result;
|
||||
use clap::clap_app;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
use zkas::{lexer::Lexer, parser::Parser};
|
||||
use zkas::{analyzer::Analyzer, lexer::Lexer, parser::Parser};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = clap_app!(zkas =>
|
||||
@@ -22,11 +22,14 @@ fn main() -> Result<()> {
|
||||
// println!("{:#?}", tokens);
|
||||
|
||||
let parser = Parser::new(filename, source.chars(), tokens);
|
||||
let (constants, witnesses, circuit) = parser.parse();
|
||||
let (constants, witnesses, statements) = parser.parse();
|
||||
|
||||
// println!("{:#?}", constants);
|
||||
// println!("{:#?}", witnesses);
|
||||
// println!("{:#?}", circuit);
|
||||
// println!("{:#?}", statements);
|
||||
|
||||
let analyzer = Analyzer::new(filename, source.chars(), constants, witnesses, statements);
|
||||
analyzer.analyze();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user