本文整理汇总了C#中ParseTree类的典型用法代码示例。如果您正苦于以下问题:C# ParseTree类的具体用法?C# ParseTree怎么用?C# ParseTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseTree类属于命名空间,在下文中一共展示了ParseTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Compile
public CodePart Compile(int startLineNum, ParseTree tree, Context context, CompilerOptions options)
{
InitCompileFlags();
part = new CodePart();
this.context = context;
this.options = options;
this.startLineNum = startLineNum;
++context.NumCompilesSoFar;
try
{
if (tree.Nodes.Count > 0)
{
PreProcess(tree);
CompileProgram(tree);
}
}
catch (KOSException kosException)
{
if (lastNode != null)
{
throw; // TODO something more sophisticated will go here that will
// attach source/line information to the exception before throwing it upward.
// that's why this seemingly pointless "catch and then throw again" is here.
}
SafeHouse.Logger.Log("Exception in Compiler: " + kosException.Message);
SafeHouse.Logger.Log(kosException.StackTrace);
throw; // throw it up in addition to logging the stack trace, so the kOS terminal will also give the user some message.
}
return part;
}
开发者ID:gisikw,项目名称:KOS,代码行数:34,代码来源:Compiler.cs
示例2: TranslateAssignment
protected override void TranslateAssignment(List<string> output, ParseTree.Assignment assignment)
{
output.Add(this.CurrentTabIndention);
Expression target = assignment.Target;
if (target is Variable && ((Variable)target).IsStatic)
{
output.Add("public static ");
}
Annotation typeAnnotation = target.GetAnnotation("type");
if (typeAnnotation != null)
{
string type = this.JavaPlatform.GetTypeStringFromAnnotation(
typeAnnotation.FirstToken,
typeAnnotation.GetSingleArgAsString(null),
false, false);
output.Add(type);
output.Add(" ");
}
this.TranslateExpression(output, target);
output.Add(" ");
output.Add(assignment.AssignmentOp);
output.Add(" ");
this.TranslateExpression(output, assignment.Value);
output.Add(";");
output.Add(this.NL);
}
开发者ID:geofrey,项目名称:crayon,代码行数:30,代码来源:JavaTranslator.cs
示例3: Compile
public CodePart Compile(ParseTree tree, Context context, CompilerOptions options)
{
_part = new CodePart();
_context = context;
_options = options;
try
{
if (tree.Nodes.Count > 0)
{
PreProcess(tree);
CompileProgram(tree);
}
}
catch (Exception e)
{
if (_lastNode != null)
{
throw new Exception(string.Format("Error parsing {0}: {1}", ConcatenateNodes(_lastNode), e.Message));
}
else
{
throw;
}
}
return _part;
}
开发者ID:ElasticRaven,项目名称:KOS,代码行数:28,代码来源:Compiler.cs
示例4: EvalAttribute
protected override object EvalAttribute(ParseTree tree, params object[] paramlist)
{
Grammar grammar = (Grammar)paramlist[0];
Symbol symbol = (Symbol)paramlist[1];
GrammarNode node = (GrammarNode)paramlist[2];
if (symbol.Attributes.ContainsKey(node.Nodes[1].Token.Text))
{
tree.Errors.Add(new ParseError("Attribute already defined for this symbol: " + node.Nodes[1].Token.Text, 0x1039, node.Nodes[1]));
return null;
}
symbol.Attributes.Add(node.Nodes[1].Token.Text, (object[])EvalParams(tree, new object[] { node }));
switch (node.Nodes[1].Token.Text)
{
case "Skip":
if (symbol is TerminalSymbol)
grammar.SkipSymbols.Add(symbol);
else
tree.Errors.Add(new ParseError("Attribute for non-terminal rule not allowed: " + node.Nodes[1].Token.Text, 0x1035, node));
break;
case "Color":
if (symbol is NonTerminalSymbol)
tree.Errors.Add(new ParseError("Attribute for non-terminal rule not allowed: " + node.Nodes[1].Token.Text, 0x1035, node));
if (symbol.Attributes["Color"].Length != 1 && symbol.Attributes["Color"].Length != 3)
tree.Errors.Add(new ParseError("Attribute " + node.Nodes[1].Token.Text + " has too many or missing parameters", 0x103A, node.Nodes[1]));
for (int i = 0; i < symbol.Attributes["Color"].Length; i++)
{
if (symbol.Attributes["Color"][i] is string)
{
tree.Errors.Add(new ParseError("Parameter " + node.Nodes[3].Nodes[i * 2].Nodes[0].Token.Text + " is of incorrect type", 0x103A, node.Nodes[3].Nodes[i * 2].Nodes[0]));
break;
}
}
break;
case "IgnoreCase":
if (!(symbol is TerminalSymbol))
tree.Errors.Add(new ParseError("Attribute for non-terminal rule not allowed: " + node.Nodes[1].Token.Text, 0x1035, node));
break;
case "FileAndLine":
if (symbol is TerminalSymbol)
{
grammar.SkipSymbols.Add(symbol);
grammar.FileAndLine = symbol;
}
else
tree.Errors.Add(new ParseError("Attribute for non-terminal rule not allowed: " + node.Nodes[1].Token.Text, 0x1035, node));
break;
default:
tree.Errors.Add(new ParseError("Attribute not supported: " + node.Nodes[1].Token.Text, 0x1036, node.Nodes[1]));
break;
}
return symbol;
}
开发者ID:hvacengi,项目名称:TinyPG,代码行数:57,代码来源:GrammarTree.cs
示例5: Parse
public ParseTree Parse(string input, string fileName, ParseTree tree)
{
scanner.Init(input, fileName);
this.tree = tree;
ParseStart(tree);
tree.Skipped = scanner.Skipped;
return tree;
}
开发者ID:Whitecaribou,项目名称:KOS,代码行数:10,代码来源:Parser.cs
示例6: X_ImageBlit
protected override void X_ImageBlit(List<string> output, ParseTree.Expression screen, ParseTree.Expression image, ParseTree.Expression x, ParseTree.Expression y)
{
output.Add("$gfx_blit_image(");
SerializeExpression(output, image);
output.Add(", $floor(");
SerializeExpression(output, x);
output.Add("), $floor(");
SerializeExpression(output, y);
output.Add("))");
}
开发者ID:blakeohare,项目名称:crython,代码行数:10,代码来源:CrayonPrimitiveMethods.cs
示例7: CompileProgram
private void CompileProgram(ParseTree tree)
{
_currentCodeSection = _part.MainCode;
PushProgramParameters();
VisitNode(tree.Nodes[0]);
if (_addBranchDestination)
{
AddOpcode(new OpcodeNOP());
}
}
开发者ID:ElasticRaven,项目名称:KOS,代码行数:11,代码来源:Compiler.cs
示例8: TranslateFunctionDefinition
protected override void TranslateFunctionDefinition(List<string> output, ParseTree.FunctionDefinition functionDef)
{
output.Add(this.CurrentTabIndention);
string returnType = "void*";
Annotation returnTypeAnnotation = functionDef.GetAnnotation("type");
if (returnTypeAnnotation != null)
{
returnType = this.CPlatform.GetTypeStringFromAnnotation(new AnnotatedType(returnTypeAnnotation), false, true);
}
output.Add(returnType);
output.Add(" ");
output.Add("v_" + functionDef.NameToken.Value);
output.Add("(");
for (int i = 0; i < functionDef.ArgNames.Length; ++i)
{
if (i > 0) output.Add(", ");
if (functionDef.ArgAnnotations[i] == null)
{
output.Add("object ");
}
else
{
string argType = functionDef.ArgAnnotations[i].GetSingleArgAsString(null);
string type = this.CPlatform.GetTypeStringFromAnnotation(functionDef.ArgAnnotations[i].FirstToken, argType, false, true);
output.Add(type);
output.Add(" ");
}
output.Add("v_" + functionDef.ArgNames[i].Value);
}
output.Add(")");
output.Add(this.NL);
output.Add(this.CurrentTabIndention);
output.Add("{");
output.Add(this.NL);
this.CurrentIndention++;
Executable[] code = functionDef.Code;
if (functionDef.GetAnnotation("omitReturn") != null)
{
Executable[] newCode = new Executable[code.Length - 1];
Array.Copy(code, newCode, newCode.Length);
code = newCode;
}
this.Translate(output, code);
this.CurrentIndention--;
output.Add(this.CurrentTabIndention);
output.Add("}");
//*/
output.Add(this.NL);
}
开发者ID:geofrey,项目名称:crayon,代码行数:52,代码来源:CTranslator.cs
示例9: Parse
public override ParseTree Parse(Lexer lexer, ParserState state)
{
ParseTree bodyTree = body.Parse(lexer, state);
if (bodyTree == ParseTree.No)
return ParseTree.No;
ParseTree labelledTree = new ParseTree();
labelledTree = labelledTree.ExtendFields(bodyTree);
labelledTree.Fields[label] = bodyTree.Value;
return labelledTree;
}
开发者ID:KevinKelley,项目名称:katahdin,代码行数:13,代码来源:LabelNode.cs
示例10: EvalAssignmentExpression
protected override object EvalAssignmentExpression(ParseTree tree, params object[] paramlist)
{
object result = this.GetValue(tree, TokenType.ConditionalOrExpression, 0);
if (nodes.Count >= 5 && result is bool
&& nodes[1].Token.Type == TokenType.QUESTIONMARK
&& nodes[3].Token.Type == TokenType.COLON)
{
if (Convert.ToBoolean(result))
result = nodes[2].Eval(tree, paramlist); // return 1st argument
else
result = nodes[4].Eval(tree, paramlist); // return 2nd argumen
}
return result;
}
开发者ID:ErikBehar,项目名称:sequencer,代码行数:14,代码来源:ParseTreeEvaluator.cs
示例11: AssembleGraph
private void AssembleGraph(BidirectionalGraph<ParseTree, Edge<ParseTree>> graph, ParseTree parent)
{
if (parent.Children == null)
{
return;
}
foreach (var child in parent.Children)
{
graph.AddVertex(child);
graph.AddEdge(new Edge<ParseTree>(parent, child));
AssembleGraph(graph, child);
}
}
开发者ID:ShyAlex,项目名称:scheme-ish,代码行数:14,代码来源:TreeClientApp.cs
示例12: EvalAdditiveExpression
protected override object EvalAdditiveExpression(ParseTree tree, params object[] paramlist)
{
object result = this.GetValue(tree, TokenType.MultiplicativeExpression, 0);
for (int i = 1; i < nodes.Count; i += 2)
{
Token token = nodes[i].Token;
object val = nodes[i + 1].Eval(tree, paramlist);
if (token.Type == TokenType.PLUS)
result = Convert.ToDouble(result) + Convert.ToDouble(val);
else if (token.Type == TokenType.MINUS)
result = Convert.ToDouble(result) - Convert.ToDouble(val);
}
return result;
}
开发者ID:ErikBehar,项目名称:sequencer,代码行数:15,代码来源:ParseTreeEvaluator.cs
示例13: AllowNestedOutputAtEachLevel
public void AllowNestedOutputAtEachLevel()
{
var tree = new ParseTree("<system goal>");
tree.AddTerminalChild("begin");
tree.AddChildNode(BuildStatementNode());
tree.AddTerminalChild("end");
tree.BuildLinesDifferently();
Assert.AreEqual("<system goal>", tree.Lines[0]);
Assert.AreEqual("begin <statement> end ", tree.Lines[1]);
Assert.AreEqual("begin Id := <expression> ; end ", tree.Lines[2]);
Assert.AreEqual("begin Id := <primary> <add op> <expression> ; end ", tree.Lines[3]);
Assert.AreEqual("begin Id := Id <add op> <expression> ; end ", tree.Lines[4]);
Assert.AreEqual("begin Id := Id PlusOp <expression> ; end ", tree.Lines[5]);
Assert.AreEqual("begin Id := Id PlusOp <primary> ; end ", tree.Lines[6]);
Assert.AreEqual("begin Id := Id PlusOp IdX ; end ", tree.Lines[7]);
}
开发者ID:joshmaletz,项目名称:ucd-csci-5640,代码行数:16,代码来源:ParseTreeShould.cs
示例14: Populate
public static void Populate(TreeView treeview, ParseTree parsetree)
{
treeview.Visible = false;
treeview.SuspendLayout();
treeview.Nodes.Clear();
treeview.Tag = parsetree;
ParseNode start = parsetree.Nodes[0];
TreeNode node = new TreeNode(start.Text);
node.Tag = start;
node.ForeColor = Color.SteelBlue;
treeview.Nodes.Add(node);
PopulateNode(node, start);
treeview.ExpandAll();
treeview.ResumeLayout();
treeview.Visible = true;
}
开发者ID:geocine,项目名称:tccdotnet,代码行数:18,代码来源:ParseTreeViewer.cs
示例15: X_DrawRectangle
protected override void X_DrawRectangle(List<string> output, ParseTree.Expression screen, ParseTree.Expression left, ParseTree.Expression top, ParseTree.Expression width, ParseTree.Expression height, ParseTree.Expression red, ParseTree.Expression green, ParseTree.Expression blue)
{
output.Add("$gfx_draw_rectangle(");
SerializeExpression(output, left);
output.Add(", ");
SerializeExpression(output, top);
output.Add(", ");
SerializeExpression(output, width);
output.Add(", ");
SerializeExpression(output, height);
output.Add(", ");
SerializeExpression(output, red);
output.Add(", ");
SerializeExpression(output, green);
output.Add(", ");
SerializeExpression(output, blue);
output.Add(", 255)");
}
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:CrayonPrimitiveMethods.cs
示例16: Compile
public CodePart Compile(int startLineNum, ParseTree tree, Context context, CompilerOptions options)
{
InitCompileFlags();
part = new CodePart();
this.context = context;
this.options = options;
this.startLineNum = startLineNum;
++context.NumCompilesSoFar;
if (tree.Nodes.Count > 0)
{
PreProcess(tree);
CompileProgram(tree);
}
return part;
}
开发者ID:KSP-KOS,项目名称:KOS,代码行数:18,代码来源:Compiler.cs
示例17: ExtendingFields
public void ExtendingFields()
{
ParseTree a = new ParseTree();
a.Fields["a"] = "A";
a.Fields["b"] = "B";
a.Fields["c"] = "C";
Assert.IsTrue(a.Fields.ContainsKey("a"));
Assert.IsTrue(a.Fields.ContainsKey("b"));
Assert.IsTrue(a.Fields.ContainsKey("c"));
ParseTree b = new ParseTree();
b.ExtendFields(a);
b.Fields["d"] = "D";
Assert.IsTrue(b.Fields.ContainsKey("a"));
Assert.IsTrue(b.Fields.ContainsKey("b"));
Assert.IsTrue(b.Fields.ContainsKey("c"));
Assert.IsTrue(b.Fields.ContainsKey("d"));
}
开发者ID:KevinKelley,项目名称:katahdin,代码行数:20,代码来源:ParseTreeTest.cs
示例18: X_DrawRectangle
protected override void X_DrawRectangle(List<string> output, ParseTree.Expression screen, ParseTree.Expression left, ParseTree.Expression top, ParseTree.Expression width, ParseTree.Expression height, ParseTree.Expression red, ParseTree.Expression green, ParseTree.Expression blue)
{
// TODO: need to run this through a helper function to avoid 1-height bugs
output.Add("pygame.draw.rect(");
SerializeExpression(output, screen);
output.Add(", (");
SerializeExpression(output, red);
output.Add(", ");
SerializeExpression(output, green);
output.Add(", ");
SerializeExpression(output, blue);
output.Add("), pygame.Rect(");
SerializeExpression(output, left);
output.Add(", ");
SerializeExpression(output, top);
output.Add(", ");
SerializeExpression(output, width);
output.Add(", ");
SerializeExpression(output, height);
output.Add("))");
}
开发者ID:blakeohare,项目名称:crython,代码行数:21,代码来源:PythonPrimitiveMethods.cs
示例19: TranslateFunctionDefinition
protected override void TranslateFunctionDefinition(List<string> output, ParseTree.FunctionDefinition functionDef)
{
Annotation returnType = functionDef.GetAnnotation("type");
string type = returnType == null ? "Object" : this.JavaPlatform.GetTypeStringFromString(returnType.GetSingleArgAsString(null), false, false);
output.Add(this.CurrentTabIndention);
output.Add("public static ");
output.Add(type);
output.Add(" v_");
output.Add(functionDef.NameToken.Value);
output.Add("(");
for (int i = 0; i < functionDef.ArgNames.Length; ++i)
{
if (i > 0) {
output.Add(", ");
}
Annotation annotation = functionDef.ArgAnnotations[i];
string argType = annotation == null ? "Object" : annotation.GetSingleArgAsString(null);
output.Add(this.JavaPlatform.GetTypeStringFromString(argType, false, false));
output.Add(" v_");
output.Add(functionDef.ArgNames[i].Value);
}
output.Add(") {");
output.Add(this.NL);
this.CurrentIndention++;
Executable[] code = functionDef.Code;
if (functionDef.GetAnnotation("omitReturn") != null)
{
Executable[] newCode = new Executable[code.Length - 1];
Array.Copy(code, newCode, newCode.Length);
code = newCode;
}
this.Translate(output, code);
this.CurrentIndention--;
output.Add(this.CurrentTabIndention);
output.Add("}");
output.Add(this.NL);
}
开发者ID:geofrey,项目名称:crayon,代码行数:40,代码来源:JavaTranslator.cs
示例20: Parse
public override ParseTree Parse(Lexer lexer, ParserState state)
{
state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "token");
int start = lexer.Position;
ParseTree bodyTree = body.Parse(lexer, state);
if (bodyTree == ParseTree.No)
{
state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
return ParseTree.No;
}
state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
ParseTree tokenTree = new ParseTree(
lexer.Text.Substring(start, lexer.Position - start));
tokenTree = tokenTree.ExtendFields(bodyTree);
return tokenTree;
}
开发者ID:KevinKelley,项目名称:katahdin,代码行数:23,代码来源:TokenNode.cs
注:本文中的ParseTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论