Files
BlitzLLVM/code_compiler/source/main.cpp
T

89 lines
3.0 KiB
C++
Raw Normal View History

2024-06-26 00:31:06 +02:00
// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2017-2025 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
2024-06-26 00:31:06 +02:00
// AUTOGENERATED COPYRIGHT HEADER END
2025-01-25 16:27:50 +01:00
#include <clocale>
#include <iostream>
#include "compiler.hpp"
2024-06-26 00:31:06 +02:00
#include "error.hpp"
#include "lexer.hpp"
#include "parser.hpp"
2024-06-26 00:31:06 +02:00
int main(int argc, char** argv)
{
try {
std::setlocale(LC_ALL, "en_US.UTF-8");
2025-01-25 16:27:50 +01:00
std::cout << argv[1] << std::endl;
2025-02-12 00:03:19 +01:00
std::list<std::shared_ptr<blitz::ast::node>> nodes;
2024-06-26 00:31:06 +02:00
2025-02-12 00:03:19 +01:00
std::shared_ptr<blitz::lexer> lex2 = std::make_shared<blitz::lexer>(argv[1]);
for (blitz::token token = lex2->next(); (token.type != blitz::token::variant::ENDOFFILE); token = lex2->next()) {
std::cout << token.to_string() << " ";
if (token.type == blitz::token::variant::NEWLINE) {
2024-06-26 00:31:06 +02:00
std::cout << std::endl;
}
2025-02-12 00:03:19 +01:00
2024-06-26 00:31:06 +02:00
if (token.type == blitz::token::variant::UNKNOWN) {
std::cin.get();
2025-02-12 00:03:19 +01:00
} else if (blitz::ast::declare::can_parse(lex2)) {
nodes.push_back(blitz::ast::declare::try_parse(lex2));
} else if (blitz::ast::value::can_parse(lex2)) {
nodes.push_back(blitz::ast::value::try_parse(lex2));
} else if (blitz::ast::variable::can_parse(lex2)) {
nodes.push_back(blitz::ast::variable::try_parse(lex2));
2024-06-26 00:31:06 +02:00
}
}
//std::cin.get();
return 0;
2024-06-26 00:31:06 +02:00
} catch (blitz::error const& ex) {
2025-02-12 00:03:19 +01:00
std::cout << std::endl << ex.file() << std::endl;
2024-06-26 00:31:06 +02:00
std::cout << "Line " << ex.at().first << ", Char " << ex.at().second << ": " << ex.what() << std::endl;
return 1;
2024-06-26 00:31:06 +02:00
} catch (std::runtime_error const& ex) {
2025-02-12 00:03:19 +01:00
std::cout << std::endl << ex.what() << std::endl;
return 1;
2024-06-26 00:31:06 +02:00
}
2024-06-06 13:37:13 +02:00
}
2024-06-26 00:31:06 +02:00
// BlitzBasic is a strange but powerful language in the right hands. While it has
// somewhat unusual syntax and rules at times, it does not usually have ambigious
// syntax and rules like C and C++ do. Overall, the quirks can be easily explained
// and shouldn't cause odd problems.
//
// 1. Variables can be automatically defined if you did not define them before.
// ```
// Local var1 ; Local Variable definition of var1
// Global var2 ; Global Variable definition of var2
// var1 = var3 ; Automatic definition of var3 as Local Variable
// ```
//
// 2. Names are not unique, and case-insensitive
// ```
// Local myName ; Defines myName as Local
// Local MyName ; Defines MyName as Local, should error because myName has already been defined.
// Function myName() : End Function ; Defines myName as Function
// Type myName ; Defines myName as Type
// Field Bla
// End Type
// ```
//
// 3. Function calls don't always need Parenthesis:
// ```
// Local myName
2024-06-26 00:31:06 +02:00
// Function myName() : End Function
// If myName() Then : EndIf ; <- Calls myName
// myName ; <- Calls myName, because there is no = after it.
// ```
//
// 4. Int(TypeVariable) returns the pointer to the TypeVariable:
// ```
// Type myName
// Field Bla
// End Type
// Local myName.myName = New myName
2025-01-25 16:27:50 +01:00
// Print Int(myName) ; <- Prints the address of the object contained in myName.
2024-06-26 00:31:06 +02:00
// ```
//
// As this is a Basic language, there is no concept of undefined or uninitialized anything. Every behavior is well defined.