本文整理汇总了C#中ProgrammingLanguageNr1.AST.getTokenType方法的典型用法代码示例。如果您正苦于以下问题:C# AST.getTokenType方法的具体用法?C# AST.getTokenType怎么用?C# AST.getTokenType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgrammingLanguageNr1.AST
的用法示例。
在下文中一共展示了AST.getTokenType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: evaluate
private float evaluate(AST tree)
{
float returnValue = 0;
if(tree.getTokenType() == Token.TokenType.NUMBER) {
returnValue = (float)System.Convert.ToDouble(tree.getTokenString());
}
else if(tree.getTokenType() == Token.TokenType.OPERATOR) {
if(tree.getTokenString() == "+") {
returnValue = evaluate(tree.getChild(0)) + evaluate(tree.getChild(1));
}
else if(tree.getTokenString() == "-") {
returnValue = evaluate(tree.getChild(0)) - evaluate(tree.getChild(1));
}
else if(tree.getTokenString() == "*") {
returnValue = evaluate(tree.getChild(0)) * evaluate(tree.getChild(1));
}
else if(tree.getTokenString() == "/") {
returnValue = evaluate(tree.getChild(0)) / evaluate(tree.getChild(1));
}
else if(tree.getTokenString() == "<") {
returnValue = (evaluate(tree.getChild(0)) < evaluate(tree.getChild(1))) ? 1 : 0;
}
else if(tree.getTokenString() == ">") {
returnValue = (evaluate(tree.getChild(0)) > evaluate(tree.getChild(1))) ? 1 : 0;
}
else if(tree.getTokenString() == "<=") {
returnValue = (evaluate(tree.getChild(0)) <= evaluate(tree.getChild(1))) ? 1 : 0;
}
else if(tree.getTokenString() == ">=") {
returnValue = (evaluate(tree.getChild(0)) >= evaluate(tree.getChild(1))) ? 1 : 0;
}
else if(tree.getTokenString() == "&&") {
returnValue = (evaluate(tree.getChild(0)) != 0 && evaluate(tree.getChild(1)) != 0) ? 1 : 0;
}
else if(tree.getTokenString() == "||") {
returnValue = (evaluate(tree.getChild(0)) != 0 || evaluate(tree.getChild(1)) != 0) ? 1 : 0;
}
else if(tree.getTokenString() == "!=") {
returnValue = (evaluate(tree.getChild(0)) != evaluate(tree.getChild(1))) ? 1 : 0;
}
else if(tree.getTokenString() == "==") {
returnValue = (evaluate(tree.getChild(0)) == evaluate(tree.getChild(1))) ? 1 : 0;
}
else {
throw new InvalidOperationException("ExpressionEvaluator can't handle operators with string " + tree.getTokenString());
}
}
else {
throw new InvalidOperationException("ExpressionEvaluator can't handle tokens of type " + tree.getTokenType());
}
return returnValue;
}
示例2: addToList
private void addToList(List<AST> list, AST ast)
{
switch (ast.getTokenType())
{
case Token.TokenType.FUNC_DECLARATION:
addToList(list, ast.getChild(2));
addToList(list, ast.getChild(3));
break;
case Token.TokenType.IF:
addToList(list, ast.getChild(0));
list.Add(ast);
#if WRITE_DEBUG_INFO
Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
#endif
break;
case Token.TokenType.LOOP:
list.Add(ast);
#if WRITE_DEBUG_INFO
Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
#endif
break;
case Token.TokenType.LOOP_BLOCK:
list.Add(ast);
#if WRITE_DEBUG_INFO
Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
#endif
break;
default:
addChildren(list, ast);
#if WRITE_DEBUG_INFO
Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
#endif
list.Add(ast);
break;
}
}
示例3: evaluateScopeDeclarations
private void evaluateScopeDeclarations(AST tree)
{
Debug.Assert(tree != null);
if (tree.getTokenType() == Token.TokenType.FUNC_DECLARATION)
{
evaluateFunctionScope(tree);
}
else if (tree.getTokenType() == Token.TokenType.IF) {
evaluateIfScope(tree);
}
else if (tree.getTokenType() == Token.TokenType.LOOP) {
evaluateLoopScope(tree);
}
else if (tree.getTokenType() == Token.TokenType.LOOP_BLOCK) {
evaluateLoopBlockScope(tree);
}
else if (tree.getChildren() != null)
{
evaluateScopeDeclarationsInAllChildren(tree);
}
}
示例4: execute
private ReturnValue execute(AST tree)
{
Token.TokenType tokenType = tree.getToken().getTokenType();
ReturnValue returnValue = null;
if (tokenType == Token.TokenType.FUNC_DECLARATION)
{
return new ReturnValue();
}
#if WRITE_DEBUG_INFO
Console.WriteLine("Executing " + tree.getTokenType() + " " + tree.getTokenString());
#endif
if (tokenType == Token.TokenType.STATEMENT_LIST)
{
executeAllChildNodes(tree);
}
else if (tokenType == Token.TokenType.FUNCTION_CALL) {
returnValue = functionCall(tree);
}
else if (tokenType == Token.TokenType.NAME) {
returnValue = name(tree);
}
else if (tokenType == Token.TokenType.NUMBER) {
returnValue = number(tree);
}
else if (tokenType == Token.TokenType.OPERATOR) {
returnValue = operation(tree);
}
else if (tokenType == Token.TokenType.QUOTED_STRING) {
returnValue = quotedString(tree);
}
else if (tokenType == Token.TokenType.IF) {
ifThenElse(tree);
}
else if (tokenType == Token.TokenType.VAR_DECLARATION) {
varDeclaration(tree);
}
else if (tokenType == Token.TokenType.ASSIGNMENT) {
assignment(tree);
}
else if (tokenType == Token.TokenType.RETURN) {
returnStatement(tree);
}
else {
throw new NotImplementedException("The interpreter hasn't got support for token type " + tokenType + " yet!");
}
return returnValue;
}
示例5: evaluateReferences
private void evaluateReferences(AST tree)
{
Debug.Assert(tree != null);
if (tree.getTokenType() == Token.TokenType.VAR_DECLARATION)
{
evaluateReferencesForVAR_DECLARATION(tree);
}
else if (tree.getTokenType() == Token.TokenType.ASSIGNMENT)
{
evaluateReferencesForASSIGNMENT(tree);
}
else if (tree.getTokenType() == Token.TokenType.ASSIGNMENT_TO_ARRAY)
{
evaluateReferencesForASSIGNMENT_TO_ARRAY(tree);
}
else if (tree.getTokenType() == Token.TokenType.FUNC_DECLARATION)
{
evaluateReferencesForFUNC_DECLARATION(tree);
}
else if (tree.getTokenType() == Token.TokenType.FUNCTION_CALL)
{
evaluateReferencesForFUNCTION_CALL(tree);
}
else if (tree.getTokenType() == Token.TokenType.IF)
{
evaluateReferencesForIF(tree);
}
else if (tree.getTokenType() == Token.TokenType.NAME)
{
evaluateReferencesForNAME(tree);
}
else if (tree.getTokenType() == Token.TokenType.LOOP_BLOCK)
{
evaluateReferencesForLOOP_BLOCK(tree);
}
else if (tree.getTokenType() == Token.TokenType.LOOP)
{
evaluateReferencesForLOOP(tree);
}
else
{
evaluateReferencesInAllChildren(tree);
}
}