-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some things in member expression (#57 from wesuRage/main)
Fixed some things in member expression
- Loading branch information
Showing
5 changed files
with
103 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
bool isBigger := 3 > 2 ? 1 : 0; | ||
extern int printf( string ) ; | ||
extern int putchar( string ) ; | ||
|
||
def pedidor_de_socorrokk( string nome) -> int: | ||
|
||
printf( "socorro") ; | ||
putchar( "\n" ) ; | ||
|
||
return 0 ; | ||
end; | ||
|
||
def main( ) -> int: | ||
pedidor_de_socorrokk( "natan" ) ; | ||
pedidor_de_socorrokk( "bruno" ) ; | ||
pedidor_de_socorrokk( "casado" ) ; | ||
|
||
return 0 ; | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef PARSE_MEMBER_EXPR_H | ||
#define PARSE_MEMBER_EXPR_H | ||
|
||
#include "frontend/parser/core.h" | ||
|
||
AstNode *parse_member_expr(Parser *parser); | ||
|
||
#endif // PARSE_MEMBER_EXPR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "frontend/parser/expressions/parse_member_expr.h" | ||
#include "frontend/parser/expressions/parse_expr.h" | ||
#include "frontend/parser/expressions/parse_primary_expr.h" | ||
#include "utils.h" | ||
|
||
AstNode *parse_member_expr(Parser *parser) { | ||
int line = at(parser).line; | ||
int column_start_member = at(parser).column_start; | ||
int position_start_member = at(parser).position_start; | ||
|
||
AstNode *object = parse_primary_expr(parser); | ||
|
||
AstNode *current_member = object; | ||
|
||
while (at(parser).type == TOKEN_DOT) { | ||
eat(parser); | ||
|
||
if (at(parser).type != TOKEN_IDENTIFIER && at(parser).type != TOKEN_NUMBER) { | ||
error(parser, "Expected identifier or number after '.' in member expression."); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
int column_start_val = at(parser).column_start; | ||
int position_start_val = at(parser).position_start; | ||
|
||
AstNode *property = parse_expr(parser); | ||
if (!property) { | ||
error(parser, "Failed to parse property in member expression."); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
int column_end_val = at(parser).column_end - 1; | ||
int position_end_val = at(parser).position_end - 1; | ||
|
||
MemberPropertyNode *prop_data = MALLOC_S(sizeof(MemberPropertyNode)); | ||
prop_data->object = current_member; | ||
prop_data->property = property; | ||
|
||
AstNode *prop_node = create_ast_node( | ||
NODE_MEMBER_PROPERTY, | ||
prop_data, | ||
line, | ||
column_start_val, | ||
position_start_val, | ||
column_end_val, | ||
position_end_val | ||
); | ||
|
||
current_member = prop_node; | ||
} | ||
|
||
MemberNode *member_data = MALLOC_S(sizeof(MemberNode)); | ||
member_data->member = object; | ||
member_data->property = current_member; | ||
|
||
AstNode *member_node = create_ast_node( | ||
NODE_MEMBER, | ||
member_data, | ||
line, | ||
column_start_member, | ||
position_start_member, | ||
at(parser).column_end - 1, | ||
at(parser).position_end - 1 | ||
); | ||
|
||
return member_node; | ||
} |