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