Fix field parsing
This commit is contained in:
10
lexer.kl
10
lexer.kl
@@ -1,4 +1,14 @@
|
|||||||
|
Lex_Stream :: struct
|
||||||
|
stream: String
|
||||||
|
offset: int
|
||||||
|
|
||||||
|
lexc :: (s: *Lex_Stream): String // @todo U8 U S
|
||||||
|
return s.stream + s.offset // @todo parsing fields wrong + s.offset // + s.offset @todo Actual string support
|
||||||
|
|
||||||
main :: ()
|
main :: ()
|
||||||
|
string_to_lex := "Identifier 2425525 Not_Number"
|
||||||
|
s := Lex_Stream(stream=string_to_lex)
|
||||||
|
|
||||||
|
for inf:=0, inf, inf // @todo for
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
5
main.cpp
5
main.cpp
@@ -43,7 +43,6 @@ For now I don't thing it should be overloadable.
|
|||||||
[ ] - Switch
|
[ ] - Switch
|
||||||
[ ] - More basic types
|
[ ] - More basic types
|
||||||
[ ] - Array of inferred size
|
[ ] - Array of inferred size
|
||||||
[ ] - Lexer: Need to insert scope endings when hitting End of file
|
|
||||||
[ ] - Add single line lambda expressions
|
[ ] - Add single line lambda expressions
|
||||||
|
|
||||||
@ideas
|
@ideas
|
||||||
@@ -61,6 +60,7 @@ For now I don't thing it should be overloadable.
|
|||||||
[x] - Default values in calls
|
[x] - Default values in calls
|
||||||
[x] - Resolving calls with default values
|
[x] - Resolving calls with default values
|
||||||
[x] - Pass statement
|
[x] - Pass statement
|
||||||
|
[x] - Lexer: Need to insert scope endings when hitting End of file
|
||||||
[x] - Resolving calls with named args, with indexed args
|
[x] - Resolving calls with named args, with indexed args
|
||||||
[x] - Structs
|
[x] - Structs
|
||||||
[x] - Struct field access
|
[x] - Struct field access
|
||||||
@@ -109,11 +109,10 @@ int main(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
result = compile_file("lexer.kl"_s);
|
result = compile_file("lexer.kl"_s);
|
||||||
|
|
||||||
FILE *f = fopen("program.c", "w");
|
FILE *f = fopen("program.c", "w");
|
||||||
assert(f);
|
assert(f);
|
||||||
fprintf(f, "%.*s", (int)result.len, result.str);
|
fprintf(f, "%.*s", (int)result.len, result.str);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
__debugbreak();
|
// __debugbreak();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ function Ast_Named *parse_named(B32);
|
|||||||
function Ast_Block *
|
function Ast_Block *
|
||||||
parse_block(){
|
parse_block(){
|
||||||
Ast_Block *block = 0;
|
Ast_Block *block = 0;
|
||||||
if(token_match(OPEN_SCOPE)){
|
if(token_expect(OPEN_SCOPE)){ // @todo: Fix error message here, it doesn't show proper token context
|
||||||
Token *token_block = token_get();
|
Token *token_block = token_get();
|
||||||
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
@@ -392,7 +392,7 @@ left_denotation(Token *op, Ast_Expr *left){
|
|||||||
function S64
|
function S64
|
||||||
postfix_binding_power(Token_Kind kind){
|
postfix_binding_power(Token_Kind kind){
|
||||||
switch(kind){
|
switch(kind){
|
||||||
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 1;
|
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 3;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,17 +405,16 @@ parse_expr(S64 rbp){
|
|||||||
token = token_get();
|
token = token_get();
|
||||||
|
|
||||||
// @note: parse postfix
|
// @note: parse postfix
|
||||||
if(postfix_binding_power(token->kind) > rbp){
|
S64 pbp = postfix_binding_power(token->kind);
|
||||||
|
if(pbp > rbp){
|
||||||
token_next();
|
token_next();
|
||||||
switch(token->kind){
|
switch(token->kind){
|
||||||
case TK_Dot: {
|
case TK_Dot: {
|
||||||
// @note: making sure that we always get a configuration where
|
Ast_Expr *right = parse_expr(pbp-1);
|
||||||
// Identifier is in left node
|
|
||||||
Ast_Expr *right = parse_expr();
|
|
||||||
left = ast_expr_binary(left, right, token);
|
left = ast_expr_binary(left, right, token);
|
||||||
}break;
|
}break;
|
||||||
case TK_OpenBracket:{
|
case TK_OpenBracket:{
|
||||||
Ast_Expr *index = parse_expr();
|
Ast_Expr *index = parse_expr(pbp-1);
|
||||||
left = ast_expr_index(token, left, index);
|
left = ast_expr_index(token, left, index);
|
||||||
token_expect(TK_CloseBracket);
|
token_expect(TK_CloseBracket);
|
||||||
}break;
|
}break;
|
||||||
@@ -423,6 +422,7 @@ parse_expr(S64 rbp){
|
|||||||
left = parse_expr_call(left);
|
left = parse_expr_call(left);
|
||||||
}break;
|
}break;
|
||||||
default:{
|
default:{
|
||||||
|
assert(token->kind == TK_Increment || token->kind == TK_Decrement);
|
||||||
if(token->kind == TK_Increment) token->kind = TK_PostIncrement;
|
if(token->kind == TK_Increment) token->kind = TK_PostIncrement;
|
||||||
else if(token->kind == TK_Decrement) token->kind = TK_PostDecrement;
|
else if(token->kind == TK_Decrement) token->kind = TK_PostDecrement;
|
||||||
left = ast_expr_unary(token, token->kind, left);
|
left = ast_expr_unary(token, token->kind, left);
|
||||||
|
|||||||
15
program.c
15
program.c
@@ -4,6 +4,17 @@
|
|||||||
#define NULL_LAMBDA 0
|
#define NULL_LAMBDA 0
|
||||||
//-------------------------------
|
//-------------------------------
|
||||||
|
|
||||||
static void main(){
|
struct Lex_Stream{
|
||||||
//pass
|
String stream;
|
||||||
|
int offset;
|
||||||
|
};
|
||||||
|
static String lexc(Lex_Stream *s){
|
||||||
|
return s->stream;
|
||||||
|
}
|
||||||
|
static void main(){
|
||||||
|
String string_to_lex = LIT("Identifier 2425525 Not_Number");
|
||||||
|
Lex_Stream s = (Lex_Stream ){.stream = string_to_lex};
|
||||||
|
for(int inf = 0;inf;inf){
|
||||||
|
//pass
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user