gjsteyn / corewar Goto Github PK
View Code? Open in Web Editor NEWWhat we do in life, echoes in eternity
What we do in life, echoes in eternity
Get next line still requires some "libft" functions
Asm byte code incorrect values when over MAX_INT
Parm: little - the value to be converted
Parm: big - the result of the conversion is to be placed in this array
For you own knowledge please research the topic, it an incredibly simply function to convert a little endian value as it is represented in C to be converted to a big endian number as should be used for the VM
i suggest we discuss a basic list structure. To make it simpler we could create a que structure and associated functions as we'll require them to manage and parse tokens.
PROGRAM =
HEADER {CODE}
HEADER =
<.name> TEXT "\n" <.comment> TEXT "\n"
CODE =
[{<label_chars>} ":"] OP <whitespace - \n> " ARG { ARG}"\n"
OP =
"live"
| "ld"
| "st"
| "add"
| "sub"
| "and"
| "or"
| "xor"
| "zjmp"
| "ldi"
| "sti"
| "fork"
| "lld"
| "lldi"
| "lfork"
| "aff"
ARG =
["%"] [":"] {number}
TEXT =
{ascci}
token type = value
e_keyword;
e_op;
e_arg;
[KEY WORD] = name
[TEXT] = "zork"
[KEY WORD] = comment
[TEXT] = "..."
[LABEL] = "l2"
[OP] = <e_opcode>
[ARG] = <e_arg_code>
[ARG_LABEL] =
[NUMBER] =
[EOL]
[NUMBER] =
[ARITH] = {+, *, -, /, %}
[BRAKET] = 1, 2
Example: Gagnant.cor (Yes, trying to compile Gagnant.cor, not Gagnant.s).
long f_atoi(char *nbr, int *error)
parm: nbr - string of number to be converted
parm: error - this value is to be set incase of error else it should be set to 0.
A standard atoi function, please note it should convert any number until a non digit value is reached. eg. "12345abc" -> 12345
Error should include char* not starting with a digit or "-".
Function SHOULD segfault in cases where nbr is NULL
#include "f_io.h"
#include "f_print.h"
void file_example(void)
{
char *file_name;
char mode;
t_file *file;
mode = 'r'; // r - read, w - write, a - appened
file_name = "path/to/file.txt";
file = f_openf(file_name, mode);
char *line;
int ret;
t_file *out_file;
out_file = f_openf("out.txt", 'w');
int i = 0;
// To get a line from stdin replace file wth STDIN
while (f_next_line(&line, file))
{
f_fprintf(out_file, "[%d] %s\n", i++, line);
//f_fprintf can also take STDOUT or STDERR
free(line);
}
f_closef(file);
f_closef(out_file);
}
void put_nbr_err(int nbr)
parm: nbr - number to be written to stderr, fd=2
void f_putstr_err(char *str)
parm : str - string to be printed
Function to print null terminated char* to stderr, fd=2.
param: big - The value to be converted to little endian
return - the little endian value
This will be the opposite conversion to its counter part
Lexer is giving an error when file does not env on a with \n
** parm: path - path of the bin **
** parm: header - header to be written to binary. nb Size to changed to big endian **
This function will write to a file the bytecode for the corewar vm.
Suggestion create a char bin[max_program_size] and do a single write call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.