-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory issues in lexer and tokenise some extra stuff
- change VAR token to NAME so it doubles as the token for functions (also tokenising those now) - replace op tokens with BINARY_OP and UNARY_OP tokens (also parsing unary minus now) - added null byte to end of string when reading file (lexer didn't properly know when to stop, causing invalid read) - also made a failed (uncommitted) attempt at a parser
- Loading branch information
Showing
11 changed files
with
62 additions
and
95 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,3 +1,4 @@ | ||
build | ||
result | ||
experiments | ||
old |
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,3 +1,2 @@ | ||
hello there! | ||
this is some | ||
text. | ||
let a=abs(2+3-6)*-4 | ||
print a, "test" |
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,2 +1 @@ | ||
reM hello | ||
REm this is a commentntntntttt | ||
1+2*-3 |
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,6 +1,6 @@ | ||
REM this is a remark | ||
10 LET A=(2+3)*-4 | ||
REM another remark | ||
LET B="missing end quotes | ||
PRINT A, 567, "th1s i5 string" | ||
LET B = "missing end quotes | ||
PRINT A, 567, "th1s i5 a string" | ||
PRINT invalid token 12.34 |
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,9 +1,8 @@ | ||
REM this is a demo | ||
1 let A=2 | ||
1 let A = 2 | ||
REM this is another comment | ||
REM and so is this | ||
REM | ||
|
||
20 B=A+3*4 Rem 2+3*4=14 | ||
LET C=(A + 3) / a REM should be 5/2=2 | ||
|
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
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 |
---|---|---|
@@ -1 +0,0 @@ | ||
#include "parser.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +0,0 @@ | ||
#ifndef INCLUDE_PARSER_H | ||
#define INCLUDE_PARSER_H | ||
|
||
#include <stdlib.h> | ||
|
||
typedef enum { | ||
AST_ASSIGNMENT, | ||
AST_EXPRESSION, | ||
AST_STRING, | ||
AST_PRINT | ||
} ASTNodeType; | ||
|
||
typedef enum { | ||
MATH_OP_ADD, | ||
MATH_OP_SUB, | ||
MATH_OP_MUL, | ||
MATH_OP_DIV, | ||
MATH_OP_MOD, | ||
} MathOp; | ||
|
||
typedef struct { | ||
struct ASTExpression *exprs; | ||
size_t length; | ||
} ASTExpressionList; | ||
|
||
typedef struct ASTNode { | ||
ASTNodeType type; | ||
union { | ||
struct ASTExpression { | ||
MathOp op; | ||
struct ASTExpression *lhs; | ||
struct ASTExpression *rhs; | ||
} expr; | ||
struct ASTAssignment { | ||
char variable; | ||
struct ASTExpression *expr; | ||
} assingment; | ||
char *string; | ||
ASTExpressionList print; | ||
} node; | ||
} ASTNode; | ||
|
||
typedef struct { | ||
ASTNode nodes; | ||
size_t length; | ||
} AST; | ||
|
||
extern AST new_ast(); | ||
|
||
#endif // INCLUDE_PARSER_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