示例#1
0
        private bool ParseProgramDefinition(out BaseASTNode pCurrentASTNode)
        {
            ProgramDeclarationASTNode node = null;
            Token name = null;

            pCurrentASTNode = null;
            if (tokens.RegisteredTokens[index].Type == EnumTokenType.KEYWORD_TOKEN &&
                tokens.RegisteredTokens[index].Value.Equals("program"))
            {
                Advance();
                AdvanceWhitespace();
                if (tokens.RegisteredTokens[index].Type == EnumTokenType.IDENTIFIER_TOKEN)
                {
                    name            = tokens.RegisteredTokens[index];
                    node            = new ProgramDeclarationASTNode(name.Value);
                    pCurrentASTNode = (BaseASTNode)node;
                    Symbol sym = new Symbol(name.Value, EnumSymbolType.PROGRAM, null);
                    symbols.RegisterSymbol(sym);
                    Advance();
                    AdvanceWhitespace();
                    return(true);
                }
            }
            pCurrentASTNode = null;
            return(false);
        }
示例#2
0
        private bool ParseVariableDeclaration(out BaseASTNode pCurrentASTNode)
        {
            VariableDeclarationASTNode node = null;
            Token name = null;
            Token type = null;

            pCurrentASTNode = null;
            if (tokens.RegisteredTokens[index].Type != EnumTokenType.KEYWORD_TOKEN &&
                !tokens.RegisteredTokens[index].Value.Equals("var"))
            {
                return(false);
            }
            Advance();
            AdvanceWhitespace();
            if (tokens.RegisteredTokens[index].Type != EnumTokenType.IDENTIFIER_TOKEN)
            {
                return(false);
            }
            name = tokens.RegisteredTokens[index];
            Advance();
            AdvanceWhitespace();
            if (tokens.RegisteredTokens[index].Type == EnumTokenType.OPERATOR_TOKEN)
            {
                if (!ParseValueExpression(out pCurrentASTNode))
                {
                    return(false);
                }
            }

            if (tokens.RegisteredTokens[index].Type != EnumTokenType.TYPE_TOKEN)
            {
                return(false);
            }
            type = tokens.RegisteredTokens[index];
            Advance();
            AdvanceWhitespace();
            node            = new VariableDeclarationASTNode(name.Value, type.Value, pCurrentASTNode);
            pCurrentASTNode = (BaseASTNode)node;
            Symbol sym = new Symbol(name.Value, EnumSymbolType.VARIABLE);

            symbols.RegisterSymbol(sym);
            return(true);
        }
示例#3
0
        private bool ParseReferenceExpression(out BaseASTNode pCurrentAstNode)
        {
            Token     @operator  = tokens.RegisteredTokens[index];
            Token     identifier = null;
            Token     type       = null;
            EnumTypes outT;
            ReferenceExpressionASTNode node = null;

            pCurrentAstNode = null;
            Advance();
            AdvanceWhitespace();

            if (tokens.RegisteredTokens[index].Type != EnumTokenType.IDENTIFIER_TOKEN)
            {
                ThrowError(EnumErrorCodes.UNEXPECTED_TOKEN, "Expected Identifier Found: " + tokens.RegisteredTokens[index].Type.ToString());
                return(false);
            }

            return(true);
        }
示例#4
0
 public ReferenceExpressionASTNode(EnumTypes nodeDataType, string identifier, BaseASTNode pNodeData)
 {
     this.nodeDataType = nodeDataType;
     this.identifier   = identifier;
     this.PNodeData    = pNodeData;
 }
示例#5
0
 private bool ParseSubroutineDeclaration(out BaseASTNode pCurrentAstNode)
 {
     //TODO Implement
     pCurrentAstNode = null;
     return(true);
 }
示例#6
0
        private bool ParseValueExpression(out BaseASTNode pCurrentAstNode)
        {
            Token     @operator = tokens.RegisteredTokens[index];
            Token     value     = null;
            Token     type      = null;
            EnumTypes outT;
            ValueExpressionASTNode node = null;

            pCurrentAstNode = null;
            Advance();
            AdvanceWhitespace();
            switch (@operator.Value)
            {
            case "=":
            {
                if (tokens.RegisteredTokens[index].Type == EnumTokenType.IDENTIFIER_TOKEN)
                {
                    Advance(-1);
                    AdvanceWhitespaceReverse();
                    //Advance(-1);
                    //AdvanceWhitespaceReverse();
                    if (!ParseReferenceExpression(out pCurrentAstNode))
                    {
                        return(true);
                    }
                }
                else if ((tokens.RegisteredTokens[index].Type &
                          (EnumTokenType.INTEGER_LITERAL | EnumTokenType.STRING_LITERAL)) > 0)
                {
                    value = tokens.RegisteredTokens[index];
                }
                Advance();
                AdvanceWhitespace();
                if (tokens.RegisteredTokens[index].Type == EnumTokenType.OPERATOR_TOKEN)
                {
                    //TODO Implement Chained Expressions
                    throw new NotImplementedException("Chained Expressions Are Not Implemented Yet");
                }
                else if (tokens.RegisteredTokens[index].Type == EnumTokenType.TYPE_TOKEN)
                {
                    type = tokens.RegisteredTokens[index];
                }
                if (Enum.TryParse <EnumTypes>(type.Value, true, out outT))
                {
                    string ty = outT.ToString().ToLower();
                    if (ty.Equals(type.Value))
                    {
                        node = new ValueExpressionASTNode(outT, value.Value, pCurrentAstNode);
                    }
                    else
                    {
                        ThrowError(EnumErrorCodes.INCORRECT_TYPE, "Expected: " + type.Value + " Found: " + ty);
                        return(false);
                    }
                }
                pCurrentAstNode = (BaseASTNode)node;
                break;
            }
            }
            return(true);
        }
示例#7
0
 public ValueExpressionASTNode(EnumTypes nodeDataType, string value, BaseASTNode pNodeData)
 {
     this.nodeDataType = nodeDataType;
     this.value        = value;
     this.PNodeData    = pNodeData;
 }
示例#8
0
 public LiteralExpressionASTNode(string expressionValue, BaseASTNode pNodeData)
 {
     this.expressionValue = expressionValue;
     this.PNodeData       = pNodeData;
 }