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