pain^2
This commit is contained in:
parent
6f525e2b9d
commit
b061ec79a2
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@
|
||||
build/
|
||||
test.x
|
||||
out.asm
|
||||
out.o
|
||||
out
|
||||
@ -2,14 +2,15 @@
|
||||
|
||||
A short and relatively detailed list of all the basics of XILANG. Also yes, the name is supposed to be all caps *always* just like older FORTRAN.
|
||||
|
||||
## Extremly Basic Functions
|
||||
## Extremely Basic Functions
|
||||
|
||||
* `ret` then a value (can be a numeral or a string) will return that value
|
||||
* `exit` then a value (can ONLY be a numeral) will exit with that return value
|
||||
* `func` then a name (ex: `func main() {};`) allows you to define a new function
|
||||
* `import` and a filename (either in `""` or `<>` depending on if it is a local file in the dir or a file from the include path, similar to C) allows you to import the functions from another file (ex: `import Example.xh`)
|
||||
* `print` then a value will allow to print a character or string to the screen (you can also print any other type of varible)
|
||||
* `print` then a value will allow to print a character or string to the screen (you can also print any other type of variable)
|
||||
|
||||
## Defining Varibles
|
||||
## Defining Variables
|
||||
|
||||
you define something by doing the type of var you want to define then a name then an = and the value of it (ex: `float Example = 1.0;`)
|
||||
|
||||
@ -38,4 +39,4 @@ func main() {
|
||||
ret 0;
|
||||
}
|
||||
```
|
||||
This small prgram will print `Hello World!` and return 0.
|
||||
This small program will print `Hello World!` and return 0.
|
||||
@ -1,7 +1,7 @@
|
||||
;This is a comment
|
||||
|
||||
global _start
|
||||
start:
|
||||
_start:
|
||||
mov rax, 60
|
||||
mov rsi, 0
|
||||
syscall
|
||||
@ -1,5 +1,5 @@
|
||||
!This is a Comment
|
||||
|
||||
func main() {
|
||||
ret 0;
|
||||
exit 0;
|
||||
};
|
||||
21
src/main.cxx
21
src/main.cxx
@ -4,6 +4,8 @@
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
//#include "./tokesizer.hxx"
|
||||
|
||||
#define version "RD-00002"
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
@ -12,7 +14,7 @@
|
||||
const char *output_filename = "out.asm";
|
||||
|
||||
enum class TokenType {
|
||||
ret,
|
||||
exit,
|
||||
int_lit,
|
||||
semicolon,
|
||||
comment
|
||||
@ -38,8 +40,8 @@ std::vector<Token> Tokenize(const std::string& str) {
|
||||
}
|
||||
i--;
|
||||
|
||||
if (buffer == "ret") { // return func checkor
|
||||
Tokens.push_back({.type = TokenType::ret});
|
||||
if (buffer == "exit") { // return func checkor
|
||||
Tokens.push_back({.type = TokenType::exit});
|
||||
buffer.clear();
|
||||
continue;
|
||||
}
|
||||
@ -53,11 +55,9 @@ std::vector<Token> Tokenize(const std::string& str) {
|
||||
i--;
|
||||
Tokens.push_back({.type = TokenType::int_lit, .value = buffer});
|
||||
buffer.clear();
|
||||
}
|
||||
else if (c == ';') { // legit only checks for a semicolon
|
||||
} else if (c == ';') { // legit only checks for a semicolon
|
||||
Tokens.push_back({.type = TokenType::semicolon});
|
||||
}
|
||||
else if (std::isspace(c)) {
|
||||
} else if (std::isspace(c)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -67,10 +67,10 @@ std::vector<Token> Tokenize(const std::string& str) {
|
||||
|
||||
std::string Tokens_To_Asm(const std::vector<Token>& Tokens) {
|
||||
std::stringstream output;
|
||||
output << "global _start\nstart:\n";
|
||||
output << "global _start\n_start:\n";
|
||||
for (int i = 0; i < Tokens.size(); i++) {
|
||||
const Token& Token = Tokens.at(i);
|
||||
if (Token.type == TokenType::ret) {
|
||||
if (Token.type == TokenType::exit) {
|
||||
if (i + 1 < Tokens.size() && Tokens.at(i+1).type == TokenType::int_lit) {
|
||||
if (i + 2 < Tokens.size() && Tokens.at(i+2).type == TokenType::semicolon) {
|
||||
output << " mov rax, 60\n";
|
||||
@ -104,5 +104,8 @@ int main(int argC, char *argV[]) {
|
||||
file << Tokens_To_Asm(Tokens);
|
||||
}
|
||||
|
||||
system("nasm -felf64 out.asm");
|
||||
system("ld -o out out.o");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
11
src/tokesizer.hxx
Normal file
11
src/tokesizer.hxx
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
inline Tokenizer(const std::string& src) {
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string m_src;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user