Lexer done for now, moving on to ast
This commit is contained in:
@@ -1,9 +1,92 @@
|
||||
// AUTOGENERATED COPYRIGHT HEADER START
|
||||
// Copyright (C) 2017-2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||
// AUTOGENERATED COPYRIGHT HEADER END
|
||||
#include <iostream>
|
||||
#include "compiler.hpp"
|
||||
#include "error.hpp"
|
||||
#include "lexer.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::cout << argv[1] << std::endl;
|
||||
blitz::lexer lex(argv[1]);
|
||||
|
||||
try {
|
||||
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();
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
} catch (std::runtime_error const& ex) {
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
blitz::compiler comp;
|
||||
comp.compile(argv[1], std::string(argv[1]) + ".exe");
|
||||
std::cin.get();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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:
|
||||
// ```
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user