Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression parser #9

Merged
merged 75 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
b6dcd99
Add a grammar base
mifka01 Oct 18, 2023
b4d9b98
Refactor grammar markdown
mifka01 Oct 18, 2023
ea5ef87
Refactor grammar markdown added breaks
mifka01 Oct 18, 2023
38f5521
Update grammar.md
loumadev Oct 19, 2023
ae04c45
Remove inintializer comment in grammar
mifka01 Oct 21, 2023
d947e78
Add if statement parsing
mifka01 Oct 21, 2023
67bb9dc
Add while statement parsing
mifka01 Oct 21, 2023
2444dd0
Add return statement parsing
mifka01 Oct 21, 2023
81e315e
Add function call parsing
mifka01 Oct 21, 2023
7302768
Add variable declaration parsing
mifka01 Oct 22, 2023
22abfe2
Add new files Expressions.h and Expressions.c
Korunka1 Oct 27, 2023
07b3fc9
Add assignment statement
mifka01 Oct 28, 2023
613f314
Add new AST nodes, functions for creating them, expression parsing wi…
Korunka1 Oct 29, 2023
8b71036
Update src/compiler/parser/ASTNodes.c
loumadev Oct 30, 2023
a24846e
Update src/compiler/parser/ASTNodes.c
loumadev Oct 30, 2023
5aaee47
small changes in syntax after code review, first test for expression …
Korunka1 Nov 3, 2023
b0cd65f
new tests for expression parser
Korunka1 Nov 4, 2023
8203d0f
Merge branch 'master' of https://github.com/loumadev/IFJ2023 into exp…
Korunka1 Nov 4, 2023
5d150df
some new errors
Korunka1 Nov 5, 2023
7337723
remove test file
Korunka1 Nov 6, 2023
a22f7ef
small syntax changes
Korunka1 Nov 6, 2023
d089e27
Merge branch 'master' of https://github.com/loumadev/IFJ2023 into exp…
Korunka1 Nov 6, 2023
7c0bf52
syntax changes
Korunka1 Nov 6, 2023
7769fd7
untested expression parser, added error handling and memory managing
Korunka1 Nov 10, 2023
49a2acd
removed some comments
Korunka1 Nov 10, 2023
0ba5e4f
Merge remote-tracking branch 'origin/parser' into expressionParser
loumadev Nov 12, 2023
90074c9
Renamed `Expressions` to `ExpressionParser`
loumadev Nov 12, 2023
130f57b
Changed formatting
loumadev Nov 12, 2023
e093ef5
Added ability to pass `Lexer` instance directly to `Parser` constructor
loumadev Nov 12, 2023
85d6a6a
Modified definition of `Expr_getTopTerminal` to prevent copying data
loumadev Nov 12, 2023
4a587b1
Added message why the segfault is caused
loumadev Nov 12, 2023
9882b80
Added test files for `Parser` and `ExpressionParser`
loumadev Nov 12, 2023
6311469
Fixed token no properly consuming
loumadev Nov 13, 2023
305a9e0
fixed segfault + syntax changes
Korunka1 Nov 14, 2023
80b43ba
Merge branch 'expressionParser' of https://github.com/loumadev/IFJ202…
Korunka1 Nov 14, 2023
380288f
Fix brackets parsing in Block
mifka01 Nov 14, 2023
3ac5ee7
Fix peeking on zero in parseStatements
mifka01 Nov 14, 2023
19194c6
Renamed `name`s to `id`s
loumadev Nov 14, 2023
dcb24c0
Renamed `name`s in function declarations
loumadev Nov 14, 2023
401dc44
Renamed `enum OperatorType` to just `OperatorType` cuz vs code didn't…
loumadev Nov 14, 2023
5ce26d7
Added `LiteralType` info to `LiteralExpressionASTNode`
loumadev Nov 14, 2023
ffc500e
Fixed typo
loumadev Nov 14, 2023
1f9f2bc
Added/fixed include guards
loumadev Nov 14, 2023
5cdf62e
Sorted includes
loumadev Nov 14, 2023
d11c595
Added helper macros for testing parser
loumadev Nov 14, 2023
1b55518
Finished example parser test
loumadev Nov 14, 2023
7e06202
Fixed `__Parser_parseCondition` consuming `(` without actually making…
loumadev Nov 14, 2023
b831cdc
Fixed `if(let a)` being a valid statement
loumadev Nov 14, 2023
819e775
Fixed `LexerToParserError` improperly propagating result type and sev…
loumadev Nov 15, 2023
1603e0f
Added and renamed some of the `ResultType`s
loumadev Nov 15, 2023
7088827
Add variable declaration tests
mifka01 Nov 15, 2023
ae9235d
Refactor variable declaration tests
mifka01 Nov 15, 2023
2ff690f
Add function declaration tests
mifka01 Nov 15, 2023
5752cc1
Fix optional parameter initializer
mifka01 Nov 15, 2023
3b354f6
Added strings tokenizations + interpolated string support + tests
loumadev Nov 15, 2023
9759145
Merge branch 'expressionParser' of https://github.com/loumadev/IFJ202…
loumadev Nov 15, 2023
ed325a9
Add basic if statement parsing
mifka01 Nov 15, 2023
6b7e66d
Updated some comments
loumadev Nov 16, 2023
0fc69f2
Added more macros for matching whitespace
loumadev Nov 16, 2023
238be77
Simplified the `whitespace_consistent` macro
loumadev Nov 16, 2023
2ba9d63
'if (true)' bug fix
Korunka1 Nov 16, 2023
b6605d2
Change test lexer source
mifka01 Nov 16, 2023
3100438
Fix consuming optinal closing param
mifka01 Nov 16, 2023
3cd444f
Fix not consuming if keyword in else if
mifka01 Nov 16, 2023
9e9a283
Fix array name in statements macro
mifka01 Nov 17, 2023
b4f9559
Add tests for binding condition
mifka01 Nov 17, 2023
d40b2b0
Add simple tests for while statement
mifka01 Nov 17, 2023
c022367
Replace unnecessary ElseClauseASTNode
mifka01 Nov 17, 2023
083fab9
Moved error descriptions inline to each enum item
loumadev Nov 18, 2023
346fdc6
Added `LF` macro + fixed formatting
loumadev Nov 18, 2023
d15ad2e
Fixed bug when parsing two variable declarations right after another
loumadev Nov 18, 2023
949093a
Added check for statement separation + very light tests
loumadev Nov 18, 2023
4600109
Introduced new memory allocation function `mem_recalloc`
loumadev Nov 18, 2023
c5d4a45
Fixed array resizing allocation bug
loumadev Nov 18, 2023
6236fad
Added ability to specify a priority of the test file
loumadev Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/allocator/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ enum AllocatorAction {
MEMORY_ALLOC,
MEMORY_CALLOC,
MEMORY_REALLOC,
MEMORY_RECALLOC,
MEMORY_FREE,
MEMORY_CLEANUP
};

void* mem_alloc(size_t size);
void* mem_calloc(size_t nitems, size_t size);
void* mem_realloc(void *ptr, size_t size);
void* mem_recalloc(void *ptr, size_t oldNitems, size_t nitems, size_t size);
void mem_free(void *ptr);

void* safe_malloc(size_t size);
Expand Down
37 changes: 11 additions & 26 deletions include/compiler/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "internal/String.h"
#include "internal/Array.h"

#ifndef PARSER_H
#define PARSER_H
#ifndef RESULT_H
#define RESULT_H

enum Severity {
SEVERITY_NONE = 0,
Expand All @@ -12,35 +12,20 @@ enum Severity {
SEVERITY_INFO
};


/*

• 1 - chyba v programu v rámci lexikální analýzy (chybná struktura aktuálního lexému).
• 2 - chyba v programu v rámci syntaktické analýzy (chybná syntaxe programu, chybějící hlavička, atp.).
• 3 - sémantická chyba v programu – nedefinovaná funkce, pokus o redefinice funkce.
• 4 - sémantická/běhová chyba v programu – špatný počet/typ parametrů u volání funkce či typ návratové hodnoty z funkce.
• 5 - sémantická chyba v programu – použití nedefinované proměnné.
• 6 - sémantická/běhová chyba v programu – chybějící/přebývající výraz v příkazu návratu z funkce.
• 7 - sémantická/běhová chyba typové kompatibility v aritmetických, řetězcových a
relačních výrazech.
• 8 - ostatní sémantické chyby.
• 99 - interní chyba překladače tj. neovlivněná vstupním programem (např. chyba alokace paměti atd.).



*/
enum ResultType {
RESULT_INVALID = -3,
RESULT_NO_MATCH = -2,
RESULT_ASSERTION = -1,
RESULT_SUCCESS = 0,
RESULT_ERROR_STATIC_LEXICAL_ANALYSIS = 1,
RESULT_ERROR_STATIC_SYNTACTIC_ANALYSIS = 2,
// TODO: Add more error types
RESULT_ERROR_SEMANTIC_FUNCTION = 3,
RESULT_ERROR_RUNTIME_UNDEFINED_VARIABLE = 5,
RESULT_ERROR_SEMANTIC_OTHER = 8,
RESULT_ERROR_INTERNAL = 99
RESULT_ERROR_LEXICAL_ANALYSIS = 1, // Chybná struktura aktuálního lexému
RESULT_ERROR_SYNTACTIC_ANALYSIS = 2, // Chybná syntaxe programu, chybějící hlavička, atp.
RESULT_ERROR_SEMANTIC_FUNCTION_DEFINITION = 3, // Nedefinovaná funkce, pokus o redefinice funkce
RESULT_ERROR_SEMANTIC_INVALID_FUNCTION_CALL = 4, // Špatný počet/typ parametrů u volání funkce či typ návratové hodnoty z funkce
RESULT_ERROR_SEMANTIC_UNDEFINED_VARIABLE = 5, // Použití nedefinované proměnné
RESULT_ERROR_SEMANTIC_INVALID_RETURN = 6, // Chybějící/přebývající výraz v příkazu návratu z funkce
RESULT_ERROR_SEMANTIC_INVALID_TYPE = 7, // Chyba typové kompatibility v aritmetických, řetězcových a relačních výrazech
RESULT_ERROR_SEMANTIC_OTHER = 8, // Ostatní sémantické chyby
RESULT_ERROR_INTERNAL = 99 // Interní chyba překladače tj. neovlivněná vstupním programem (např. chyba alokace paměti atd.)
};

typedef struct Result {
Expand Down
2 changes: 1 addition & 1 deletion include/compiler/lexer/LexerResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ LexerResult LexerResult_construct(

#define LexerSuccess() LexerResult_construct(RESULT_SUCCESS, SEVERITY_NONE, NULL, NULL, NULL)
#define LexerNoMatch() LexerResult_construct(RESULT_NO_MATCH, SEVERITY_NONE, NULL, NULL, NULL)
#define LexerError(message, markers) LexerResult_construct(RESULT_ERROR_STATIC_LEXICAL_ANALYSIS, SEVERITY_ERROR, message, markers, NULL)
#define LexerError(message, markers) LexerResult_construct(RESULT_ERROR_LEXICAL_ANALYSIS, SEVERITY_ERROR, message, markers, NULL)

#endif
22 changes: 15 additions & 7 deletions include/compiler/lexer/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum TokenType {
TOKEN_EOF = 1,
TOKEN_CONTROL, // Forgot what this is for :(
TOKEN_MARKER, // Marker in the source code (for error messages)
TOKEN_STRING_INTERPOLATION_MARKER,

TOKEN_LITERAL,
TOKEN_IDENTIFIER,
Expand All @@ -21,6 +22,9 @@ enum TokenKind {
TOKEN_DEFAULT = 0,

// Literals
// This has to be at this position in the enum
// because it's being converted into another
// enum with the same values.
TOKEN_STRING,
TOKEN_INTEGER,
TOKEN_FLOATING,
Expand Down Expand Up @@ -67,13 +71,13 @@ enum TokenKind {
enum WhitespaceType {
WHITESPACE_NONE = 0, // No whitespace

// WHITESPACE_LEFT_LIMIT = 1 << 0, // BOF or EOF
WHITESPACE_LEFT_SPACE = 1 << 1, // Space, tab, or vertical tab
WHITESPACE_LEFT_NEWLINE = 1 << 2, // Line feed or carriage return
// WHITESPACE_LEFT_LIMIT = 1 << 0, // BOF or EOF
WHITESPACE_LEFT_SPACE = 1 << 1, // Space, tab, vertical tab or multi-line comment on a single line
WHITESPACE_LEFT_NEWLINE = 1 << 2, // Line feed, carriage return, multi-line comment on multiple lines or single-line comment

// WHITESPACE_RIGHT_LIMIT = 1 << 4, // BOF or EOF
WHITESPACE_RIGHT_SPACE = 1 << 5, // Space, tab, or vertical tab
WHITESPACE_RIGHT_NEWLINE = 1 << 6, // Line feed or carriage return
// WHITESPACE_RIGHT_LIMIT = 1 << 4, // BOF or EOF
WHITESPACE_RIGHT_SPACE = 1 << 5, // Space, tab, vertical tab or multi-line comment on a single line
WHITESPACE_RIGHT_NEWLINE = 1 << 6, // Line feed, carriage return, multi-line comment on multiple lines or single-line comment

WHITESPACE_LEFT = WHITESPACE_LEFT_SPACE | WHITESPACE_LEFT_NEWLINE,
WHITESPACE_RIGHT = WHITESPACE_RIGHT_SPACE | WHITESPACE_RIGHT_NEWLINE,
Expand All @@ -83,7 +87,11 @@ enum WhitespaceType {
WHITESPACE_MASK_RIGHT = /*WHITESPACE_RIGHT_LIMIT |*/ WHITESPACE_RIGHT_SPACE | WHITESPACE_RIGHT_NEWLINE
};

#define whitespace_both(whitespace) (((whitespace) & WHITESPACE_LEFT) && ((whitespace) & WHITESPACE_RIGHT))
#define whitespace_left(whitespace) ((whitespace) & WHITESPACE_LEFT)
#define whitespace_right(whitespace) ((whitespace) & WHITESPACE_RIGHT)
#define whitespace_both(whitespace) (whitespace_left(whitespace) && whitespace_right(whitespace))
#define whitespace_none(whitespace) ((whitespace) == WHITESPACE_NONE)
#define whitespace_consistent(whitespace) (whitespace_both(whitespace) || whitespace_none(whitespace))

#define right_to_left_whitespace(whitespace) (((whitespace) & WHITESPACE_RIGHT) >> 4)
#define left_to_right_whitespace(whitespace) (((whitespace) & WHITESPACE_LEFT) << 4)
Expand Down
180 changes: 156 additions & 24 deletions include/compiler/parser/ASTNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "internal/Array.h"
#include "internal/String.h"
#include "compiler/lexer/Token.h"

#ifndef ASTNode_H
#define ASTNode_H
Expand All @@ -13,15 +14,52 @@ enum ASTNodeType {
NODE_IDENTIFIER,
NODE_TYPE_REFERENCE,
NODE_VARIABLE_DECLARATION,
NODE_VARIABLE_DECLARATION_LIST,
NODE_VARIABLE_DECLARATOR,
NODE_EXPRESSION_STATEMENT,
NODE_RETURN_STATEMENT,
NODE_PARAMETER,
NODE_PARAMETER_LIST,
NODE_FUNCTION_DECLARATION,
NODE_ARGUMENT,
NODE_FUNCTION_CALL
NODE_BINARY_EXPRESSION,
NODE_UNARY_EXPRESSION,
NODE_LITERAL_EXPRESSION,
NODE_ARGUMENT_LIST,
NODE_FUNCTION_CALL,
NODE_IF_STATEMENT,
NODE_PATTERN,
NODE_CONDITION,
NODE_OPTIONAL_BINDING_CONDITION,
NODE_WHILE_STATEMENT,
NODE_ASSIGNMENT_STATEMENT
};

typedef enum OperatorType {
OPERATOR_DEFAULT = 0,
OPERATOR_PLUS,
OPERATOR_MINUS,
OPERATOR_MUL,
OPERATOR_DIV,
OPERATOR_UNWRAP,
OPERATOR_NULL_COALESCING,
OPERATOR_EQUAL,
OPERATOR_NOT_EQUAL,
OPERATOR_LESS,
OPERATOR_GREATER,
OPERATOR_LESS_EQUAL,
OPERATOR_GREATER_EQUAL
} OperatorType;

typedef enum LiteralType {
LITERAL_INVALID = 0,
LITERAL_STRING,
LITERAL_INTEGER,
LITERAL_FLOATING,
LITERAL_BOOLEAN,
LITERAL_NIL
} LiteralType;


/* Definition of AST nodes */

Expand Down Expand Up @@ -53,10 +91,21 @@ typedef struct TypeReferenceASTNode {
bool isNullable;
} TypeReferenceASTNode;

typedef struct VariableDeclaratorASTNode {
enum ASTNodeType _type;
struct PatternASTNode *pattern;
ExpressionASTNode *initializer;
} VariableDeclaratorASTNode;

typedef struct VariableDeclarationListASTNode {
enum ASTNodeType _type;
Array /*<VariableDeclaratorASTNode>*/ *declarators;
} VariableDeclarationListASTNode;

typedef struct VariableDeclarationASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
TypeReferenceASTNode *type;
VariableDeclarationListASTNode *declaratorList;
bool isConstant;
} VariableDeclarationASTNode;

typedef struct ExpressionStatementASTNode {
Expand All @@ -71,10 +120,10 @@ typedef struct ReturnStatementASTNode {

typedef struct ParameterASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
IdentifierASTNode *internalId;
TypeReferenceASTNode *type;
ExpressionASTNode *initializer;
IdentifierASTNode *externalName;
IdentifierASTNode *externalId;
bool isLabeless;
} ParameterASTNode;

Expand All @@ -83,12 +132,6 @@ typedef struct ParameterListASTNode {
Array /*<ParameterASTNode>*/ *parameters;
} ParameterListASTNode;

typedef struct ArgumentASTNode {
enum ASTNodeType _type;
ExpressionASTNode *expression;
IdentifierASTNode *label;
} ArgumentASTNode;

typedef struct FunctionDeclarationASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
Expand All @@ -97,35 +140,124 @@ typedef struct FunctionDeclarationASTNode {
BlockASTNode *body;
} FunctionDeclarationASTNode;

typedef struct ArgumentASTNode {
enum ASTNodeType _type;
ExpressionASTNode *expression;
IdentifierASTNode *label;
} ArgumentASTNode;

typedef struct ArgumentListASTNode {
enum ASTNodeType _type;
Array /*<ArgumentASTNode>*/ *arguments;
} ArgumentListASTNode;

typedef struct FunctionCallASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
Array /*<ArgumentASTNode>*/ *arguments;
ArgumentListASTNode *argumentList;
} FunctionCallASTNode;

// typedef struct ExpressionASTNode {
// enum ASTNodeType _type;
// BinaryExpressionASTNode *BExpression;
// UnaryExpressionASTNode *UExpression;
// LiteralExpressionASTNode *LExpression;
// IdentifierASTNode *IExpression;
// } ExpressionASTNode;

typedef struct BinaryExpressionASTNode {
enum ASTNodeType _type;
ExpressionASTNode *left;
ExpressionASTNode *right;
OperatorType operator;
} BinaryExpressionASTNode;

typedef struct UnaryExpressionASTNode {
enum ASTNodeType _type;
ExpressionASTNode *argument;
OperatorType operator;
// bool isPrefix;
} UnaryExpressionASTNode;

typedef struct LiteralExpressionASTNode {
enum ASTNodeType _type;
LiteralType type;
union TokenValue value;
} LiteralExpressionASTNode;

typedef struct PatternASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
TypeReferenceASTNode *type;
} PatternASTNode;

typedef struct OptionalBindingConditionASTNode {
enum ASTNodeType _type;
PatternASTNode *pattern;
ExpressionASTNode *initializer;
bool isConstant;
} OptionalBindingConditionASTNode;

typedef struct ConditionASTNode {
enum ASTNodeType _type;
ExpressionASTNode *expression;
OptionalBindingConditionASTNode *optionalBindingCondition;
} ConditionASTNode;

typedef struct IfStatementASTNode {
enum ASTNodeType _type;
ConditionASTNode *condition;
BlockASTNode *body;
ASTNode /* BlockASTNode | IfStatementASTNode | null */ *alternate;
} IfStatementASTNode;

typedef struct WhileStatementASTNode {
enum ASTNodeType _type;
ConditionASTNode *condition;
BlockASTNode *body;
} WhileStatementASTNode;

typedef struct AssignmentStatementASTNode {
enum ASTNodeType _type;
IdentifierASTNode *id;
ExpressionASTNode *assignment;
} AssignmentStatementASTNode;

// TODO: Add more AST nodes


/* Constructors for AST nodes */

ProgramASTNode * new_ProgramASTNode(BlockASTNode *block);
BlockASTNode * new_BlockASTNode(Array *statements);
IdentifierASTNode * new_IdentifierASTNode(String *name);
TypeReferenceASTNode * new_TypeReferenceASTNode(IdentifierASTNode *id, bool isNullable);
VariableDeclarationASTNode * new_VariableDeclarationASTNode(IdentifierASTNode *id, TypeReferenceASTNode *type);
ReturnStatementASTNode * new_ReturnStatementASTNode(ExpressionASTNode *expression);
ParameterASTNode * new_ParameterASTNode(IdentifierASTNode *id, TypeReferenceASTNode *type, ExpressionASTNode *initializer, IdentifierASTNode *externalName, bool isLabeless);
ParameterListASTNode * new_ParameterListASTNode(Array *parameters);
ArgumentASTNode * new_ArgumentASTNode(ExpressionASTNode *expression, IdentifierASTNode *label);
FunctionDeclarationASTNode * new_FunctionDeclarationASTNode(IdentifierASTNode *id, ParameterListASTNode *parameterList, TypeReferenceASTNode *returnType, BlockASTNode *body);
FunctionCallASTNode * new_FunctionCallASTNode(IdentifierASTNode *id, Array *arguments);
ProgramASTNode* new_ProgramASTNode(BlockASTNode *block);
BlockASTNode* new_BlockASTNode(Array *statements);
IdentifierASTNode* new_IdentifierASTNode(String *name);
TypeReferenceASTNode* new_TypeReferenceASTNode(IdentifierASTNode *id, bool isNullable);
VariableDeclarationASTNode* new_VariableDeclarationASTNode(VariableDeclarationListASTNode *declaratorList, bool isConstant);
VariableDeclaratorASTNode* new_VariableDeclaratorASTNode(PatternASTNode *pattern, ExpressionASTNode *initializer);
VariableDeclarationListASTNode* new_VariableDeclarationListASTNode(Array *declarators);
ReturnStatementASTNode* new_ReturnStatementASTNode(ExpressionASTNode *expression);
ParameterASTNode* new_ParameterASTNode(IdentifierASTNode *internalId, TypeReferenceASTNode *type, ExpressionASTNode *initializer, IdentifierASTNode *externalId, bool isLabeless);
ParameterListASTNode* new_ParameterListASTNode(Array *parameters);
FunctionDeclarationASTNode* new_FunctionDeclarationASTNode(IdentifierASTNode *id, ParameterListASTNode *parameterList, TypeReferenceASTNode *returnType, BlockASTNode *body);
BinaryExpressionASTNode* new_BinaryExpressionASTNode(ExpressionASTNode *left, ExpressionASTNode *right, OperatorType operator);
UnaryExpressionASTNode* new_UnaryExpressionASTNode(ExpressionASTNode *argument, OperatorType operator /*, bool isPrefix*/);
LiteralExpressionASTNode* new_LiteralExpressionASTNode(LiteralType type, union TokenValue value);
ArgumentASTNode* new_ArgumentASTNode(ExpressionASTNode *expression, IdentifierASTNode *label);
ArgumentListASTNode* new_ArgumentListASTNode(Array *arguments);
FunctionCallASTNode* new_FunctionCallASTNode(IdentifierASTNode *id, ArgumentListASTNode *argumentList);
PatternASTNode* new_PatternASTNode(IdentifierASTNode *id, TypeReferenceASTNode *type);
OptionalBindingConditionASTNode* new_OptionalBindingConditionASTNode(PatternASTNode *pattern, ExpressionASTNode *initializer, bool isConstant);
ConditionASTNode* new_ConditionASTNode(ExpressionASTNode *expression, OptionalBindingConditionASTNode *optionalBindingCondition);
IfStatementASTNode* new_IfStatementASTNode(ConditionASTNode *condition, BlockASTNode *body, ASTNode *alternate);
WhileStatementASTNode* new_WhileStatementASTNode(ConditionASTNode *condition, BlockASTNode *body);
AssignmentStatementASTNode* new_AssignmentStatementASTNode(IdentifierASTNode *id, ExpressionASTNode *assignment);

// TODO: Add more AST node constructors


/* Other public functions */

ASTNode * ASTNode_alloc(size_t size, enum ASTNodeType type);
ASTNode* ASTNode_alloc(size_t size, enum ASTNodeType type);
void ASTNode_free(ASTNode *node);

void ASTNode_print(ASTNode *node);
Expand Down
Loading
Loading