diff --git a/CompilerDesignIflr1.sln b/CompilerDesignIflr1.sln new file mode 100644 index 0000000..9f39004 --- /dev/null +++ b/CompilerDesignIflr1.sln @@ -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 diff --git a/CompilerDesignIflr1/CompilerDesignIflr1.csproj b/CompilerDesignIflr1/CompilerDesignIflr1.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/CompilerDesignIflr1/CompilerDesignIflr1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/CompilerDesignIflr1/GrammarReader.cs b/CompilerDesignIflr1/GrammarReader.cs new file mode 100644 index 0000000..dd8ed46 --- /dev/null +++ b/CompilerDesignIflr1/GrammarReader.cs @@ -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) + { + + } + } +} diff --git a/CompilerDesignIflr1/LR1Closure.cs b/CompilerDesignIflr1/LR1Closure.cs new file mode 100644 index 0000000..724b6d2 --- /dev/null +++ b/CompilerDesignIflr1/LR1Closure.cs @@ -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 + { + } +} diff --git a/CompilerDesignIflr1/LR1Unit.cs b/CompilerDesignIflr1/LR1Unit.cs new file mode 100644 index 0000000..d3ec49b --- /dev/null +++ b/CompilerDesignIflr1/LR1Unit.cs @@ -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() { } + } +} diff --git a/CompilerDesignIflr1/LexicalAnalysis.cs b/CompilerDesignIflr1/LexicalAnalysis.cs new file mode 100644 index 0000000..e3b3ae0 --- /dev/null +++ b/CompilerDesignIflr1/LexicalAnalysis.cs @@ -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; } = ""; + + + } +} diff --git a/CompilerDesignIflr1/Program.cs b/CompilerDesignIflr1/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/CompilerDesignIflr1/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/CompilerDesignIflr1/if-grammar.grammar b/CompilerDesignIflr1/if-grammar.grammar new file mode 100644 index 0000000..531ff15 --- /dev/null +++ b/CompilerDesignIflr1/if-grammar.grammar @@ -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]+ } +} \ No newline at end of file