本文整理汇总了C#中Parser.getAST方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.getAST方法的具体用法?C# Parser.getAST怎么用?C# Parser.getAST使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.getAST方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatingSimpleTree
public void CreatingSimpleTree()
{
Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
List<Token> tokens = tokenizer.process(File.OpenText("code4.txt"));
Parser parser = new Parser(tokens, s_errorHandler);
parser.process();
//Console.WriteLine("Tree: " + parser.getAST().toStringTree());
ASTPainter p = new ASTPainter();
p.PaintAST(parser.getAST());
AST root = parser.getAST();
Assert.AreEqual(Token.TokenType.PROGRAM_ROOT, root.getTokenType());
AST statementList = root.getChild(0);
Assert.AreEqual(Token.TokenType.STATEMENT_LIST, statementList.getTokenType());
AST multiplicationTree = statementList.getChild(1);
Assert.AreEqual(Token.TokenType.OPERATOR, multiplicationTree.getTokenType());
AST operand1 = multiplicationTree.getChild(0);
AST operand2 = multiplicationTree.getChild(1);
Assert.AreEqual("a", operand1.getTokenString());
Assert.AreEqual("b", operand2.getTokenString());
}
示例2: DeclareVariableInSubscopes
public void DeclareVariableInSubscopes()
{
Tokenizer t = new Tokenizer(s_errorHandler, true);
Parser p = new Parser(t.process(File.OpenText("code16.txt")), s_errorHandler);
p.process();
ScopeBuilder scopeBuilder = new ScopeBuilder(p.getAST(), s_errorHandler);
scopeBuilder.process();
}
示例3: DeclareAndReferenceFunctionsAndVariables
public void DeclareAndReferenceFunctionsAndVariables()
{
Tokenizer t = new Tokenizer(s_errorHandler, true);
Parser p = new Parser(t.process(File.OpenText("code13.txt")), s_errorHandler);
p.process();
ScopeBuilder scopeBuilder = new ScopeBuilder(p.getAST(), s_errorHandler);
scopeBuilder.process();
}
示例4: DefineVariableFromCode
public void DefineVariableFromCode()
{
Tokenizer t = new Tokenizer(s_errorHandler, true);
Parser p = new Parser(t.process(File.OpenText("code11.txt")), s_errorHandler);
p.process();
ScopeBuilder scopeBuilder = new ScopeBuilder(p.getAST(), s_errorHandler);
scopeBuilder.process();
Scope globalScope = scopeBuilder.getGlobalScope();
Assert.IsNotNull(globalScope.resolve("x"));
}
示例5: ForgettingEndStatement
public void ForgettingEndStatement()
{
Tokenizer t = new Tokenizer(s_errorHandler, true);
ErrorHandler e = new ErrorHandler();
Parser p = new Parser(t.process(File.OpenText("code68.txt")), e);
p.process();
ScopeBuilder scopeBuilder = new ScopeBuilder(p.getAST(), e);
scopeBuilder.process();
e.printErrorsToConsole();
Assert.AreEqual(1, e.getErrors().Count);
}
示例6: OperationOrder
public void OperationOrder()
{
Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
List<Token> tokens = tokenizer.process(File.OpenText("code6.txt"));
Parser parser = new Parser(tokens, s_errorHandler);
parser.process();
//Console.WriteLine("Tree: " + parser.getAST().toStringTree());
Assert.AreEqual("(<STATEMENT_LIST> <GLOBAL_VARIABLE_DEFINITIONS_LIST> (+ (* a b) (+ (* c d) e)))",
parser.getAST().getChild(0).getTreeAsString());
}
示例7: ParseFunctionDeclaration
public void ParseFunctionDeclaration()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.BUILT_IN_TYPE_NAME, "float"));
tokens.Add(new Token(Token.TokenType.NAME, "foo"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_LEFT, "("));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_RIGHT, ")"));
tokens.Add(new Token(Token.TokenType.BLOCK_END, "end"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Console.WriteLine("Tree: " + parser.getAST().getTreeAsString());
errorHandler.printErrorsToConsole();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}