|
|
@@ -21,9 +21,9 @@ I believe that this chapter should be a breakpoint for you to write a simple C p |
|
|
|
- chapter 0: To format our code properly in order to increase readability and we've implemented some core functions for memory management, strings and input / output. |
|
|
|
- chapter 1: To declare and define functions, and we've covered character and file descriptor related functions, as well as ASCII table and discussed C keywords. |
|
|
|
- chapter 2: To use external variables, function pointers and minor part of 'libncurses' reimplementation that doesn't care about portability. |
|
|
|
- chapter 3: To use standard library 'printf' function, and to implement variadic argument functions, while also covering switch statement in more depth. |
|
|
|
- chapter 3: To use standard library 'printf' function, and to implement variadic argument functions, while also covering functions and switch statement in more depth. |
|
|
|
|
|
|
|
From this moment onwards, some chapters will have few functions called 'program_*', which we can use to forge even larger programs. They'll each have their own dependencies, for |
|
|
|
From this moment onwards, some chapters will have few functions called 'program_*', which we can use to build even larger programs. They'll each have their own dependencies, for |
|
|
|
example, some of them will require functions from some or all previous chapter source and header files, but I'll make sure not to use in them functions that'll be in future |
|
|
|
chapters. Instead of that, we'll (re)implement newer stuff with different approach if necessary. That way, you can be sure that if you're reading chapter four, for example, it'll |
|
|
|
only use functions and variables defined in chapters zero to three. Lets begin. |
|
|
@@ -84,6 +84,78 @@ This is how we parse it, determine where some syntax rule begins, where it ends, |
|
|
|
^ - if it is, we return index of that rule (with function 'syntax_select') and length is 3, without changing the offset. |
|
|
|
|
|
|
|
And we repeat that process until we reach the end of the string, that null termination, it's not a fast algorithm, but it's simple. Easy. |
|
|
|
|
|
|
|
With all that said, learning C is great and all, but lets see some other programming languages, some minimal program in few of them, hello world for example. |
|
|
|
|
|
|
|
@C |
|
|
|
// I didn't use preprocessor in this example or real C comments with asterix. |
|
|
|
extern int puts (const char *); |
|
|
|
|
|
|
|
int main (void) { |
|
|
|
puts ("Hello world!"); |
|
|
|
|
|
|
|
return (0); |
|
|
|
} |
|
|
|
@ |
|
|
|
|
|
|
|
@Ada |
|
|
|
-- Also, 'use' keyword would apply the namespace, more on that later. |
|
|
|
with ada.text_io; |
|
|
|
|
|
|
|
procedure hello_world is |
|
|
|
begin |
|
|
|
ada.text_io.put_line ("Hello world!"); |
|
|
|
end hello_world; |
|
|
|
@ |
|
|
|
|
|
|
|
@C++ |
|
|
|
// This is C++23 standard, they like new stuff anyway, but it can look more like C if you want. |
|
|
|
import module std; |
|
|
|
|
|
|
|
int main () { |
|
|
|
std::print ("Hello world!\n"); |
|
|
|
} |
|
|
|
@ |
|
|
|
|
|
|
|
@HolyC |
|
|
|
// Masterpiece. |
|
|
|
"Hello world!\n"; |
|
|
|
@ |
|
|
|
|
|
|
|
@Flat |
|
|
|
; This will run only on 64-bit GNU/Linux OS without issues. |
|
|
|
format ELF64 executable 3 |
|
|
|
|
|
|
|
segment readable executable |
|
|
|
mov rax, 1 |
|
|
|
mov rdi, 1 |
|
|
|
mov rsi, string |
|
|
|
mov rdx, [length] |
|
|
|
syscall |
|
|
|
mov rax, 60 |
|
|
|
mov rdi, 0 |
|
|
|
syscall |
|
|
|
|
|
|
|
segment readable writable |
|
|
|
string db 'Hello world!', 10, 0 |
|
|
|
length dq $-string |
|
|
|
@ |
|
|
|
|
|
|
|
@Fortran |
|
|
|
! Fortran is great programming language, but it can be autistic at times. |
|
|
|
|
|
|
|
program hello_world |
|
|
|
print *, 'Hello world!' |
|
|
|
end program hello_world |
|
|
|
@ |
|
|
|
|
|
|
|
@Python |
|
|
|
# Well, they call it "second best language for everything" for some reason... |
|
|
|
|
|
|
|
print ("Hello world!") |
|
|
|
@ |
|
|
|
|
|
|
|
Learning C well will make learning those other programming languages, except assembly languages, a walk in the park. |
|
|
|
*/ |
|
|
|
|
|
|
|
extern int syntax_define (int enrange, int derange, char * begin, char * end, char escape, int colour, int effect); // This must be called before 'syntax_select' function. |
|
|
|