示例#1
0
        private AST_identifier Parse_identifier(TokenKind followSet)
        {
            IncrementDepth();

            AST_identifier identifier;

            Token t = GetNextToken();

            if (t.Kind == Identifier)
            {
                identifier        = new AST_identifier(t.Lexeme);
                identifier.Row    = t.Row;
                identifier.Column = t.Column;
                DebugPrint("identifier: " + t.Lexeme);
            }
            else
            {
                Error("Identifier expected, '" + t.ToString() + "' found.", t);
                SkipUntilFollow(followSet);
                identifier = new AST_identifier("");
            }

            DecrementDepth();

            return(identifier);
        }
示例#2
0
        private AST_read_statement Parse_read_statement()
        {
            IncrementDepth();

            AST_read_statement read_statement;

            Match(read_Keyword);
            AST_identifier identifier = Parse_identifier(Semicolon);

            DebugPrint("read_statement, identifier = " + identifier.Name);

            read_statement = new AST_read_statement(identifier);

            DecrementDepth();

            return(read_statement);
        }
示例#3
0
        override public void Visit(AST_identifier identifier)
        {
            base.Visit(identifier);
            string name = identifier.Name;

            if (name.Length > 0)
            {
                if (variables.ContainsKey(name))
                {
                    identifier.Declaration = variables.GetValueOrDefault(name);
                    if (identifier.Declaration.Type != null)
                    {
                        identifier.DataType = identifier.Declaration.Type.Kind;
                    }
                }
                else
                {
                    Error("Variable '" + name + "' has not been declared.", identifier);
                }
            }
        }
示例#4
0
        public void IncrementVariable(AST_identifier identifier)
        {
            Variable var = variables.GetValueOrDefault(identifier.Name);

            var.Set(var.IntValue + 1);
        }
示例#5
0
 override public void Visit(AST_identifier identifier)
 {
     this.value = variables.GetValueOrDefault(identifier.Name).Copy();
 }
示例#6
0
        private AST_for_statement Parse_for_statement()
        {
            IncrementDepth();
            DebugPrint("for_statement");

            AST_for_statement  for_statement  = null;
            AST_expression     from           = null;
            AST_expression     to             = null;
            AST_statement_list statement_list = null;

            Match(for_Keyword);
            AST_identifier identifier = Parse_identifier(in_Keyword);

            bool skipForDo = false;
            bool skipAll   = false;

            if (!Match(in_Keyword))
            {
                Error("'in' expected.", lastReadToken);
                // Prefer to skip for .. do and still process the statement_list,
                // worst case is to skip everything until 'end for'
                SkipUntilFollow(do_Keyword | end_Keyword);
                if (LookAheadToken().Kind == end_Keyword)
                {
                    Match(end_Keyword);
                    Match(for_Keyword);
                    skipAll = true;
                }
                else
                {
                    Match(do_Keyword);
                    skipForDo = true;
                }
            }
            if (!skipAll)
            {
                if (!skipForDo)
                {
                    from = Parse_expression(RangeDots);
                    if (!Match(RangeDots))
                    {
                        SkipUntilFollow(do_Keyword | end_Keyword);
                        if (LookAheadToken().Kind == end_Keyword)
                        {
                            Match(end_Keyword);
                            Match(for_Keyword);
                            skipAll = true;
                        }
                        else
                        {
                            Match(do_Keyword);
                            skipForDo = true;
                        }
                    }
                    if (!skipAll && !skipForDo)
                    {
                        to = Parse_expression(do_Keyword | end_Keyword);
                        if (!Match(do_Keyword))
                        {
                            Error("'do' expected.", lastReadToken);
                            ReuseToken();
                        }
                    }
                }
                if (!skipAll)
                {
                    statement_list = Parse_statement_list();
                    if (!Match(end_Keyword))
                    {
                        Error("'end for' or a statement expected.", lastReadToken);
                        SkipUntilFollow(Semicolon);
                    }
                    else
                    {
                        if (!Match(for_Keyword))
                        {
                            Error("'end for' expected.", lastReadToken);
                            SkipUntilFollow(Semicolon);
                        }
                    }
                }
            }

            for_statement = new AST_for_statement(identifier, from, to, statement_list);

            DecrementDepth();

            return(for_statement);
        }
示例#7
0
 public virtual void Visit(AST_identifier identifier)
 {
 }