本文整理汇总了C#中ParseTree类的典型用法代码示例。如果您正苦于以下问题:C# ParseTree类的具体用法?C# ParseTree怎么用?C# ParseTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseTree类属于命名空间,在下文中一共展示了ParseTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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("))");
}
示例7: CompileProgram
private void CompileProgram(ParseTree tree)
{
_currentCodeSection = _part.MainCode;
PushProgramParameters();
VisitNode(tree.Nodes[0]);
if (_addBranchDestination)
{
AddOpcode(new OpcodeNOP());
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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]);
}
示例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;
}
示例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)");
}