예제 #1
0
 internal void InitArrayDecl(Token initToken, int? initSize)
 {
     if (initToken != null && initSize != null)
     {
         this.tokenType = initToken;
         this.size = (int)initSize;
     }
 }
예제 #2
0
 internal static bool IsOperator(Token op)
 {
     foreach (string inop in AllOperators)
     {
         if (op.Value.Equals(inop))
         {
             return true;
         }
     }
     return false;
 }
예제 #3
0
        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;
        }
예제 #4
0
 internal StringDeclExpr(Token var)
 {
     this.varName = var;
 }
예제 #5
0
 internal StatementsSeqExpr(
     Token identifer,
     SequenceExpressionType type)
     : this()
 {
     identifier = identifer;
     sequenceType = type;
 }
예제 #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;
        }
예제 #7
0
 internal static LeafNode CreateLeafNode(Token token)
 {
     return null;
 }
예제 #8
0
 internal BlockDeclExpr(
     Token returnType,
     Token name)
     : this()
 {
     functionReturnType = returnType;
     functionIdentifier = name;
 }
예제 #9
0
 internal IntegerLeaf(Token t)
     : base(t)
 {
 }
예제 #10
0
 internal IdentifierExpression(Token token)
     : this()
 {
     this.identifier = token;
 }
예제 #11
0
            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];
            }
예제 #12
0
 internal FunctionCallExpression(
     Token functionName)
     : this()
 {
     this.functionName = functionName.IdentiferName;
     this.identifier = functionName;
 }
예제 #13
0
 internal FunctionDeclBlock(
     Token returnType,
     Token name)
     : base(returnType, name)
 {
 }
예제 #14
0
 internal FunctionCallExpression(
     Token functionName,
     List<Expr> parameters)
     : this(functionName)
 {
     this.functionName = functionName.IdentiferName;
     this.listOfParameters = parameters;
 }
예제 #15
0
 internal EndFunctionExpression(Token functionName)
     : this()
 {
     this.identifier = functionName;
 }
예제 #16
0
 internal BlockDeclExpr(
     Token name)
     : this()
 {
     functionIdentifier = name;
 }
예제 #17
0
 internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier, int size)
     : this(tokenType, tokenIdentifier)
 {
     this.size = size;
 }
예제 #18
0
 internal OperatorNode(Token operand)
     : base(operand)
 {
 }
예제 #19
0
 internal IdentifierExpression(Token token, IdentifierExpression nested)
     : this(token)
 {
     this.nestedExpression = nested;
 }
예제 #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;
                }
            }
        }
예제 #21
0
 internal IntDeclExpr(Token var, Token op, Token expr)
     : base()
 {
     this.variableName = var;
     this.theOperator = op;
     this.assignmentExpression = expr;
 }
예제 #22
0
 internal OperatorExpression(Token token)
     : this()
 {
     this.identifier = token;
     operationType = Arity.binary;
 }
예제 #23
0
 internal IdentifierLeaf(Token identifier)
     : base(identifier)
 {
 }
예제 #24
0
 internal ProgramDeclBlock(
     Token name)
     : base(name)
 {
 }
예제 #25
0
 internal LeafNode(Token value)
     : base()
 {
     _value = value;
 }
예제 #26
0
 internal void AddTokenToList(Token token)
 {
     if (token.Kind == ByteCodeIdentifiers.TokenCode.Program)
     {
         this.Name = token;
         this.tokenList.Add(token);
     }
 }
예제 #27
0
 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;
 }
예제 #28
0
 internal ArrayDeclExpr(Token tokenType, Token tokenIdentifier)
     : this()
 {
     this.tokenType = tokenType;
     this.tokenIdentifier = tokenIdentifier;
 }
예제 #29
0
 internal void PutTokenBack(Token t)
 {
     _scanPointer -= ((string)t.Value).Length;
 }
예제 #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;
        }