Add fluxc compiler skeleton: token definitions and lexer

Introduces the fluxc Rust crate with the first two compiler stages:

- token.rs: define_tokens! macro generates TokenKind enum and its
  Display impl from a single table covering all Flux tokens
  (literals, keywords, operators, punctuation, Eof/Unknown).
  Span (half-open u32 byte range) and Token<'src> (kind + span +
  zero-copy text slice) round out the module.

- lexer.rs: Lexer<'src> produces Token<'src> from a source &str.
  Skips whitespace, // line comments, and /* */ block comments.
  Handles all integer bases (decimal, hex, octal, binary with _
  separators), floats (fractional + exponent), string/char literals
  with escape sequences, and Unicode identifiers via unicode-xid.
  Implements Iterator<Item = Token> and includes 17 unit tests.

Also adds .gitignore (ignores fluxc/target) and expands
examples/fibonacci.flx with an iterative variant.
This commit is contained in:
2026-03-10 17:20:17 +01:00
parent 0e08640f59
commit 4f80de51b2
7 changed files with 798 additions and 2 deletions

View File

@@ -1,7 +1,23 @@
fn fibonacci(n: u8) -> u64 {
fn fibonacci_rec(n: u8) -> u64 {
if n < 2 {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
return fibonacci_rec(n - 1) + fibonacci_rec(n - 2);
}
fn fibonacci_iter(n: u8) -> u64 {
let mut counter = 0;
let mut a = 0;
let mut b = 1;
while counter < n {
let temp = a + b;
a = b;
b = temp;
counter = counter + 1;
}
return a;
}