Permalink
Browse files

Initial WIP

  • Loading branch information...
Brad Robinson
Brad Robinson committed Jul 25, 2010
0 parents commit 8687f48d6d0cd4bae9a239b3c7d0df9c4e19557d
Showing with 5,193 additions and 0 deletions.
  1. +11 −0 .gitignore
  2. +32 −0 MiniME.sln
  3. +31 −0 MiniME/CompileError.cs
  4. +76 −0 MiniME/Compiler.cs
  5. +89 −0 MiniME/MiniME.csproj
  6. +851 −0 MiniME/Parser.cs
  7. +36 −0 MiniME/Properties/AssemblyInfo.cs
  8. +553 −0 MiniME/StringScanner.cs
  9. +69 −0 MiniME/SymbolDeclarationVisitor.cs
  10. +68 −0 MiniME/SymbolFrequency.cs
  11. +119 −0 MiniME/SymbolManager.cs
  12. +31 −0 MiniME/SymbolScope.cs
  13. +50 −0 MiniME/SymbolUsageVisitor.cs
  14. +997 −0 MiniME/Tokenizer.cs
  15. +30 −0 MiniME/Utils.cs
  16. +954 −0 MiniME/ast/ExpressionNode.cs
  17. +45 −0 MiniME/ast/Node.cs
  18. +36 −0 MiniME/ast/Parameter.cs
  19. +11 −0 MiniME/ast/Statement.cs
  20. +74 −0 MiniME/ast/StatementBlock.cs
  21. +43 −0 MiniME/ast/StatementBreakContinue.cs
  22. +42 −0 MiniME/ast/StatementDoWhile.cs
  23. +33 −0 MiniME/ast/StatementExpression.cs
  24. +70 −0 MiniME/ast/StatementFor.cs
  25. +61 −0 MiniME/ast/StatementForEach.cs
  26. +60 −0 MiniME/ast/StatementIfElse.cs
  27. +34 −0 MiniME/ast/StatementLabel.cs
  28. +50 −0 MiniME/ast/StatementReturnThrow.cs
  29. +94 −0 MiniME/ast/StatementSwitch.cs
  30. +89 −0 MiniME/ast/StatementTryCatchFinally.cs
  31. +50 −0 MiniME/ast/StatementVariableDeclaration.cs
  32. +40 −0 MiniME/ast/StatementWhile.cs
  33. +41 −0 MiniME/ast/StatementWith.cs
  34. +60 −0 MiniMETestCases/MiniMETestCases.csproj
  35. +36 −0 MiniMETestCases/Properties/AssemblyInfo.cs
  36. +13 −0 MiniMETestCases/SymbolManagerTests.cs
  37. +70 −0 mm/Program.cs
  38. +36 −0 mm/Properties/AssemblyInfo.cs
  39. +13 −0 mm/input.js
  40. +71 −0 mm/mm.csproj
  41. +24 −0 mm/test.html
@@ -0,0 +1,11 @@
build
bin
obj
Release
Debug
*.pdb
*.user
*.suo
*.swp
*.swo
*.ncb
@@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniME", "MiniME\MiniME.csproj", "{947703CB-0944-4609-A4C3-B85B90DF50E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mm", "mm\mm.csproj", "{692B99CE-C938-43AE-9F1F-1DA24557FD14}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniMETestCases", "MiniMETestCases\MiniMETestCases.csproj", "{76CC33AD-D621-431C-8366-C5D4A1C428A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{947703CB-0944-4609-A4C3-B85B90DF50E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{947703CB-0944-4609-A4C3-B85B90DF50E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{947703CB-0944-4609-A4C3-B85B90DF50E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{947703CB-0944-4609-A4C3-B85B90DF50E1}.Release|Any CPU.Build.0 = Release|Any CPU
{692B99CE-C938-43AE-9F1F-1DA24557FD14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{692B99CE-C938-43AE-9F1F-1DA24557FD14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{692B99CE-C938-43AE-9F1F-1DA24557FD14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{692B99CE-C938-43AE-9F1F-1DA24557FD14}.Release|Any CPU.Build.0 = Release|Any CPU
{76CC33AD-D621-431C-8366-C5D4A1C428A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76CC33AD-D621-431C-8366-C5D4A1C428A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76CC33AD-D621-431C-8366-C5D4A1C428A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76CC33AD-D621-431C-8366-C5D4A1C428A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MiniME
{
public class CompileError : Exception
{
internal CompileError(string message, Tokenizer t)
{
m_strMessage = message;
m_strFileName = t.FileName;
m_lineNumber = t.currentLine;
m_linePosition = t.currentLinePosition;
}
public override string Message
{
get
{
return string.Format("{0}({1},{2}): {3}", m_strFileName, m_lineNumber+1, m_linePosition+1, m_strMessage);
}
}
string m_strMessage;
string m_strFileName;
int m_lineNumber;
int m_linePosition;
}
}
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MiniME
{
public class Compiler
{
public Compiler()
{
Reset();
}
public TextWriter Output
{
get;
set;
}
public void Reset()
{
m_files.Clear();
}
public void AddFile(string strFileName)
{
var i=new FileInfo();
i.filename=strFileName;
i.content=File.ReadAllText(strFileName);
m_files.Add(i);
}
public void Compile()
{
foreach (var file in m_files)
{
Console.WriteLine("Processing {0}...", file.filename);
// Create a tokenizer and parser
Tokenizer t = new Tokenizer(file.content, file.filename);
Parser p = new Parser(t);
// Parse the file into a namespace
var statements = new ast.StatementBlock();
p.ParseStatements(statements);
statements.GlobalScope = false;
if (t.more)
{
throw new CompileError("Unexpected EOF", t);
}
//statements.Dump(0);
SymbolScope rootScope = new SymbolScope(null);
statements.Visit(new SymbolDeclarationVisitor(rootScope));
statements.Visit(new SymbolUsageVisitor(rootScope));
rootScope.Dump(0);
StringBuilder sb = new StringBuilder();
statements.Render(sb);
Console.WriteLine(sb.ToString());
}
}
class FileInfo
{
public string filename;
public string content;
}
List<FileInfo> m_files=new List<FileInfo>();
}
}
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{947703CB-0944-4609-A4C3-B85B90DF50E1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MiniME</RootNamespace>
<AssemblyName>MiniME</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ast\StatementTryCatchFinally.cs" />
<Compile Include="ast\StatementWith.cs" />
<Compile Include="ast\StatementForEach.cs" />
<Compile Include="ast\StatementLabel.cs" />
<Compile Include="ast\StatementWhile.cs" />
<Compile Include="ast\StatementDoWhile.cs" />
<Compile Include="ast\StatementBreakContinue.cs" />
<Compile Include="ast\StatementSwitch.cs" />
<Compile Include="ast\StatementExpression.cs" />
<Compile Include="ast\StatementVariableDeclaration.cs" />
<Compile Include="ast\StatementFor.cs" />
<Compile Include="ast\StatementIfElse.cs" />
<Compile Include="ast\ExpressionNode.cs" />
<Compile Include="ast\StatementReturnThrow.cs" />
<Compile Include="ast\Node.cs" />
<Compile Include="ast\Parameter.cs" />
<Compile Include="ast\Statement.cs" />
<Compile Include="ast\StatementBlock.cs" />
<Compile Include="SymbolFrequency.cs" />
<Compile Include="SymbolScope.cs" />
<Compile Include="SymbolUsageVisitor.cs" />
<Compile Include="SymbolDeclarationVisitor.cs" />
<Compile Include="Utils.cs" />
<Compile Include="SymbolManager.cs" />
<Compile Include="CompileError.cs" />
<Compile Include="Compiler.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringScanner.cs" />
<Compile Include="Tokenizer.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Oops, something went wrong.

0 comments on commit 8687f48

Please sign in to comment.