internal static bool IsOperator(Token op) { foreach (string inop in AllOperators) { if (op.Value.Equals(inop)) { return true; } } return false; }
internal FunctionCallExpression( Token functionName) : this() { this.functionName = functionName.IdentiferName; this.identifier = functionName; }
internal FunctionCallExpression( Token functionName, List<Expr> parameters) : this(functionName) { this.functionName = functionName.IdentiferName; this.listOfParameters = parameters; }
internal static ShiftReduceEval Validate(Token opOnStack, Token opInStream) { string s = (String)opOnStack.Value; string y = (String)opInStream.Value; OpValue? stackEnum = GetOpAsEnum(s); OpValue? streamEnum = GetOpAsEnum(y); return OperatorPrecedenceTable.ShiftReduceOperationTable[(int)stackEnum, (int)streamEnum]; }
internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier, int size) : this(tokenType, tokenIdentifier) { this.size = size; }
internal StatementsSeqExpr( Token identifer, SequenceExpressionType type) : this() { identifier = identifer; sequenceType = type; }
internal OperatorExpression(Token token) : this() { this.identifier = token; operationType = Arity.binary; }
internal IdentifierExpression(Token token, IdentifierExpression nested) : this(token) { this.nestedExpression = nested; }
internal IntegerLeaf(Token t) : base(t) { }
internal IdentifierLeaf(Token identifier) : base(identifier) { }
internal OperatorNode(Token operand) : base(operand) { }
/// <summary> /// Parse the signature of the function /// </summary> private void ParseFunctionSignature( Expr parentNode, Token functionName) { List<Expr> pll = null; functionName.Kind = ByteCodeIdentifiers.TokenCode.Function; Token paren = _scanner.GetToken(); /* * If there are parameters * add them to the parameter list */ if (paren.Value.Equals(constants.LEFTPAREN)) { pll = ParseFunctionParameters(); } if (pll != null && pll.Count > 0) { var progExpression = parentNode as BlockDeclExpr; if (progExpression != null) { progExpression.Parameters = pll; } if (functionName.IdentiferName.Equals(constants.MAIN, StringComparison.OrdinalIgnoreCase)) { _isMain = true; progExpression.IsMain = true; } } }
private IdentifierExpression DetermineNextToken(Token t) { switch (t.IdentiferName.ToLower()) { case "int": case "float": case "string": case "char": case "bool": case "bit": case "object": case "new": Token next = _scanner.GetToken(); Expr currentScope = _expressionScopeStack.Peek(); SymbolTable.CreateInstance().AddTokenToScope(currentScope, new IdentifierExpression(next)); if (next.IsReserverdWord()) { throw new NireExecutionException("a reserverd word cannot be here"); } if (next.IsIdentifier() && !next.isOperator) { return new IdentifierExpression(t, new IdentifierExpression(next)); } break; default: { Expr defaultScope = _expressionScopeStack.Peek(); SymbolTable.CreateInstance().AddTokenToScope(defaultScope, new IdentifierExpression(t)); return new IdentifierExpression(t); } } return null; }
private Expr ArrayDeclaration(Token tokenType) { Token isArray = _scanner.Peek(); var expStack = _expressionScopeStack.Peek(); ArrayDeclExpr ade = null; if (isArray is TokenSpecial) { if (isArray.Equals("[]")) { _scanner.EatCurrentToken(); Token t = _scanner.GetToken(); ade = new ArrayDeclExpr(tokenType, t); return ade; } if (isArray.Equals("[")) { _scanner.EatCurrentToken(); var endBracket = _scanner.Peek(); if (endBracket is TokenSpecial && endBracket.Equals("]")) { _scanner.EatCurrentToken(); Token identifier = _scanner.GetToken(); ade = new ArrayDeclExpr(tokenType, identifier); return ade; } else { var context = ParserContext.Context; if (endBracket.Kind == ByteCodeIdentifiers.TokenCode.Number) { if (context == ParserContextEnum.FunctionDecl) { throw new NireException(); } int value; if(int.TryParse(endBracket.Value.ToString(), out value)) { _scanner.EatCurrentToken(); var isEnd = _scanner.GetToken(); if (isEnd.Equals("]")) { _scanner.EatCurrentToken(); Token t = _scanner.GetToken(); ade = new ArrayDeclExpr(tokenType, t, value); return ade; } } else { _scanner.EatCurrentToken(); Token t = _scanner.GetToken(); ade = new ArrayDeclExpr(tokenType, t); return ade; } } } } if (ade != null) { SymbolTable.CreateInstance().AddTokenToScope(expStack, ade); } } return null; }
internal FunctionDeclBlock( Token returnType, Token name) : base(returnType, name) { }
internal LeafNode(Token value) : base() { _value = value; }
internal IdentifierExpression(Token token) : this() { this.identifier = token; }
internal static LeafNode CreateLeafNode(Token token) { return null; }
internal IntDeclExpr(Token var, Token op, Token expr) : base() { this.variableName = var; this.theOperator = op; this.assignmentExpression = expr; }
internal BlockDeclExpr( Token returnType, Token name) : this() { functionReturnType = returnType; functionIdentifier = name; }
internal ProgramDeclBlock( Token name) : base(name) { }
internal BlockDeclExpr( Token name) : this() { functionIdentifier = name; }
internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier) : this() { this.tokenType = tokenType; this.tokenIdentifier = tokenIdentifier; }
internal EndFunctionExpression(Token functionName) : this() { this.identifier = functionName; }
internal void InitArrayDecl(Token initToken, int? initSize) { if (initToken != null && initSize != null) { this.tokenType = initToken; this.size = (int)initSize; } }
internal void PutTokenBack(Token t) { _scanPointer -= ((string)t.Value).Length; }