添加项目文件。

This commit is contained in:
lichx 2024-12-20 20:20:34 +08:00
parent 1cedd76eac
commit 235500f8ce
8 changed files with 183 additions and 0 deletions

22
CompilerDesignIflr1.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompilerDesignIFlr1", "CompilerDesignIFlr1\CompilerDesignIFlr1.csproj", "{A7C303EC-99CC-4B0B-93B1-1EAD185DF63B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7C303EC-99CC-4B0B-93B1-1EAD185DF63B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7C303EC-99CC-4B0B-93B1-1EAD185DF63B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7C303EC-99CC-4B0B-93B1-1EAD185DF63B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7C303EC-99CC-4B0B-93B1-1EAD185DF63B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CompilerDesignIFlr1
{
internal class GrammarReader
{
public GrammarReader(Uri grammarFilePath)
{
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CompilerDesignIFlr1
{
internal class LR1Closure
{
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CompilerDesignIFlr1
{
internal class LR1Unit
{
public LR1Unit() { }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CompilerDesignIflr1
{
internal class LexicalAnalysis
{
string Text { get; set; } = "";
}
}

View File

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View File

@ -0,0 +1,93 @@
@top Program {
StatementList
}
StatementList {
Statement*
}
@skip { Whitespace }
IfStatement {
If LParen ConditionalExpression RParen PartIfStatement Else Statement | If LParen ConditionalExpression RParen Statement
}
PartIfStatement {
If LParen ConditionalExpression RParen PartIfStatement Else PartIfStatement | NoIfStatement
}
ConditionalExpression {
Expression Operator Expression | Expression
}
Expression {
Term (AddLike Term)*
}
Statement {
IfStatement | NoIfStatement
}
NoIfStatement {
AssignmentStatement Semicolon | VariableDefinition Semicolon | LBrace Statement* RBrace | ConstantDefinition Semicolon
}
AssignmentStatement {
Identifier Equal Expression
}
Term {
Factor (MultiplyLike Factor)*
}
VariableDefinition {
Type (Identifier | Identifier Equal Expression)+
}
ConstantDefinition {
Const VariableDefinition
}
Type {
Int | Char
}
Factor {
Identifier | Number | Character | LParen Expression RParen
}
AddLike {
Plus | Minus
}
MultiplyLike {
Multiply | Divide | Modulo
}
Number {
UnsignedNumber | Minus UnsignedNumber | Plus UnsignedNumber
}
@tokens {
If { "!if" }
Else { "!else" }
Int {"!int"}
Char {"!char"}
Const { "!const" }
Plus { "+" }
Minus { "-" }
Multiply { "*" }
Modulo { "%" }
Divide { "/" }
LParen { "(" }
RParen { ")" }
LBrace { "{" }
RBrace { "}" }
Semicolon { ";" }
Identifier { $[a-zA-Z_]$[a-zA-Z0-9_]* }
UnsignedNumber { $[0-9]+ }
String { "\"" $[\x00-\x7F]* "\"" }
Character { "'" $[\x00-\x7F] "'" }
Operator { "==" | "!=" | "<=" | ">=" | "<" | ">" }
Equal { "=" }
Whitespace { $[\t\n\r]+ }
}