Ejemplo n.º 1
0
        private static Nodes.Assignment ArrayAssignment(Lexer.Lexem currLexem, Nodes.Node.Coords coords)
        {
            Nodes.Expression index = Expr();
            if (Lexer.LookAhead().LexType != Lexer.LexType.CloseSquadBracket)
                ErrorList.Add(new Error(ParserException.NeedCloseSquadBracket, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            if (Lexer.LookAhead().LexType == Lexer.LexType.EqualSign)
            {
                Lexer.NextLexem();
                Nodes.Expression value = Expr();
                /*if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                    ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
                else
                    Lexer.NextLexem();*/
                Nodes.Assignment result = new Nodes.Assignment(new Nodes.ElementOfArray(currLexem.VarName, index), value, coords);
                result.Head = result;
                result.Tail = result;
                return result;
            }
            else
            {
                while (Lexer.LookBack().LexType != Lexer.LexType.Variable)
                    Lexer.RollBack();
                Lexer.RollBack();
                return null;
            }
        }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 private static Nodes.Assignment Assignment()
 {
     Nodes.Node.Coords coords = Lexer.Coords;
     if (Lexer.LookAhead().LexType != Lexer.LexType.Variable)
         return null;
     Lexer.Lexem currLexem = Lexer.NextLexem();
     if (Lexer.LookAhead().LexType == Lexer.LexType.EqualSign)
     {
         Lexer.NextLexem();
         if (Lexer.LookAhead().LexType == Lexer.LexType.String)
         {
             Nodes.Expression strValue = Expr();
             /*if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                 ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
             else
                 Lexer.NextLexem();*/
             Nodes.Assignment result = new Nodes.Assignment(new Nodes.Variable(currLexem.VarName), strValue, coords);
             result.Head = result;
             result.Tail = result;
             return result;
         }
         else
             return VariableAssignment(currLexem, coords);
     }
     else
         if (Lexer.LookAhead().LexType == Lexer.LexType.OpenSquadBracket)
         {
             Lexer.NextLexem();
             return ArrayAssignment(currLexem, coords);
         }
         else
         {
             Lexer.RollBack();
             return null;
         }
 }
Ejemplo n.º 4
0
        private static Nodes.Assignment VariableAssignment(Lexer.Lexem currLexem, Nodes.Node.Coords coords)
        {
            Nodes.Expression value = Expr();
            /*if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
            {
                throw new ParserException();
            }
            Lexer.NextLexem();*/
            /*if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();*/
            Nodes.Assignment result = new Nodes.Assignment(new Nodes.IntVar(currLexem.VarName), value, coords);
            //Statements.Add(result);
            result.Head = result;
            result.Tail = result;

            return result;
        }