Skip to content

Commit b458e3f

Browse files
Refactor code & add array but still no array index
1 parent 58dd123 commit b458e3f

File tree

4 files changed

+141
-210
lines changed

4 files changed

+141
-210
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ CritLang/bin
22
CritLang/obj
33
.vs
44
crit.exe
5+
CritLang/Properties/PublishProfiles/FolderProfile.pubxml
6+
CritLang/Properties/PublishProfiles/FolderProfile.pubxml.user
7+
CritLang/CritLang.csproj.user

CritLang/Content/Crit.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ assignment: IDENTIFIER '=' expression;
2020
functionCall: IDENTIFIER '(' (expression (',' expression)*)? ')';
2121

2222
expression
23-
: constant #constantExpression
23+
: constant (index)* #constantExpression
2424
| IDENTIFIER #identifierExpression
2525
| functionCall #functionCallExpression
2626
| '(' expression ')' #parenthesizedExpression
@@ -40,12 +40,14 @@ boolOp: BOOL_OPERATOR;
4040

4141
BOOL_OPERATOR: 'and' | 'or' | 'xor';
4242

43-
constant: INTEGER | FLOAT | STRING | BOOL | NULL;
43+
constant: INTEGER | FLOAT | STRING | BOOL | array | NULL;
4444

4545
INTEGER: [0-9]+;
4646
FLOAT: [0-9]+ '.' [0-9]+;
4747
STRING: ('"' ~'"'* '"') | ('\'' ~'\''* '\'');
4848
BOOL: 'true' | 'false';
49+
array: '[' (constant (',' constant)*)? ']';
50+
index: '[' INTEGER ']';
4951
NULL: 'null';
5052

5153

CritLang/Content/test.crit

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1 @@
1-
i = 1;
2-
name = "Lucas";
3-
Write("Hello " + name + "!\n");
4-
j = i + 1;
5-
6-
if j < i {
7-
WriteLine("J is smaller than i");
8-
}
9-
else if 4 > 5 {
10-
WriteLine("4 is bigger than 5");
11-
}
12-
else {
13-
WriteLine("ELSE");
14-
}
15-
16-
#COMMENT
17-
18-
until i > 10
19-
{
20-
WriteLine("I isn't big eneugh" + i + ".");
21-
i = i + 1;
22-
23-
}
24-
else {
25-
WriteLine("I is already big enough" + i + ".");
26-
}
27-
28-
WriteLine("I: " + i + ".");
1+
WriteLine("Hello, World!")

0 commit comments

Comments
 (0)