Skip to content

Commit 7f8b0da

Browse files
Initial commit
0 parents  commit 7f8b0da

File tree

11 files changed

+783
-0
lines changed

11 files changed

+783
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CritLang/bin
2+
CritLang/obj
3+
.vs

CritLang.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32526.322
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CritLang", "CritLang\CritLang.csproj", "{56347825-5AA0-4FC9-8F61-774E0B4E8C15}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{56347825-5AA0-4FC9-8F61-774E0B4E8C15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{56347825-5AA0-4FC9-8F61-774E0B4E8C15}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{56347825-5AA0-4FC9-8F61-774E0B4E8C15}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{56347825-5AA0-4FC9-8F61-774E0B4E8C15}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7DCF180B-BE7E-400B-9445-B0F51EA375EA}
24+
EndGlobalSection
25+
EndGlobal

CritLang/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[assembly: CLSCompliant(false)]

CritLang/Content/Crit.g4

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
grammar Crit;
2+
3+
4+
program: line* EOF;
5+
6+
line: statement | ifBlock | whileBlock;
7+
8+
statement: (assignment|functionCall) ';';
9+
10+
ifBlock: 'if' expression block ('else' elseIfBlock);
11+
12+
elseIfBlock: block | ifBlock;
13+
14+
whileBlock: WHILE expression block ('else' elseIfBlock);
15+
16+
WHILE: 'while' | 'until';
17+
18+
assignment: IDENTIFIER '=' expression;
19+
20+
functionCall: IDENTIFIER '(' (expression (',' expression)*)? ')';
21+
22+
expression
23+
: constant #constantExpression
24+
| IDENTIFIER #identifierExpression
25+
| functionCall #functionCallExpression
26+
| '(' expression ')' #parenthesizedExpression
27+
| '!' expression #notExpression
28+
| expression multOp expression #multiplicativeExpression
29+
| expression addOp expression #additiveExpression
30+
| expression compareOp expression #comparisonExpression
31+
| expression boolOp expression #booleanExpression
32+
;
33+
34+
35+
36+
multOp: '*' | '/' | '%';
37+
addOp: '+' | '-';
38+
compareOp: '==' | '!=' | '<' | '>' | '<=' | '>=';
39+
boolOp: BOOL_OPERATOR;
40+
41+
BOOL_OPERATOR: 'and' | 'or' | 'xor';
42+
43+
constant: INTEGER | FLOAT | STRING | BOOL | NULL;
44+
45+
INTEGER: [0-9]+;
46+
FLOAT: [0-9]+ '.' [0-9]+;
47+
STRING: ('"' ~'"'* '"') | ('\'' ~'\''* '\'');
48+
BOOL: 'true' | 'false';
49+
NULL: 'null';
50+
51+
52+
block: '{' line* '}';
53+
54+
WS: [ \t\r\n]+ -> skip;
55+
IDENTIFIER: [a-zA-Z_][a-zA-Z0-9_]*;
56+
57+
Comment
58+
: '#' ~( '\r' | '\n' )*
59+
;
60+
61+

CritLang/Content/test.crit

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 + ".");

CritLang/CritLang.csproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<WarningsAsErrors>Nullable</WarningsAsErrors>
9+
<Optimize>true</Optimize>
10+
<PackAsTool>true</PackAsTool>
11+
<ToolCommandName>crit</ToolCommandName>
12+
<PackageOutputPath>./nupkg</PackageOutputPath>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Antlr4" Version="4.6.6">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="Antlr4.CodeGenerator" Version="4.6.6">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReference Include="Antlr4.Runtime" Version="4.6.6" />
25+
</ItemGroup>
26+
<ItemGroup>
27+
<Content Include="Crit.g4" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<None Update="Content\test.crit">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
</ItemGroup>
34+
35+
</Project>

0 commit comments

Comments
 (0)