This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a360ca3
Showing
17 changed files
with
2,550 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>41f915cb-c113-409c-afcc-74281a492009</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Mizu3.Parser</RootNamespace> | ||
<AssemblyName>Mizu3.Parser</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</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" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Class1.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
// Generated by TinyPG v1.2 available at www.codeproject.com | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Mizu3.Parser | ||
{ | ||
#region ParseTree | ||
public class ParseErrors : List<ParseError> | ||
{ | ||
} | ||
|
||
public class ParseError | ||
{ | ||
private string message; | ||
private int code; | ||
private int line; | ||
private int col; | ||
private int pos; | ||
private int length; | ||
|
||
public int Code { get { return code; } } | ||
public int Line { get { return line; } } | ||
public int Column { get { return col; } } | ||
public int Position { get { return pos; } } | ||
public int Length { get { return length; } } | ||
public string Message { get { return message; } } | ||
|
||
public ParseError(string message, int code, ParseNode node) : this(message, code, 0, node.Token.StartPos, node.Token.StartPos, node.Token.Length) | ||
{ | ||
} | ||
|
||
public ParseError(string message, int code, int line, int col, int pos, int length) | ||
{ | ||
this.message = message; | ||
this.code = code; | ||
this.line = line; | ||
this.col = col; | ||
this.pos = pos; | ||
this.length = length; | ||
} | ||
} | ||
|
||
// rootlevel of the node tree | ||
public partial class ParseTree : ParseNode | ||
{ | ||
public ParseErrors Errors; | ||
|
||
public List<Token> Skipped; | ||
|
||
public ParseTree() : base(new Token(), "ParseTree") | ||
{ | ||
Token.Type = TokenType.Start; | ||
Token.Text = "Root"; | ||
Skipped = new List<Token>(); | ||
Errors = new ParseErrors(); | ||
} | ||
|
||
public string PrintTree() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
int indent = 0; | ||
PrintNode(sb, this, indent); | ||
return sb.ToString(); | ||
} | ||
|
||
private void PrintNode(StringBuilder sb, ParseNode node, int indent) | ||
{ | ||
|
||
string space = "".PadLeft(indent, ' '); | ||
|
||
sb.Append(space); | ||
sb.AppendLine(node.Text); | ||
|
||
foreach (ParseNode n in node.Nodes) | ||
PrintNode(sb, n, indent + 2); | ||
} | ||
|
||
/// <summary> | ||
/// this is the entry point for executing and evaluating the parse tree. | ||
/// </summary> | ||
/// <param name="paramlist">additional optional input parameters</param> | ||
/// <returns>the output of the evaluation function</returns> | ||
public object Eval(params object[] paramlist) | ||
{ | ||
return Nodes[0].Eval(this, paramlist); | ||
} | ||
} | ||
|
||
public partial class ParseNode | ||
{ | ||
protected string text; | ||
protected List<ParseNode> nodes; | ||
|
||
public List<ParseNode> Nodes { get {return nodes;} } | ||
|
||
public ParseNode Parent; | ||
public Token Token; // the token/rule | ||
public string Text { // text to display in parse tree | ||
get { return text;} | ||
set { text = value; } | ||
} | ||
|
||
public virtual ParseNode CreateNode(Token token, string text) | ||
{ | ||
ParseNode node = new ParseNode(token, text); | ||
node.Parent = this; | ||
return node; | ||
} | ||
|
||
protected ParseNode(Token token, string text) | ||
{ | ||
this.Token = token; | ||
this.text = text; | ||
this.nodes = new List<ParseNode>(); | ||
} | ||
|
||
protected object GetValue(ParseTree tree, TokenType type, int index) | ||
{ | ||
return GetValue(tree, type, ref index); | ||
} | ||
|
||
protected object GetValue(ParseTree tree, TokenType type, ref int index) | ||
{ | ||
object o = null; | ||
if (index < 0) return o; | ||
|
||
// left to right | ||
foreach (ParseNode node in nodes) | ||
{ | ||
if (node.Token.Type == type) | ||
{ | ||
index--; | ||
if (index < 0) | ||
{ | ||
o = node.Eval(tree); | ||
break; | ||
} | ||
} | ||
} | ||
return o; | ||
} | ||
|
||
/// <summary> | ||
/// this implements the evaluation functionality, cannot be used directly | ||
/// </summary> | ||
/// <param name="tree">the parsetree itself</param> | ||
/// <param name="paramlist">optional input parameters</param> | ||
/// <returns>a partial result of the evaluation</returns> | ||
internal object Eval(ParseTree tree, params object[] paramlist) | ||
{ | ||
object Value = null; | ||
|
||
switch (Token.Type) | ||
{ | ||
case TokenType.Start: | ||
Value = EvalStart(tree, paramlist); | ||
break; | ||
case TokenType.Statements: | ||
Value = EvalStatements(tree, paramlist); | ||
break; | ||
case TokenType.Statement: | ||
Value = EvalStatement(tree, paramlist); | ||
break; | ||
case TokenType.ImportStatement: | ||
Value = EvalImportStatement(tree, paramlist); | ||
break; | ||
case TokenType.ReAssignmentStatement: | ||
Value = EvalReAssignmentStatement(tree, paramlist); | ||
break; | ||
case TokenType.LetStatement: | ||
Value = EvalLetStatement(tree, paramlist); | ||
break; | ||
case TokenType.IterStatement: | ||
Value = EvalIterStatement(tree, paramlist); | ||
break; | ||
case TokenType.FuncStatement: | ||
Value = EvalFuncStatement(tree, paramlist); | ||
break; | ||
case TokenType.TypeFuncDeclartion: | ||
Value = EvalTypeFuncDeclartion(tree, paramlist); | ||
break; | ||
case TokenType.RetStatement: | ||
Value = EvalRetStatement(tree, paramlist); | ||
break; | ||
case TokenType.Argument: | ||
Value = EvalArgument(tree, paramlist); | ||
break; | ||
case TokenType.FuncCall: | ||
Value = EvalFuncCall(tree, paramlist); | ||
break; | ||
case TokenType.ArrayIndexExpr: | ||
Value = EvalArrayIndexExpr(tree, paramlist); | ||
break; | ||
case TokenType.ObjectCreatetion: | ||
Value = EvalObjectCreatetion(tree, paramlist); | ||
break; | ||
case TokenType.MathExpr: | ||
Value = EvalMathExpr(tree, paramlist); | ||
break; | ||
case TokenType.OPERATOR: | ||
Value = EvalOPERATOR(tree, paramlist); | ||
break; | ||
|
||
default: | ||
Value = Token.Text; | ||
break; | ||
} | ||
return Value; | ||
} | ||
|
||
protected virtual object EvalStart(ParseTree tree, params object[] paramlist) | ||
{ | ||
return "Could not interpret input; no semantics implemented."; | ||
} | ||
|
||
protected virtual object EvalStatements(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalImportStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalReAssignmentStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalLetStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalIterStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalFuncStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalTypeFuncDeclartion(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalRetStatement(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalArgument(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalFuncCall(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalArrayIndexExpr(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalObjectCreatetion(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalMathExpr(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected virtual object EvalOPERATOR(ParseTree tree, params object[] paramlist) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
} | ||
|
||
#endregion ParseTree | ||
} |
Oops, something went wrong.