添加项目文件。
This commit is contained in:
@@ -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>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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() { }
|
||||
}
|
||||
}
|
||||
@@ -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; } = "";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
@@ -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]+ }
|
||||
}
|
||||
Reference in New Issue
Block a user