Skip to content

Commit

Permalink
Merge pull request #2 from ReCT-Lang/dev
Browse files Browse the repository at this point in the history
Pretty much completed the parser architecture.
  • Loading branch information
Khhs167 authored Jan 28, 2024
2 parents f220262 + 6bfec68 commit 5c7017a
Show file tree
Hide file tree
Showing 10 changed files with 501 additions and 96 deletions.
16 changes: 8 additions & 8 deletions docs/ACCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ that we should try and give each one a purpose.

| Name | Effect |
|---------|------------------------------------------|
| private | private |
| set | public |
| private | May only be accessed within scope |
| set | May be accessed outside scope |
| static | class-wide(not on instances) |
| unsafe | unmanaged code allowed(pointers) |
| extern | External(may not define function body) |
Expand All @@ -22,9 +22,9 @@ resolved from external binaries.

## Valid access modifiers on different "items"

| Item | Valid modifiers |
|-----------|----------------------------------|
| variables | var, set, static, extern |
| functions | var, set, static, unsafe, extern |
| classes | var, set, static, unsafe |
| structs | var, set, unsafe |
| Item | Valid modifiers |
|-----------|--------------------------------------|
| variables | private, set, static, extern |
| functions | private, set, static, unsafe, extern |
| classes | private, set, static, unsafe |
| structs | private, set, unsafe |
5 changes: 4 additions & 1 deletion src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static int is_char_numeric(int c) {

// We allow A-Z in any capitalization plus underscores in the start of a word/identifier
static int is_char_word_starter(int c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_';
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == '@';
}
// Then 2nd character onward allows us to do numbers tool.
static int is_char_word(int c) {
Expand Down Expand Up @@ -382,6 +382,9 @@ void lexer_process(lexer_context* context) {
CASE_SIMPLE_MULT("<=", TOKEN_OP_LT_EQUALS)
CASE_SIMPLE_MULT(">=", TOKEN_OP_GR_EQUALS)

CASE_SIMPLE_MULT("++", TOKEN_INCREMENT)
CASE_SIMPLE_MULT("--", TOKEN_DECREMENT)

CASE_SIMPLE('=', TOKEN_OP_EQUALS)

CASE_SIMPLE('<', TOKEN_OP_LT)
Expand Down
9 changes: 8 additions & 1 deletion src/lexer/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ typedef enum token_type_e {
TOKEN_TRUE,
TOKEN_FALSE,

TOKEN_INCREMENT,
TOKEN_DECREMENT,

TOKEN_OP_PLUS,
TOKEN_OP_MINUS,
TOKEN_OP_MOD,
Expand Down Expand Up @@ -67,7 +70,11 @@ typedef enum token_type_e {

TOKEN_PACKAGE_ACCESS,

TOKEN_END_STMT
TOKEN_END_STMT,

// These are just for ease-of-work
TOKEN_GENERIC_OPEN = TOKEN_BRACKET_OPEN,
TOKEN_GENERIC_CLOSE = TOKEN_BRACKET_CLOSE,

} token_type_e;

Expand Down
2 changes: 2 additions & 0 deletions src/lexer/token_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const char* TOKEN_NAMES[] = {
"TOKEN_NUMERIC",
"TOKEN_TRUE",
"TOKEN_FALSE",
"TOKEN_INCREMENT",
"TOKEN_DECREMENT",
"TOKEN_OP_PLUS",
"TOKEN_OP_MINUS",
"TOKEN_OP_MOD",
Expand Down
16 changes: 15 additions & 1 deletion src/parser/nodes.hgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
PERMS_NONE = 0
} permissions;
typedef enum operators {
OP_NONE,
OP_ADD,
OP_SUBTRACT,
OP_DIVIDE,
OP_MULTIPLY
} operators;
typedef enum {
\tNODE_NULL,
\t'''
Expand Down Expand Up @@ -87,6 +95,10 @@
};
static void print_node_list(const char* name, node_list* list, int indent) {
if(list->length == 0) {
printf("%*s%s: NULL\\n", indent * 4, "", name);
return;
}
printf("%*s%s:\\n", indent * 4, "", name);
for (int i = 0; i < list->length; ++i) {
print_node(list->data[i], NULL, indent + 1);
Expand Down Expand Up @@ -141,8 +153,10 @@
output += "\tprint_int(\"" + name + "\", n->" + name + ", indent + 1);\n"
elif fields[name] == "permissions": # Perms is just an int for now.
output += "\tprint_int(\"" + name + "\", n->" + name + ", indent + 1);\n"
elif fields[name] == "operators": # Same for operators
output += "\tprint_int(\"" + name + "\", n->" + name + ", indent + 1);\n"
elif fields[name] == "node":
output += "\tprint_node(n->" + name + ", \"\", indent + 1);\n"
output += "\tprint_node(n->" + name + ", \"" + name + "\", indent + 1);\n"
elif fields[name] in definitions:
output += "\tprint_" + fields[name] + "(n->" + name + ", \"" + name + "\", indent + 1);\n"

Expand Down
41 changes: 37 additions & 4 deletions src/parser/nodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
"node_class_def": {
"name": "string",
"flags": "permissions",
"children": "node_list"
"body": "node_body",
"generics": "node_list"
},
"node_struct_def": {
"name": "string",
"flags": "permissions"
"flags": "permissions",
"body": "node_body"
},
"node_function_def": {
"name": "string",
"flags": "permissions",
"return_type": "node_identifier",
"body": "node_function_body"
"body": "node_body",
"parameters": "node_list"
},
"node_enum_def": {
"name": "string",
Expand All @@ -33,7 +36,7 @@
"child": "node_identifier",
"generic_values": "node_list"
},
"node_function_body": {
"node_body": {
"children": "node_list"
},
"node_variable_def": {
Expand All @@ -42,7 +45,37 @@
"value_type": "node_identifier",
"default_value": "node"
},
"node_parameter": {
"name": "string",
"value_type": "node_identifier",
"default_value": "node"
},
"node_literal": {
"value": "string"
},
"node_assignation": {
"operator": "operators",
"target": "node_identifier",
"value": "node"
},
"node_unary_exp": {
"operator": "operators",
"operand": "node"
},
"node_binary_exp": {
"operator": "operators",
"left": "node",
"right": "node"
},
"node_function_call": {
"target": "node_identifier",
"parameters": "node_list"
},
"node_make": {
"target": "node_identifier",
"parameters": "node_list"
},
"node_return": {
"value": "node"
}
}
Loading

0 comments on commit 5c7017a

Please sign in to comment.