本文整理汇总了C#中Parser.process方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.process方法的具体用法?C# Parser.process怎么用?C# Parser.process使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ComplexExpressions
public void ComplexExpressions()
{
Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
List<Token> tokens = tokenizer.process(File.OpenText("code8.txt"));
Parser parser = new Parser(tokens, s_errorHandler);
parser.process();
//Console.WriteLine("Tree: " + parser.getAST().getTreeAsString());
}
示例5: 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"));
}
示例6: 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);
}
示例7: 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());
}
示例8: ParseSomeExpressionsWithFunctions
public void ParseSomeExpressionsWithFunctions()
{
Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
List<Token> tokens = tokenizer.process(File.OpenText("code15.txt"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
//Console.WriteLine("Tree: " + parser.getAST().getTreeAsString());
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例9: ParseSingleName
public void ParseSingleName()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.NAME, "erik"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例10: ParseSimpleExpression
public void ParseSimpleExpression()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.NAME, "a"));
tokens.Add(new Token(Token.TokenType.OPERATOR, "+"));
tokens.Add(new Token(Token.TokenType.NAME, "b"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例11: ParseLongerExpression
public void ParseLongerExpression()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.NUMBER, "2"));
tokens.Add(new Token(Token.TokenType.OPERATOR, "*"));
tokens.Add(new Token(Token.TokenType.NUMBER, "3"));
tokens.Add(new Token(Token.TokenType.OPERATOR, "+"));
tokens.Add(new Token(Token.TokenType.NUMBER, "4"));
tokens.Add(new Token(Token.TokenType.OPERATOR, "*"));
tokens.Add(new Token(Token.TokenType.NUMBER, "5"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例12: ParseIfElseBlock
public void ParseIfElseBlock()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.IF, "if"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_LEFT, "("));
tokens.Add(new Token(Token.TokenType.NAME, "m_hasGotCandy"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_RIGHT, ")"));
tokens.Add(new Token(Token.TokenType.NEW_LINE, "\n"));
tokens.Add(new Token(Token.TokenType.NAME, "boringFunction"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_LEFT, "("));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_RIGHT, ")"));
tokens.Add(new Token(Token.TokenType.NEW_LINE, "\n"));
tokens.Add(new Token(Token.TokenType.BLOCK_END, "end"));
tokens.Add(new Token(Token.TokenType.ELSE, "else"));
tokens.Add(new Token(Token.TokenType.NEW_LINE, "\n"));
tokens.Add(new Token(Token.TokenType.BLOCK_END, "end"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例13: 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);
}
示例14: ParseFunctionCallWithParameters
public void ParseFunctionCallWithParameters()
{
List<Token> tokens = new List<Token>();
tokens.Add(new Token(Token.TokenType.NAME, "foo"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_LEFT, "("));
tokens.Add(new Token(Token.TokenType.NAME, "a"));
tokens.Add(new Token(Token.TokenType.COMMA, ","));
tokens.Add(new Token(Token.TokenType.NAME, "bar"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_LEFT, "("));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_RIGHT, ")"));
tokens.Add(new Token(Token.TokenType.COMMA, ","));
tokens.Add(new Token(Token.TokenType.NUMBER, "400"));
tokens.Add(new Token(Token.TokenType.PARANTHESIS_RIGHT, ")"));
ErrorHandler errorHandler = new ErrorHandler();
Parser parser = new Parser(tokens, errorHandler);
parser.process();
Assert.AreEqual(0, errorHandler.getErrors().Count);
}
示例15: ParseCode3
public void ParseCode3()
{
Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
List<Token> tokens = tokenizer.process(File.OpenText("code3.txt"));
Parser parser = new Parser(tokens, s_errorHandler);
parser.process();
}