internal void InitArrayDecl(Token initToken, int? initSize)
 {
     if (initToken != null && initSize != null)
     {
         this.tokenType = initToken;
         this.size = (int)initSize;
     }
 }
Example #2
0
 internal static bool IsOperator(Token op)
 {
     foreach (string inop in AllOperators)
     {
         if (op.Value.Equals(inop))
         {
             return true;
         }
     }
     return false;
 }
        private Expr ParseIfCondition(Expr expr, Token lparen)
        {
            if (_expressionScopeStack.Peek() is IfDeclExpr)
            {
                expr = _expressionScopeStack.Peek();
            }
            else
            {
                expr = new IfDeclExpr();
                _expressionScopeStack.Push(expr);
            }
            if (lparen.Kind == ByteCodeIdentifiers.TokenCode.LParen)
            {
                ParseStatementExpression();
                this.boe.Push(this.BinaryExpression);
                ((IfDeclExpr)expr).AddCondition(this.BinaryExpression);
            }

            return expr;
        }
 internal StringDeclExpr(Token var)
 {
     this.varName = var;
 }
 internal StatementsSeqExpr(
     Token identifer,
     SequenceExpressionType type)
     : this()
 {
     identifier = identifer;
     sequenceType = type;
 }
Example #6
0
        private IdentifierExpression DetermineNextToken(Token t)
        {
            if (t != null && t.IsReserverdWord())
            {
                Token next = _scanner.GetToken();
                Expr currentScope = null;

                if (_expressionScopeStack.Count > 0)
                {
                    currentScope = _expressionScopeStack.Peek();
                }

                if (next.IsReserverdWord())
                {
                    throw new NireExecutionException("a reserverd word cannot be used in the expression");
                }

                if (next.IsIdentifier() && !next.isOperator)
                {
                    var identExpression = new IdentifierExpression(t, new IdentifierExpression(next));
                    SymbolTable.CreateInstance().AddTokenToScope(currentScope, identExpression);
                    return identExpression;
                }
            }
            else
            {
                var isParen = _scanner.Peek();
                if (isParen.Kind == ByteCodeIdentifiers.TokenCode.LParen)
                {
                    new ParserContext(ParserContextEnum.FuncExecution);
                    //_scanner.GetToken();
                }

                Expr defaultScope = _expressionScopeStack.Peek();
                var funcExpression = new IdentifierExpression(t);
                SymbolTable.CreateInstance().AddTokenToScope(defaultScope, funcExpression);
                return funcExpression;
            }

            return null;
        }
Example #7
0
 internal static LeafNode CreateLeafNode(Token token)
 {
     return null;
 }
 internal BlockDeclExpr(
     Token returnType,
     Token name)
     : this()
 {
     functionReturnType = returnType;
     functionIdentifier = name;
 }
Example #9
0
 internal IntegerLeaf(Token t)
     : base(t)
 {
 }
 internal IdentifierExpression(Token token)
     : this()
 {
     this.identifier = token;
 }
            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 FunctionCallExpression(
     Token functionName)
     : this()
 {
     this.functionName = functionName.IdentiferName;
     this.identifier = functionName;
 }
 internal FunctionDeclBlock(
     Token returnType,
     Token name)
     : base(returnType, name)
 {
 }
 internal FunctionCallExpression(
     Token functionName,
     List<Expr> parameters)
     : this(functionName)
 {
     this.functionName = functionName.IdentiferName;
     this.listOfParameters = parameters;
 }
 internal EndFunctionExpression(Token functionName)
     : this()
 {
     this.identifier = functionName;
 }
 internal BlockDeclExpr(
     Token name)
     : this()
 {
     functionIdentifier = name;
 }
 internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier, int size)
     : this(tokenType, tokenIdentifier)
 {
     this.size = size;
 }
Example #18
0
 internal OperatorNode(Token operand)
     : base(operand)
 {
 }
 internal IdentifierExpression(Token token, IdentifierExpression nested)
     : this(token)
 {
     this.nestedExpression = nested;
 }
Example #20
0
        /// <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;
                }
            }
        }
 internal IntDeclExpr(Token var, Token op, Token expr)
     : base()
 {
     this.variableName = var;
     this.theOperator = op;
     this.assignmentExpression = expr;
 }
 internal OperatorExpression(Token token)
     : this()
 {
     this.identifier = token;
     operationType = Arity.binary;
 }
Example #23
0
 internal IdentifierLeaf(Token identifier)
     : base(identifier)
 {
 }
 internal ProgramDeclBlock(
     Token name)
     : base(name)
 {
 }
Example #25
0
 internal LeafNode(Token value)
     : base()
 {
     _value = value;
 }
 internal void AddTokenToList(Token token)
 {
     if (token.Kind == ByteCodeIdentifiers.TokenCode.Program)
     {
         this.Name = token;
         this.tokenList.Add(token);
     }
 }
 private Token ParseToRightBracket(Expr expr, Token bracket, BinaryOperatorExpression boe)
 {
     while (bracket.Kind != ByteCodeIdentifiers.TokenCode.RBracket)
     {
         ParseStatementExpression();
         ((IfDeclExpr)expr).AddStatementToCondition(boe, this.BinaryExpression);
         bracket = _scanner.GetToken();
     }
     return bracket;
 }
 internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier)
     : this()
 {
     this.tokenType = tokenType;
     this.tokenIdentifier = tokenIdentifier;
 }
Example #29
0
 internal void PutTokenBack(Token t)
 {
     _scanPointer -= ((string)t.Value).Length;
 }
Example #30
0
        private Expr ArrayDeclaration(Token tokenType)
        {
            ArrayDeclExpr ade = null;

            Token ident = _scanner.GetToken();

            if (ParserContext.Context != ParserContextEnum.FunctionDecl)
            {
                if (ident.Kind != ByteCodeIdentifiers.TokenCode.Number)
                {
                    throw new NireExecutionException("array declaration did not contain a number");
                }

                var number = _scanner.GetToken();
                if (number.Kind != ByteCodeIdentifiers.TokenCode.Number || number.Kind != ByteCodeIdentifiers.TokenCode.Identifier)
                {
                    throw new NireExecutionException("not a valid array declaration");
                }

                var rb = _scanner.GetToken();

                //rbracket("]", "Not a valid array declaration");

                ade = new ArrayDeclExpr(tokenType, ident, Convert.ToInt32(ident.Value));
                return ade;
            }

            ade = new ArrayDeclExpr(tokenType, ident);

            return ade;
        }