本文整理汇总了C#中ProgrammingLanguageNr1.AST.getTokenString方法的典型用法代码示例。如果您正苦于以下问题:C# AST.getTokenString方法的具体用法?C# AST.getTokenString怎么用?C# AST.getTokenString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgrammingLanguageNr1.AST
的用法示例。
在下文中一共展示了AST.getTokenString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: arrayLookup
private AST arrayLookup()
{
AST arrayName = new AST(match(Token.TokenType.NAME));
AST arrayLookupNode = new AST(new Token(Token.TokenType.ARRAY_LOOKUP, arrayName.getTokenString()));
match(Token.TokenType.BRACKET_LEFT);
AST arrayIndex = expression();
match(Token.TokenType.BRACKET_RIGHT);
arrayLookupNode.addChild(arrayIndex);
return arrayLookupNode;
}
示例2: findParent
public AST findParent(AST ofThisChild)
{
Console.WriteLine("Going into " + getTokenString());
if(ofThisChild == null) { return null; }
if(m_children == null) { return null; }
int i = m_children.IndexOf(ofThisChild);
if(i >= 0) {
Console.WriteLine("Found " + ofThisChild.getTokenString());
return this;
}
else {
foreach(AST child in m_children) {
AST parent = child.findParent(ofThisChild);
if(parent != null) {
return parent;
}
}
}
return null;
}
示例3: 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;
}
}
示例4: parameter
private AST parameter()
{
#if WRITE_DEBUG_INFO
Console.WriteLine("parameter");
#endif
AST parameterTree = new AST(new Token(Token.TokenType.PARAMETER, "<PARAMETER>", lookAhead(1).LineNr, lookAhead(1).LinePosition));
AST type = null;
if(lookAheadType(1) == Token.TokenType.BUILT_IN_TYPE_NAME) {
type = new AST(match(Token.TokenType.BUILT_IN_TYPE_NAME));
} else {
type = new AST(new Token(Token.TokenType.BUILT_IN_TYPE_NAME, "var"));
}
AST name = new AST(match(Token.TokenType.NAME));
AST declaration = new AST_VariableDeclaration(new Token(Token.TokenType.VAR_DECLARATION, "<PARAMETER_DECLARATION>"),
ExternalFunctionCreator.GetReturnTypeFromString(type.getTokenString()), name.getTokenString());
AST assigment = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), name.getTokenString());
parameterTree.addChild(declaration);
parameterTree.addChild(assigment);
return parameterTree;
}
示例5: 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;
}
示例6: 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;
}
示例7: operation
private ReturnValue operation(AST tree)
{
ReturnValue returnValue = null;
float lhs = execute(tree.getChild(0)).FloatValue;
float rhs = execute(tree.getChild(1)).FloatValue;
if(tree.getTokenString() == "+") {
returnValue = new ReturnValue(lhs + rhs);
}
else if(tree.getTokenString() == "-") {
returnValue = new ReturnValue(lhs - rhs);
}
else if(tree.getTokenString() == "*") {
returnValue = new ReturnValue(lhs * rhs);
}
else if(tree.getTokenString() == "/") {
returnValue = new ReturnValue(lhs / rhs);
}
else if(tree.getTokenString() == "<") {
float v = lhs < rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == ">") {
float v = lhs > rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == "<=") {
float v = lhs <= rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == ">=") {
float v = lhs >= rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == "==") {
float v = lhs == rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == "!=") {
float v = lhs != rhs ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == "&&") {
float v = ((lhs != 0 ? true : false) && (rhs != 0 ? true : false)) ? 1 : 0;
returnValue = new ReturnValue(v);
}
else if(tree.getTokenString() == "||") {
float v = ((lhs != 0 ? true : false) || (rhs != 0 ? true : false)) ? 1 : 0;
returnValue = new ReturnValue(v);
}
else {
throw new NotImplementedException("Operator " + tree.getTokenString() + " isn't implemented yet!");
}
return returnValue;
}
示例8: quotedString
private ReturnValue quotedString(AST tree)
{
ReturnValue returnValue = new ReturnValue(tree.getTokenString());
return returnValue;
}
示例9: number
private ReturnValue number(AST tree)
{
ReturnValue returnValue = new ReturnValue((float)Convert.ToDouble(tree.getTokenString()));
return returnValue;
}
示例10: name
private ReturnValue name(AST tree)
{
string name = tree.getTokenString();
ReturnValue val = null;
val = m_currentMemorySpace.getValue(name);
if (val == null) {
val = m_globalMemorySpace.getValue(name);
}
Assert.IsNotNull(val);
#if WRITE_DEBUG_INFO
Console.WriteLine("The fetched value is of type " + val.getReturnType());
if(val.getReturnType() == ReturnType.FLOAT) {
Console.WriteLine("And has value: " + val.FloatValue);
}
else if(val.getReturnType() == ReturnType.STRING) {
Console.WriteLine("And has value: " + val.StringValue);
}
#endif
return val;
}
示例11: functionCall
private ReturnValue functionCall(AST tree)
{
ReturnValue returnValue = null;
if (m_externalFunctionCreator.externalFunctions.ContainsKey(tree.getTokenString()))
{
ExternalFunctionCreator.OnFunctionCall functionCall = m_externalFunctionCreator.externalFunctions[tree.getTokenString()];
if (functionCall != null)
{
ReturnValue[] parameters = new ReturnValue[tree.getChildren().Count];
int i = 0;
foreach (AST parameter in tree.getChildren())
{
parameters[i] = execute(parameter);
i++;
}
returnValue = functionCall(parameters);
}
else
{
throw new Error("Can't find external function " + tree.getTokenString(), Error.ErrorType.UNDEFINED, tree.getToken().LineNr, tree.getToken().LinePosition);
}
}
else
{
// Call user defined function
string functionName = tree.getTokenString();
AST functionTree = getFunctionTreeNode(functionName);
Assert.IsNotNull(functionTree);
// Create list of parameter values
List<ReturnValue> parameterValues = new List<ReturnValue>();
List<AST> functionCallChildNodes = tree.getChildren();
if (functionCallChildNodes != null)
{
foreach(AST parameter in tree.getChildren())
{
ReturnValue val = execute(parameter);
parameterValues.Add(val);
}
}
returnValue = function(functionTree, parameterValues);
}
return returnValue;
}
示例12: evaluateReferencesForNAME
private void evaluateReferencesForNAME(AST tree)
{
Symbol symbol = m_currentScope.resolve(tree.getTokenString());
if(symbol == null) {
m_errorHandler.errorOccured(
new Error("Can't find anything called '" + tree.getTokenString() + "'",
Error.ErrorType.SYNTAX,
tree.getToken().LineNr,
tree.getToken().LinePosition));
}
else if (symbol is FunctionSymbol) {
m_errorHandler.errorOccured(
new Error("'" + tree.getTokenString() + "' is a function and must be called with ()",
Error.ErrorType.SYNTAX,
tree.getToken().LineNr,
tree.getToken().LinePosition));
}
#if WRITE_DEBUG_INFO
Console.WriteLine("Resolved symbol with name " + tree.getTokenString() + " (on line " + tree.getToken().LineNr + ")" + " in " + m_currentScope);
#endif
evaluateReferencesInAllChildren(tree);
}
示例13: evaluateReferencesForFUNCTION_CALL
private void evaluateReferencesForFUNCTION_CALL(AST tree)
{
// Function name:
string functionName = tree.getTokenString();
FunctionSymbol function = (FunctionSymbol)m_currentScope.resolve(functionName);
if (function == null)
{
m_errorHandler.errorOccured("Can't find function with name " + functionName,
Error.ErrorType.SCOPE,
tree.getToken().LineNr,
tree.getToken().LinePosition
);
}
else
{
#if WRITE_DEBUG_INFO
Console.WriteLine("Resolved function call with name " + functionName + " (on line " + tree.getToken().LineNr + ")");
#endif
// Parameters
evaluateReferencesInAllChildren(tree);
AST node = function.getFunctionDefinitionNode();
AST_FunctionDefinitionNode functionDefinitionTree = (AST_FunctionDefinitionNode)(node);
/*if(functionDefinitionTree.getTokenString() != "<EXTERNAL_FUNC_DECLARATION>") {
evaluateReferencesForFUNC_DECLARATION(functionDefinitionTree);
}*/
// Setup reference to Function Definition AST node
AST_FunctionCall functionCallAst = tree as AST_FunctionCall;
Debug.Assert(functionCallAst != null);
functionCallAst.FunctionDefinitionRef = functionDefinitionTree;
List<AST> calleeParameterList = functionDefinitionTree.getChild(2).getChildren();
// Check that the number of arguments is right
AST callerParameterList = tree.getChild(0);
List<AST> arguments = callerParameterList.getChildren();
if (arguments.Count != calleeParameterList.Count)
{
m_errorHandler.errorOccured(
"Wrong number of arguments to function"
, Error.ErrorType.SYNTAX, tree.getToken().LineNr, tree.getToken().LinePosition);
}
}
}