Files
Michael Fabian 'Xaymar' Dirks 15b8ed7690 Even more work
2025-02-12 00:03:19 +01:00

91 lines
3.1 KiB
C++

/// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2017-2025 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#pragma once
#include <list>
#include <memory>
#include <optional>
#include <string>
#include "../lexer.hpp"
#include "../types.hpp"
// BlitzBasic Built-Ins
// - Include: Followed by a String, which is the file to include at this location.
// - Const: Defines one or more constants, which can not be modified.
// - Local: Defines one or more local variables, which can be modified.
// - Global: Defines one or more global variables, which can be modified from anywhere.
// - Dim: Defines a dynamically resizable array, globally accessible and modifyable.
// - If, Then, ElseIf, EndIf: Your classic If.
// - Select, Case, Default, End Select: Your classic Select.
// - For, To, Step, Next: Your classic For loop.
// - While, Wend: Your classic While loop.
// - Repeat, Until, Forever: Similar to While/Wend, but the condition is at the end and will only loop if the condition is false.
// - Exit: Exit from any currently active loops. I guess this allows leaving Repeat/Forever combinations.
// - True, False: True and False. What, did you expect something else?
// - Stop: Pause the program for the debugger, if there happens to be one.
// - End: Terminate the program.
// - Goto: Jump to a specific label, without setting the return address.
// - Gosub, Return: Jump to a specific label (subroutine), setting the return address appropriately, and Return from it eventually.
// - Function, Return, End Function: Defines a function, and allows returning values. Yes, I know, End itself terminates the program, this is a special case. Thanks younger Sibly.
// - And, Or, Not: Logical operator, self-explanatory really.
#undef NULL
namespace blitz {
namespace ast {
struct node {
std::vector<blitz::token> tokens;
virtual ~node() = default;
};
struct variable : public node {
std::string name;
blitz::types::type type;
std::string struct_name;
virtual ~variable();
static bool can_parse(std::shared_ptr<blitz::lexer> lexer);
static std::shared_ptr<blitz::ast::node> try_parse(std::shared_ptr<blitz::lexer> lexer);
};
struct value : public node {
enum class variant {
UNKNOWN,
NULL,
BOOL,
INTEGER,
UNSIGNED_INTEGER,
REAL,
STRING,
} type;
union {
bool b;
intmax_t i;
uintmax_t ui;
double f;
} number;
std::string text;
virtual ~value();
static bool can_parse(std::shared_ptr<blitz::lexer> lexer);
static std::shared_ptr<blitz::ast::node> try_parse(std::shared_ptr<blitz::lexer> lexer);
};
struct declare : public node {
// Local, Global
bool global;
std::list<std::shared_ptr<blitz::ast::node>> nodes;
virtual ~declare();
static bool can_parse(std::shared_ptr<blitz::lexer> lexer);
static std::shared_ptr<blitz::ast::node> try_parse(std::shared_ptr<blitz::lexer> lexer);
};
struct expression : public node {};
} // namespace ast
} // namespace blitz