Files
BlitzLLVM/code_compiler/source/main.cpp
T
2025-01-25 19:26:49 +01:00

103 lines
3.0 KiB
C++

// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2017-2025 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#include <clocale>
#include <iostream>
#include "compiler.hpp"
#include "error.hpp"
#include "lexer.hpp"
#include "parser.hpp"
int main(int argc, char** argv)
{
try {
std::setlocale(LC_ALL, "en_US.UTF-8");
std::cout << argv[1] << std::endl;
blitz::lexer lex(argv[1]);
for (blitz::token token = lex.next(); (token.type != blitz::token::variant::ENDOFFILE); token = lex.next()) {
switch (token.type) {
case blitz::token::variant::COMMENT:
std::cout << token.text;
break;
case blitz::token::variant::SYMBOL:
std::cout << token.text << " ";
break;
case blitz::token::variant::TEXT:
case blitz::token::variant::INTEGER:
case blitz::token::variant::REAL:
std::cout << token.text << " ";
break;
case blitz::token::variant::STRING:
std::cout << "\"" << token.text << "\""
<< " ";
break;
case blitz::token::variant::NEWLINE:
std::cout << std::endl;
break;
default:
std::cout << token.to_string() << " ";
break;
}
if (token.type == blitz::token::variant::UNKNOWN) {
std::cin.get();
}
}
blitz::parser pars(argv[1]);
//std::cin.get();
return 0;
} catch (blitz::error const& ex) {
std::cout << ex.file() << std::endl;
std::cout << "Line " << ex.at().first << ", Char " << ex.at().second << ": " << ex.what() << std::endl;
return 1;
} catch (std::runtime_error const& ex) {
std::cout << ex.what() << std::endl;
return 1;
}
}
// 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
// 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
// Print Int(myName) ; <- Prints the address of the object contained in myName.
// ```
//
// As this is a Basic language, there is no concept of undefined or uninitialized anything. Every behavior is well defined.