Example #1
0
 public While(Condition condition, Statement first, End end)
 {
     Condition = condition;
     FirstStatement = first;
     Head = condition;
     Tail = end;
 }
Example #2
0
 public If(Condition condition, Statement ifBlock, Statement elseBlock, End end, Node.Coords coords)
 {
     Condition = condition;
     IfBlock = ifBlock;
     ElseBlock = elseBlock;
     Head = condition;
     Tail = end;
     this.Coords = coords;
 }
Example #3
0
 public For(Assignment assn, Condition cond, Assignment chngAssn, Statement first, End end, Node.Coords coords)
 {
     Assignment = assn;
     Condition = cond;
     ChngAssignment = chngAssn;
     FirstStatement = first;
     Head = assn;
     Tail = end;
     this.Coords = coords;
 }
Example #4
0
        private static Nodes.While While()
        {
            Nodes.Node.Coords coords = Lexer.Coords;
            if (Lexer.LookAhead().LexType != Lexer.LexType.While)
                return null;

            Lexer.NextLexem();
            //Lexer.SkipSpacesCoords();

            if (Lexer.LookAhead().LexType != Lexer.LexType.OpenBreaket)
                ErrorList.Add(new Error(ParserException.MissedOpenBracket, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            Nodes.Condition condition = Condition();

            if (Lexer.LookAhead().LexType != Lexer.LexType.CloseBracket)
                ErrorList.Add(new Error(ParserException.MissedCloseBracket, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            Nodes.End end = new Nodes.End();

            Nodes.Statement head = Block(condition);

            condition.NextFalse = end;
            condition.NextTrue = head.Head;

            //Statements.Add(end);
            Nodes.While result = new Nodes.While(condition, head, end);

            result.Head = result;
            result.Tail = result;
            result.Coords = coords;

            return result;
        }
Example #5
0
        private static Nodes.If If()
        {
            Nodes.Node.Coords coords = Lexer.Coords;
            if (Lexer.LookAhead().LexType != Lexer.LexType.If)
            {
                return null;
            }

            Lexer.NextLexem();
            //Lexer.SkipSpacesCoords();

            if (Lexer.LookAhead().LexType != Lexer.LexType.OpenBreaket)
            {
                ErrorList.Add(new Error(ParserException.MissedOpenBracket, Lexer.LookBack().EndCoords));
            }
            else
                Lexer.NextLexem();

            /*Lexer.Lexem nextLexem = Lexer.LookAhead();
            if (nextLexem.LexType != Lexer.LexType.Number && nextLexem.LexType != Lexer.LexType.Variable && nextLexem.LexType != Lexer.LexType.OpenBreaket)
                Lexer.NextLexem();*/

            Nodes.Condition condition = Condition();

            if (Lexer.LookAhead().LexType != Lexer.LexType.CloseBracket)
            {
                ErrorList.Add(new Error(ParserException.MissedCloseBracket, Lexer.LookBack().EndCoords));
            }
            else
                Lexer.NextLexem();

            Nodes.End end = new Nodes.End();

            Nodes.Statement ifBlock = Block(end);

            Nodes.Statement elseBlock = null;
            if (Lexer.LookAhead().LexType == Lexer.LexType.Else)
            {
                Lexer.NextLexem();
                elseBlock = Block(end);
            }

            condition.NextTrue = ifBlock.Head;
            if (elseBlock != null)
                condition.NextFalse = elseBlock.Head;
            else
                condition.NextFalse = end;

            //Statements.Add(end);
            return new Nodes.If(condition, ifBlock, elseBlock, end, coords);
        }
Example #6
0
        private static Nodes.For For()
        {
            Nodes.Node.Coords coords = Lexer.Coords;
            if (Lexer.LookAhead().LexType != Lexer.LexType.For)
            {
                return null;
            }

            Lexer.NextLexem();
            //Lexer.SkipSpacesCoords();

            if (Lexer.LookAhead().LexType != Lexer.LexType.OpenBreaket)
            {
                ErrorList.Add(new Error(ParserException.MissedOpenBracket, Lexer.LookBack().EndCoords));
            }
            else
                Lexer.NextLexem();

            /*if (Lexer.LookAhead().LexType != Lexer.LexType.Variable)
                Lexer.NextLexem();*/
            Nodes.Assignment assgn = Assignment();
            //Statements.Add(assgn);

            if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            /*Lexer.Lexem nextLexem = Lexer.LookAhead();
            if (nextLexem.LexType != Lexer.LexType.Number && nextLexem.LexType != Lexer.LexType.Variable && nextLexem.LexType != Lexer.LexType.OpenBreaket)
                Lexer.NextLexem();*/

            Nodes.Condition cond = Condition();
            assgn.Next = cond;
            //Statements.Add(cond);

            if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            /*if (Lexer.LookAhead().LexType != Lexer.LexType.Variable)
                Lexer.NextLexem();*/

            Nodes.Assignment chngAssgn = Assignment();
            chngAssgn.Next = cond;

            Nodes.End end = new Nodes.End();
            cond.NextFalse = end;

            if (Lexer.LookAhead().LexType != Lexer.LexType.CloseBracket)
                ErrorList.Add(new Error(ParserException.MissedCloseBracket, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            Nodes.Statement FirstStatement = Block(chngAssgn);
            cond.NextTrue = FirstStatement.Head;

            //Statements.Add(end);

            return new Nodes.For(assgn, cond, chngAssgn, FirstStatement, end, coords);
        }