Files
flux/examples/fibonacci.flx
Jooris Hadeler 4f80de51b2 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.
2026-03-10 17:20:17 +01:00

23 lines
367 B
Plaintext

fn fibonacci_rec(n: u8) -> u64 {
if n < 2 {
return n;
}
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;
}