Skip to content

Commit ac8e8c7

Browse files
[Patch] Noviq-Rust-Nebula-0.1.1
- Variables and comments.
1 parent 7d0507f commit ac8e8c7

17 files changed

Lines changed: 883 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "noviq"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["Noviq Contributors"]
66
description = "A simple, interpreted programming language written in Rust"

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ Noviq aims to be a compiled language instead of an interpreted language in the f
2121
Builder tool for interpreter version is called: Photon or Photon-NVQ
2222
The compiler will be called: Singularity or Singularity-NVQ
2323

24+
First release of Noviq is expected to be Pre-alpha 1.0.0.
25+
26+
## Implementation:
27+
### Pre-aplha (Nebula):
28+
- Basic syntax including but not limited to variables, print, conditionals, etc.
29+
30+
### Aplha (Protostar):
31+
- Including but not limited to everything that includes a basic workstack for a language like loops, functions, libs, a lot more.
32+
- Start building a simple compiler.
33+
34+
### Beta (Nova):
35+
- More advanced features including OOP, etc.
36+
- Compiler should be able to build most of the code.
37+
38+
### Release (Supernova):
39+
- A polished interpreted release of everything implemented before it.
40+
- A fully working compiler which will be polished in future builds.
41+
2442
## Building
2543

2644
### Using Photon (Recommended)

examples/README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ cargo run -- examples/hello.nvq
1414

1515
## Available Examples
1616

17-
### `hello.nvq`
18-
Basic hello world program demonstrating:
19-
- Print statements with `log()`
20-
- Comments with `#`
21-
- String literals
22-
23-
### `test.nvq`
24-
Basic test file for development
17+
- `hello.nvq` - Basic hello world program
18+
- `test.nvq` - Simple test file
19+
- `variables.nvq` - Variable declaration and usage
20+
- `quotes.nvq` - Single and double quote strings
2521

2622
## Features Demonstrated
2723

2824
- Comments (lines starting with `#`)
2925
- Print statements with `print()`
30-
- String literals
26+
- String literals (double and single quotes)
27+
- Variable declarations with `let`
28+
- Numbers (integers and floats)
29+
- Booleans (true/false)

examples/quotes.nvq

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Testing both quote types
2+
3+
let double_quote = "String with double quotes"
4+
let single_quote = 'String with single quotes'
5+
6+
print(double_quote)
7+
print(single_quote)

examples/showcase.nvq

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Comprehensive example showcasing Noviq features
2+
3+
# Variable declarations with different types
4+
let greeting = "Hello, Noviq!"
5+
let name = 'World'
6+
let answer = 42
7+
let pi = 3.14159
8+
let is_cool = true
9+
let is_boring = false
10+
11+
# Print variables
12+
print(greeting)
13+
print(name)
14+
print(answer)
15+
print(pi)
16+
print(is_cool)
17+
print(is_boring)
18+
19+
# Direct values in print
20+
print("Direct string")
21+
print(123)
22+
print(true)

examples/variables.nvq

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Variable declaration test
2+
3+
let message = "Hello from a variable!"
4+
let number = 42
5+
let pi = 3.14
6+
let flag = true
7+
8+
print(message)
9+
print(number)
10+
print(pi)
11+
print(flag)

src/frontend/ast.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
/// AST node definitions for Noviq
66
///
7-
/// Kept minimal for the current language subset (string literals and function calls)
7+
/// Expressions and statements for the Noviq language
88
99
#[derive(Debug, Clone, PartialEq)]
1010
pub enum Expr {
1111
String(String),
12+
Number(f64),
13+
Boolean(bool),
14+
Identifier(String),
1215
Call { name: String, args: Vec<Expr> },
1316
}
1417

1518
#[derive(Debug, Clone, PartialEq)]
1619
pub enum Stmt {
20+
Let { name: String, value: Expr },
1721
Expr(Expr),
1822
}

src/frontend/lexer/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,23 @@ impl Lexer {
4343
self.reader.advance();
4444
Token::Newline
4545
}
46-
Some('"') => Token::String(self.reader.read_string()),
46+
Some('"') | Some('\'') => Token::String(self.reader.read_string()),
47+
Some('=') => {
48+
self.reader.advance();
49+
Token::Assign
50+
}
4751
Some(ch) if ch.is_alphabetic() || ch == '_' => {
48-
Token::Identifier(self.reader.read_identifier())
52+
let ident = self.reader.read_identifier();
53+
// Check for keywords
54+
match ident.as_str() {
55+
"let" => Token::Let,
56+
"true" => Token::True,
57+
"false" => Token::False,
58+
_ => Token::Identifier(ident),
59+
}
60+
}
61+
Some(ch) if ch.is_numeric() => {
62+
Token::Number(self.reader.read_number())
4963
}
5064
Some('(') => {
5165
self.reader.advance();

src/frontend/lexer/reader.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ impl Reader {
4545
}
4646

4747
pub fn read_string(&mut self) -> String {
48+
let quote_char = self.current.unwrap(); // Remember which quote (' or ")
4849
let mut result = String::new();
4950
self.advance(); // Skip opening quote
5051

5152
while let Some(ch) = self.current {
52-
if ch == '"' {
53+
if ch == quote_char {
5354
self.advance(); // Skip closing quote
5455
break;
5556
} else if ch == '\\' {
@@ -60,6 +61,7 @@ impl Reader {
6061
't' => result.push('\t'),
6162
'r' => result.push('\r'),
6263
'"' => result.push('"'),
64+
'\'' => result.push('\''),
6365
'\\' => result.push('\\'),
6466
_ => {
6567
result.push('\\');
@@ -77,6 +79,21 @@ impl Reader {
7779
result
7880
}
7981

82+
pub fn read_number(&mut self) -> f64 {
83+
let mut num_str = String::new();
84+
85+
while let Some(ch) = self.current {
86+
if ch.is_numeric() || ch == '.' {
87+
num_str.push(ch);
88+
self.advance();
89+
} else {
90+
break;
91+
}
92+
}
93+
94+
num_str.parse().unwrap_or(0.0)
95+
}
96+
8097
pub fn read_identifier(&mut self) -> String {
8198
let mut ident = String::new();
8299

src/frontend/parser/expr.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,30 @@ impl<'a> ExprParser<'a> {
4242
self.advance();
4343
Ok(Expr::String(s))
4444
}
45+
Token::Number(n) => {
46+
self.advance();
47+
Ok(Expr::Number(n))
48+
}
49+
Token::True => {
50+
self.advance();
51+
Ok(Expr::Boolean(true))
52+
}
53+
Token::False => {
54+
self.advance();
55+
Ok(Expr::Boolean(false))
56+
}
4557
Token::Identifier(name) => {
4658
self.advance();
4759

48-
// Must be a function call
60+
// Check if it's a function call
4961
if self.current() == &Token::LeftParen {
5062
self.advance(); // consume '('
5163
let args = self.parse_arguments()?;
5264
self.expect(Token::RightParen)?;
5365
Ok(Expr::Call { name, args })
5466
} else {
55-
Err(format!("Expected '(' after identifier '{}'", name))
67+
// Just an identifier (variable reference)
68+
Ok(Expr::Identifier(name))
5669
}
5770
}
5871
token => Err(format!("Unexpected token in expression: {:?}", token)),

0 commit comments

Comments
 (0)