fn fib(n) {
- return fibIter(n, 0, 1);
-}
-
-fn fibIter(n, curr, next) {
- if (n == 0) {
- return curr;
- } else if (n == 1) {
- return next;
- } else {
- return fibIter(n - 1, next, curr + next);
+ fn fibIter(n, curr, next) {
+ if (n == 0) {
+ return curr;
+ } else if (n == 1) {
+ return next;
+ } else {
+ return fibIter(n - 1, next, curr + next);
+ }
}
+
+ return fibIter(n, 0, 1);
}
class Prova {
a.var1 = 210;
println(a.var1);
-a.runtime();
\ No newline at end of file
+a.runtime();
char *lexeme = 0;
char new_ch = 0;
- while (file.stream.eof() && file.stream.peek() != '"') {
+ while (file.stream.peek() != EOF && file.stream.peek() != '"') {
if (file.stream.peek() == '\\') {
file.advance();
lexeme[len - 1] = new_ch;
}
- if (file.stream.eof()) {
+ if (file.stream.peek() == EOF) {
return MAKE_TOKEN(TokenType::Error, "Unterminated string.");
} else {
file.advance();
if (len > 1) {
switch (lexeme[1]) {
case 'l':
- return checkKeyword(lexeme, len, 2, "ass", TokenType::Break);
+ return checkKeyword(lexeme, len, 2, "ass", TokenType::Class);
case 'o':
return checkKeyword(lexeme, len, 2, "ntinue", TokenType::Continue);
}
#include "parser.hpp"
#include "syntax_error.hpp"
+#include <cstdint>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <variant>
std::vector<std::unique_ptr<Stmt>> Parser::parse() {
std::vector<std::unique_ptr<Stmt>> stmts;
if (match(TokenType::Break)) {
return std::make_unique<BreakExpr>(current->line, current->column,
current->filename);
- } else if (match(TokenType::Break)) {
+ } else if (match(TokenType::Continue)) {
return std::make_unique<ContinueExpr>(current->line, current->column,
current->filename);
}
public:
LBPLPrintln() {}
- int arity() override { return 1; };
+ constexpr int arity() override { return 1; };
Value call(Interpreter *, std::vector<Value> &args) override {
if (std::holds_alternative<std::string>(args[0])) {
public:
LBPLClock() {}
- int arity() override { return 0; };
+ constexpr int arity() override { return 0; };
Value call(Interpreter *, std::vector<Value> &args) override {
return std::chrono::duration_cast<std::chrono::milliseconds>(
#include "interpreter.hpp"
+#include "runtime_error.hpp"
#include "types/LBPLClass.hpp"
#include "types/LBPLFunction.hpp"
#include "types/LBPLInstance.hpp"
#include "types/LBPLTypes.hpp"
-#include "runtime_error.hpp"
#include <cstddef>
#include <cstdint>