예제 #1
0
    public virtual Differences VisitDoWhile(DoWhile doWhile1, DoWhile doWhile2){
      Differences differences = new Differences(doWhile1, doWhile2);
      if (doWhile1 == null || doWhile2 == null){
        if (doWhile1 != doWhile2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      DoWhile changes = (DoWhile)doWhile2.Clone();
      DoWhile deletions = (DoWhile)doWhile2.Clone();
      DoWhile insertions = (DoWhile)doWhile2.Clone();

      Differences diff = this.VisitBlock(doWhile1.Body, doWhile2.Body);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Body = diff.Changes as Block;
      deletions.Body = diff.Deletions as Block;
      insertions.Body = diff.Insertions as Block;
      Debug.Assert(diff.Changes == changes.Body && diff.Deletions == deletions.Body && diff.Insertions == insertions.Body);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpressionList(doWhile1.Invariants, doWhile2.Invariants, out changes.Invariants, out deletions.Invariants, out insertions.Invariants);
      if (diff == null){Debug.Assert(false); return differences;}
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(doWhile1.Condition, doWhile2.Condition);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Condition = diff.Changes as Expression;
      deletions.Condition = diff.Deletions as Expression;
      insertions.Condition = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Condition && diff.Deletions == deletions.Condition && diff.Insertions == insertions.Condition);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
예제 #2
0
        public WordsCollection Analiza()
        {
            WordsCollection currentSymbol = new WordsCollection(); //Simbolo Actual obtenido del
            int             x             = 0;                     //Fila
            int             y             = 0;                     //Columna
            int             r             = 0;                     //Resultado (regla, desplazamiento o aceptacion)
            Estado          fila          = new Estado(0);

            int  pops      = 0;     //Cantidad de elementos que produce la regla
            bool error     = false; //Bandera que detiene el ciclo
            bool newSymbol = true;  //Decide si se necesita un nuevo simbolo del Lexico o no

            //Inicializa cola
            ColaSintactica.Push(new Estado(0));
            Node Root = new Node();

            //Ciclo que ejecuta el analisis sintactico
            while (!error)
            {
                if (newSymbol)
                {
                    currentSymbol = ALexico.sigSimbolo();
                }
                //x = (int)pila.Peek();
                x = ((Estado)pila.Peek()).transicion;
                y = currentSymbol.TypeId;

                r = TablaLR[x, y];
                Node nodo = new Node();
                nodo = null;

                if (r > 0)
                {
                    //Desplazamiento
                    //pila.Push(currentSymbol);
                    pila.Push(new Terminal(currentSymbol.Word));
                    //pila.Push(r);
                    pila.Push(new Estado(r));
                    newSymbol = true;
                }
                else if (r < 0)
                {
                    //Regla
                    r = Math.Abs(r) - 1;
                    if (r == 0)
                    {
                        //Cadena Aceptada
                        break;
                    }
                    // Obtencion de la cantidad de POPs a realizar en la cola.

                    switch (r)
                    {
                    //case 1:  //<programa> ::= <Definiciones>
                    //nodo=new  programa(pila);
                    //			break;

                    case 3:                          //<Definiciones> ::= <Definicion> <Definiciones>
                    case 16:                         //<DefLocales> ::= <DefLocal> <DefLocales>
                    case 20:                         //<Sentencias> ::= <Sentencia> <Sentencias>
                    case 32:                         //<Argumentos> ::= <Expresion> <ListaArgumentos>
                        pila.Pop();                  //quita estado
                        Node aux = (Node)pila.Pop(); //quita <definiciones>
                        pila.Pop();                  //quita estado
                        nodo = (Node)pila.Pop();     //quita <definicion>
                        if (nodo != null)
                        {
                            nodo.Siguiente = aux;
                        }
                        break;

                    case 1:
                    case 4:                      //<Definicion> ::= <DefVar>
                    case 5:                      //<Definicion> ::= <DefFunc>
                    case 17:                     //<DefLocal> ::= <DefVar>
                    case 18:                     //<DefLocal> ::= <Sentencia>
                    case 35:                     //<Atomo> ::= <LlamadaFunc>
                    case 39:                     //<SentenciaBloque> ::= <Sentencia>
                    case 40:                     //<SentenciaBloque> ::= <Bloque>
                    case 50:                     //<Expresion> ::= <Atomo>
                        pila.Pop();              //quita estado
                        nodo = (Node)pila.Pop(); //quita defvar
                        break;

                    case 6:    // <DefVar> ::= tipo id <ListaVar> ;
                        nodo = new DefVar(ref pila);

                        break;

                    case 8:                                                                      //<ListaVar> ::= , id <ListaVar>
                        pila.Pop();                                                              //quita estado
                        Node lvar = ((Node)pila.Pop());
                        pila.Pop();                                                              //quita estado
                        nodo           = new Identificador(((Terminal)pila.Pop()).nodo.Simbolo); //quita id
                        nodo.Siguiente = lvar;
                        pila.Pop();                                                              //quita estado
                        pila.Pop();                                                              //quita la coma
                        break;

                    case 9:    //<DefFunc> ::= tipo id ( <Parametros> ) <BloqFunc>
                        nodo = new DefFunc(ref pila);
                        break;

                    case 11:    //<Parametros> ::= tipo id <ListaParam>
                        nodo = new Parametros(ref pila);
                        break;

                    case 13:        //<ListaParam> ::= , tipo id <ListaParam>
                        nodo = new Parametros(ref pila);
                        pila.Pop(); //quita estado;
                        pila.Pop(); //quita la coma
                        break;

                    case 14:                       //<BloqFunc> ::= { <DefLocales> }
                    case 30:                       //<Bloque> ::= { <Sentencias> }
                    case 41:                       //<Expresion> ::= ( <Expresion> )
                        pila.Pop();                //quita estado
                        pila.Pop();                //quita }
                        pila.Pop();                //quita estado
                        nodo = ((Node)pila.Pop()); //quita <deflocales> o <sentencias>
                        pila.Pop();
                        pila.Pop();                //quita la {
                        break;

                    case 21:     //<Sentencia> ::= id = <Expresion> ;
                        nodo = new Asignacion(ref pila);
                        break;

                    case 22:    //<Sentencia> ::= if ( <Expresion> ) <SentenciaBloque> <Otro>
                        nodo = new If(ref pila);
                        break;

                    case 23:    //<Sentencia> ::= while ( <Expresion> ) <Bloque>
                        nodo = new While(ref pila);
                        break;

                    case 24:    //<Sentencia> ::= do <Bloque> while ( <Expresion> ) ;
                        nodo = new DoWhile(ref pila);
                        break;

                    case 25:    //<Sentencia> ::= for id = <Expresion> : <Expresion> : <Expresion> <SentenciaBloque>
                        nodo = new For(ref pila);
                        break;

                    case 26:    //<Sentencia> ::= return <Expresion> ;
                        nodo = new Return(ref pila);
                        break;

                    case 27:                       //<Sentencia> ::= <LlamadaFunc> ;
                        pila.Pop();
                        pila.Pop();                //quita ;
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita llamadafunc
                        break;

                    case 29:                       //<Otro> ::= else <SentenciaBloque>
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita sentencia bloque
                        pila.Pop();
                        pila.Pop();                //quita el else
                        break;

                    case 34:    // <ListaArgumentos> ::= , <Expresion> <ListaArgumentos>

                        pila.Pop();
                        aux = ((Node)pila.Pop());  //quita la lsta de argumentos
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita expresion
                        pila.Pop();
                        pila.Pop();                //quita la ,
                        nodo.Siguiente = aux;
                        break;

                    case 36:
                        pila.Pop();
                        nodo = new Identificador(((Terminal)pila.Pop()).nodo.Simbolo);
                        break;

                    case 37:
                        pila.Pop();
                        nodo = new Constante(((Terminal)pila.Pop()).nodo.Simbolo);
                        break;

                    case 38:
                        nodo = new LlamadaFunc(ref pila);
                        break;

                    //R42 < Expresion > ::= opSuma < Expresion >
                    //R43 < Expresion > ::= opNot < Expresion >
                    case 42:
                    case 43:
                        nodo = new Operacion1(ref pila);
                        break;

                    //R44 < Expresion > ::= < Expresion > opMul < Expresion >
                    //R45 < Expresion > ::= < Expresion > opSuma < Expresion >
                    //R46 < Expresion > ::= < Expresion > opRelac < Expresion >
                    //R47 < Expresion > ::= < Expresion > opIgualdad < Expresion >
                    //R48 < Expresion > ::= < Expresion > opAnd < Expresion >
                    //R49 < Expresion > ::= < Expresion > opOr < Expresion >
                    case 44:
                    case 45:
                    case 46:
                    case 47:
                    case 48:
                    case 49:
                        nodo = new Operacion2(ref pila);
                        break;

                    //aqui cae R2,R7,R10,R12,R15,R19,R28,R31,R33,
                    default:
                        pops = Rules.ElementAt(r).TotalProductions;

                        if (pops > 0)
                        {
                            while (pops > 0)
                            {
                                pila.Pop();
                                pila.Pop();
                                pops--;
                            }
                        }
                        break;
                    }
                    //x = (int)pila.Peek();
                    x = ((Estado)pila.Peek()).transicion; //((Estado)pila.Peek()).numestado;

                    y = rules.ElementAt(r).Id;            //columna= idreglas[regla];
                    NoTerminal nt = new NoTerminal(y);    //NoTerminal NT =new NoTerminal(idreglas[regla]);
                    //nt.nodo = nodo;
                    //pila.Push(rules.ElementAt(r).Id);
                    pila.Push(nodo);

                    r = tablaLR[x, y]; //transicion = tabla[fila][columna];
                    //pila.Push(r);
                    pila.Push(new Estado(r));
                    newSymbol = false;
                    Root      = nodo;
                }
                else
                {
                    //Error
                    error = true;
                }
            }

            Root.validatipos(ASemantico.Simbolos, ASemantico.Errores);
            if (error)
            {
                currentSymbol.ErrorSintactico = true;
            }
            if (ASemantico.Errores.Count > 0)
            {
                currentSymbol.ErrorSemantico = true;
                currentSymbol.Errores        = ASemantico.Errores;
                error = true;
            }


            return(error ? currentSymbol : null);
        }
 public override Statement VisitDoWhile(DoWhile doWhile)
 {
   throw new ApplicationException("unimplemented");
 }
예제 #4
0
 public override Statement VisitDoWhile(DoWhile doWhile) {
   if (doWhile == null) return null;
   this.loopCount++;
   doWhile.Invariants = this.VisitLoopInvariantList(doWhile.Invariants);
   doWhile.Body = this.VisitBlock(doWhile.Body);
   doWhile.Condition = this.VisitBooleanExpression(doWhile.Condition);
   this.loopCount--;
   return doWhile;
 }
예제 #5
0
 public override bool Walk(DoWhile node)
 {
     AddNode(node); return(true);
 }
예제 #6
0
 public override Statement VisitDoWhile(DoWhile doWhile)
 {
     if (doWhile == null) return null;
     return base.VisitDoWhile((DoWhile)doWhile.Clone());
 }
예제 #7
0
 /// <summary>
 /// Creates a matrix using a DO-WHILE statement.
 /// </summary>
 /// <param name="Elements">Elements.</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public MatrixDoWhileDefinition(DoWhile Elements, int Start, int Length, Expression Expression)
     : base(Elements, Start, Length, Expression)
 {
 }
 public void Visit(DoWhile node)
 {
     // not applicable; terminate
 }
예제 #9
0
 public virtual bool Walk(DoWhile node)
 {
     return(true);
 }
예제 #10
0
 protected virtual T VisitDoWhile(DoWhile W)
 {
     return(VisitUnknown(W));
 }
예제 #11
0
 public virtual void PostWalk(DoWhile node)
 {
 }
예제 #12
0
        static public Block ParseBlock(ref List <Token> .Enumerator tokens, Block parent, FunctionType func)
        {
            var thisBlock = new Block(parent);

            thisBlock.Function = func;

            // Climb the parents to find the function we are in
            if (func == null)
            {
                Block curBlock = thisBlock;
                do
                {
                    if (curBlock.Function != null)
                    {
                        func = curBlock.Function;
                    }
                    curBlock = curBlock.Parent;
                }while (curBlock != null);
            }

            if (parent != null)
            {
                thisBlock.TempDeclarationNumber = parent.TempDeclarationNumber;
            }

            while (tokens.Current != null && tokens.Current.Type != TokenType.CloseBlock)
            {
                if (tokens.Current.Text == "typedef")
                {
                }
                else if (tokens.Current.Text == "if")
                {
                    thisBlock.Statements.Add(If.ParseIf(thisBlock, ref tokens));
                }
                else if (tokens.Current.Text == "do")
                {
                    thisBlock.Statements.Add(DoWhile.Parse(thisBlock, ref tokens));
                }
                else if (tokens.Current.Text == "while")
                {
                    thisBlock.Statements.Add(While.Parse(thisBlock, ref tokens));
                }
                else if (tokens.Current.Text == "struct")
                {
                    tokens.MoveNext();
                    if (tokens.Current.Type != TokenType.OpenBlock)
                    {
                        throw new System.Exception("That was gay");
                    }
                }
                else if (tokens.Current.Text == "return")
                {
                    tokens.MoveNext();

                    if (tokens.Current.Type == TokenType.StatementEnd)
                    {
                        var returnStatement = new Return(null);
                        thisBlock.Statements.Add(returnStatement);
                        tokens.MoveNext();
                    }
                    else
                    {
                        var         returnList = Tokenizer.GetStatement(ref tokens);
                        Declaration decl       = thisBlock.CreateTempDeclaration(func.ReturnType);

                        StatementHelper.Parse(thisBlock, decl, returnList);

                        var returnStatement = new Return(decl);
                        thisBlock.Statements.Add(returnStatement);

                        tokens.MoveNext();
                    }
                }
                else
                {
                    FunctionType.CallConvention specifiedConvention = FunctionType.CallConvention.CalleeSave;
                    bool useStack = false;
                    while (tokens.Current.Text.StartsWith("__"))
                    {
                        switch (tokens.Current)
                        {
                        case "__usestack":
                            useStack = true;
                            break;

                        case "__stdcall":
                            specifiedConvention = FunctionType.CallConvention.CalleeSave;
                            break;

                        case "__cdecl":
                            specifiedConvention = FunctionType.CallConvention.CallerSave;
                            break;
                        }
                        tokens.MoveNext();
                    }

                    Declaration declForStatement = thisBlock.FindDeclaration(tokens.Current.Text);
                    if (declForStatement != null)
                    {
                        StatementHelper.Parse(thisBlock, Tokenizer.GetStatement(ref tokens));
                        Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                        tokens.MoveNext();
                    }
                    else
                    {
                        String resultName = String.Empty;
                        Type   resultType = TypeHelper.ParseType(ref tokens);
                        if (resultType == null)
                        {
                            StatementHelper.Parse(thisBlock, Tokenizer.GetStatement(ref tokens));
                            Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                            tokens.MoveNext();
                        }
                        else
                        {
                            // Read the name of the declaration/type
                            if (tokens.Current.Type == TokenType.StringType)
                            {
                                resultName = tokens.Current.Text;
                                tokens.MoveNext();
                            }

                            // in this case it's either a prototype or a function
                            // Either way it gets added to the types of this module
                            if (tokens.Current.Type == TokenType.OpenParen)
                            {
                                FunctionType function = new FunctionType(ref tokens, resultType)
                                {
                                    CallingConvention = specifiedConvention,
                                    UseStack          = useStack
                                };
                                resultType = function;
                                thisBlock.Types.Add(function);

                                if (tokens.Current.Type == TokenType.OpenBlock)
                                {
                                    var declaration = new Declaration(resultType, resultName);
                                    thisBlock.Declarations.Add(declaration);

                                    tokens.MoveNext();
                                    var block = Block.ParseBlock(ref tokens, thisBlock, function);

                                    Debug.Assert(tokens.Current.Type == TokenType.CloseBlock);
                                    tokens.MoveNext();

                                    declaration.Code = block;
                                    //STP: Not sure about this
                                    //thisBlock.Declarations.Add(declaration);
                                }
                                else
                                {
                                    Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                                    tokens.MoveNext();
                                }
                            }
                            else if (tokens.Current == "[")
                            {
                                resultType = new WabbitC.Model.Types.Array(resultType, ref tokens);
                                var declaration = new Declaration(resultType, resultName);
                                thisBlock.Declarations.Add(declaration);
                                Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                                tokens.MoveNext();
                            }
                            else
                            {
                                do
                                {
                                    var decl = new Declaration(resultType, resultName);
                                    thisBlock.Declarations.Add(decl);

                                    // Handle declarations with initial values
                                    if (tokens.Current.Text == "=")
                                    {
                                        tokens.MoveNext();

                                        var valueList = Tokenizer.GetStatement(ref tokens);
                                        StatementHelper.Parse(thisBlock, decl, valueList);

                                        if (tokens.Current.Text != ",")
                                        {
                                            Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                                            break;
                                        }
                                        else
                                        {
                                            tokens.MoveNext();
                                            Debug.Assert(tokens.Current.Type == TokenType.StringType);
                                            resultName = tokens.Current.Text;
                                            tokens.MoveNext();
                                        }
                                    }
                                    else
                                    {
                                        if (tokens.Current.Text != ",")
                                        {
                                            Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
                                            break;
                                        }
                                        else
                                        {
                                            tokens.MoveNext();
                                            Debug.Assert(tokens.Current.Type == TokenType.StringType);
                                            resultName = tokens.Current.Text;
                                            tokens.MoveNext();
                                        }
                                    }
                                } while (true);
                                tokens.MoveNext();
                            }
                        }
                    }
                }
            }
            return(thisBlock);
        }
예제 #13
0
        public virtual void Visit(DoWhile node)
        {
            if (node != null)
            {
                if (node.Body != null)
                {
                    node.Body.Accept(this);
                }

                if (node.Condition != null)
                {
                    node.Condition.Accept(this);
                }
            }
        }
예제 #14
0
        public void ProcessSysIo(string strIoName, bool bCurrentState)
        {
            if (InvokeRequired)
            {
                this.BeginInvoke(new Action(() => ProcessSysIo(strIoName, bCurrentState)));
            }
            else
            {
                if (strIoName == "急停" && !bCurrentState && GlobalVariable.g_StationState != StationState.StationStateEmg)
                {
                    bAlreadyEmg = true;
                    if (GlobalVariable.g_StationState == StationState.StationStateRun || GlobalVariable.g_StationState == StationState.StationStatePause)
                    {
                        MotionMgr.GetInstace().StopEmg();
                        StationMgr.GetInstance().Stop();
                        MotionMgr.GetInstace().StopEmg();
                    }
                    GlobalVariable.g_StationState = StationState.StationStateEmg;
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("绿灯", false);
                    }
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("红灯", false);
                    }
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("黄灯", false);
                    }
                    DoWhile.StopCirculate();
                    AlarmMgr.GetIntance().Warn("急停被按下", AlarmType.AlarmType_Emg);
                }

                if (strIoName == "气源压力检测" && !bCurrentState && !bAlreadyEmg)
                {
                    bAlreadyEmg = true;
                    if (GlobalVariable.g_StationState == StationState.StationStateRun || GlobalVariable.g_StationState == StationState.StationStatePause)
                    {
                        MotionMgr.GetInstace().StopEmg();
                        StationMgr.GetInstance().Stop();
                        MotionMgr.GetInstace().StopEmg();
                    }
                    GlobalVariable.g_StationState = StationState.StationStateStop;
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("绿灯", false);
                    }
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("红灯", false);
                    }
                    if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                    {
                        IOMgr.GetInstace().WriteIoBit("黄灯", false);
                    }

                    DoWhile.StopCirculate();
                    AlarmMgr.GetIntance().Warn("气源压力检测 失败", AlarmType.AlarmType_Emg);
                }

                if (strIoName == "安全门" && !bCurrentState)
                {
                    if (ParamSetMgr.GetInstance().GetBoolParam("启用安全门"))
                    {
                        if (GlobalVariable.g_StationState == StationState.StationStateRun)
                        {
                            StationMgr.GetInstance().Pause();
                            IOMgr.GetInstace().WriteIoBit("绿灯", false);
                            if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                            {
                                IOMgr.GetInstace().WriteIoBit("红灯", false);
                            }
                            if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                            {
                                IOMgr.GetInstace().WriteIoBit("黄灯", true);
                            }
                            if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                            {
                                IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                            }
                            //AlarmMgr.GetIntance().Warn("安全门打开");
                            MessageBox.Show("安全门打开", "Waran", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //  WaranResult waranResult = AlarmMgr.GetIntance().WarnWithDlg("安全门打开", null, DlgWaranType.WaranOK);
                        }
                    }
                }
                if (strIoName == "暂停" && bCurrentState)
                {
                    if (GlobalVariable.g_StationState == StationState.StationStateRun)
                    {
                        StationMgr.GetInstance().Pause();
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("绿灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("红灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("黄灯", true);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                        {
                            IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                        }
                        //AlarmMgr.GetIntance().Warn("安全门打开");
                        // WaranResult waranResult = AlarmMgr.GetIntance().WarnWithDlg("安全门打开", null, DlgWaranType.WaranOK);
                    }
                }
                if (strIoName == "安全光栅" && !bCurrentState)
                {
                    if (ParamSetMgr.GetInstance().GetBoolParam("启用安全光栅"))
                    {
                        if (ParamSetMgr.GetInstance().GetBoolParam("启用安全光栅"))
                        {
                            if (GlobalVariable.g_StationState == StationState.StationStateRun)
                            {
                                StationMgr.GetInstance().Pause();
                                IOMgr.GetInstace().WriteIoBit("绿灯", false);
                                if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                                {
                                    IOMgr.GetInstace().WriteIoBit("红灯", false);
                                }
                                if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                                {
                                    IOMgr.GetInstace().WriteIoBit("黄灯", true);
                                }
                                if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                                {
                                    IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                                }
                                //  AlarmMgr.GetIntance().Warn("安全光栅打开");
                                //WaranResult waranResult = AlarmMgr.GetIntance().WarnWithDlg("安全光栅打开", null, DlgWaranType.WaranOK);
                                MessageBox.Show("安全光栅打开", "Waran", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                }
                if (strIoName == "启动" && bCurrentState)
                {
                    if (GlobalVariable.g_StationState == StationState.StationStateStop)
                    {
                        if (!IsSafeDoorAndGrating())
                        {
                            return;
                        }
                        StationMgr.GetInstance().Run();
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("绿灯", true);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("红灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("黄灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                        {
                            IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                        }
                    }
                    else if (GlobalVariable.g_StationState == StationState.StationStatePause)
                    {
                        if (!IsSafeDoorAndGrating())
                        {
                            return;
                        }
                        StationMgr.GetInstance().Resume();
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("绿灯", true);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("红灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("黄灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                        {
                            IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                        }
                    }
                    else
                    {
                        MessageBox.Show("发生错误,请先复位", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                if (strIoName == "复位" && bCurrentState)
                {
                    if (GlobalVariable.g_StationState == StationState.StationStateEmg)
                    {
                        GlobalVariable.g_StationState = StationState.StationStateStop;
                        MotionMgr.GetInstace().ResetAxis();
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("绿灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("绿灯", true);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("红灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("红灯", false);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("黄灯"))
                        {
                            IOMgr.GetInstace().WriteIoBit("黄灯", true);
                        }
                        if (IOMgr.GetInstace().GetOutputDic().ContainsKey("蜂鸣"))
                        {
                            IOMgr.GetInstace().WriteIoBit("蜂鸣", false);
                        }

                        bStartAlarmTimer = false;
                        bAlreadyEmg      = false;
                    }
                }
            }
        }
예제 #15
0
        public WaranResult FindBuzzer(bool bManual = false)
        {
            if (sys.g_AppMode == AppMode.AirRun)
            {
                Info("左剥料站:空跑搜寻蜂鸣器成功");
                ParamSetMgr.GetInstance().SetBoolParam("左搜寻蜂鸣器成功", true);
                ParamSetMgr.GetInstance().SetBoolParam("左装料平台上升到位", true);
                return(WaranResult.Run);
            }
            if (!IOMgr.GetInstace().ReadIoInBit("左装料平台有无感应器"))
            {
                double pos = GetStationPointDic()["装料原始位"].pointZ;

                MoveSigleAxisPosWaitInpos(AxisZ, pos, MotionMgr.GetInstace().GetAxisMovePrm(AxisZ).VelH, 20, bManual, this);
                MotionMgr.GetInstace().StopAxis(AxisZ);
                Info("左剥离工站:装料平台无料");
                WaranResult waranResult = AlarmMgr.GetIntance().WarnWithDlg("左剥料:装料平台无料,请装料,装料完成点击<<重试>>按钮", bManual ? null : this, CommonDlg.DlgWaranType.WaranInorge_Stop_Pause_Retry);
                //if( WaranResult == WaranResult.)
                return(waranResult);
            }
            else
            {
                Info("左剥料工站:装料平台寻料");
                // MotionMgr.GetInstace().ResetAxis()
                DoWhile doWhile = new DoWhile((time, dowhile, bmanual, obj) =>
                {
                    int pos = MotionMgr.GetInstace().GetAxisPos(AxisZ);
                    if (this.GetStationPointDic().ContainsKey("装料最高位"))
                    {
                        if (pos > this.GetStationPointDic()["装料最高位"].pointZ)
                        {
                            Warn("左剥料工站:左装料平台寻找蜂鸣器, 已经到达最高位");
                            Info("左剥离工站:搜寻蜂鸣器失败");
                            ParamSetMgr.GetInstance().SetBoolParam("左搜寻蜂鸣器成功", false);
                            MotionMgr.GetInstace().StopAxis(AxisZ);
                            return(AlarmMgr.GetIntance().WarnWithDlg("左剥料:装料平台Z轴升至最高点 仍然没有检查到物料  请检查最高位设置,感应器之后,装料完成点击<<重试>>按钮", bManual ? null : this, CommonDlg.DlgWaranType.WaranInorge_Stop_Pause_Retry));
                        }
                        if (MotionMgr.GetInstace().IsAxisNormalStop(AxisZ) > AxisState.NormalStop)
                        {
                            Warn("左剥料工站:电机报警");
                            ParamSetMgr.GetInstance().SetBoolParam("左搜寻蜂鸣器成功", false);
                            return(AlarmMgr.GetIntance().WarnWithDlg("左剥料:装料平台Z轴电机报警 请检查电机及驱动器,装料完成点击<<重试>>按钮", bManual ? null : this, CommonDlg.DlgWaranType.WaranInorge_Stop_Pause_Retry));
                        }
                        if (IOMgr.GetInstace().ReadIoInBit("左装料Z轴上升到位感应器"))
                        {
                            MotionMgr.GetInstace().StopAxis(AxisZ);
                            double currentzaxisPos = MotionMgr.GetInstace().GetAxisPos(AxisZ);
                            currentzaxisPos        = currentzaxisPos + ParamSetMgr.GetInstance().GetDoubleParam("装料抬升距离") * nResolutionZ;
                            if (currentzaxisPos > GetStationPointDic()["装料最高位"].pointZ)
                            {
                                currentzaxisPos = GetStationPointDic()["装料最高位"].pointZ - 10;
                            }
                            MoveSigleAxisPosWaitInpos(AxisZ, currentzaxisPos, MotionMgr.GetInstace().GetAxisMovePrm(AxisZ).VelH, 20, bManual, this);

                            Info("左剥离工站:搜寻蜂鸣器成功");
                            ParamSetMgr.GetInstance().SetBoolParam("左搜寻蜂鸣器成功", true);
                            ParamSetMgr.GetInstance().SetBoolParam("左装料平台上升到位", true);
                            ParamSetMgr.GetInstance().SetIntParam("左蜂鸣器顶位", MotionMgr.GetInstace().GetAxisPos(AxisZ));
                            return(WaranResult.Run);
                        }
                        else
                        {
                            MotionMgr.GetInstace().JogMove(AxisZ, true, 0, (int)MotionMgr.GetInstace().GetAxisMovePrm(AxisZ).VelM);
                            return(WaranResult.CheckAgain);
                        }
                    }
                    else
                    {
                        double position = GetStationPointDic()["装料原始位"].pointZ;
                        MoveSigleAxisPosWaitInpos(AxisZ, position, MotionMgr.GetInstace().GetAxisMovePrm(AxisZ).VelH, 20, bManual, bManual ? null : this);
                        MotionMgr.GetInstace().StopAxis(AxisZ);
                        Info("左剥离工站:装料平台无料");
                        WaranResult waranResult = AlarmMgr.GetIntance().WarnWithDlg("左剥料:装料平台无料,请装料,装料完成点击<<重试>>按钮", bManual ? null : this, CommonDlg.DlgWaranType.WaranInorge_Stop_Pause_Retry);
                        return(waranResult);
                    }
                }, int.MaxValue);
                return(doWhile.doSomething(this, doWhile, bManual, null));
            }
        }
예제 #16
0
 public override Statement VisitDoWhile(DoWhile doWhile){
   if (doWhile == null) return null;
   StatementList statements = new StatementList(4);
   Block doWhileBlock = new Block(statements);
   doWhileBlock.SourceContext = doWhile.SourceContext;
   Block endOfLoop = new Block(null);
   Block conditionStart = new Block(null);
   this.continueTargets.Add(conditionStart);
   this.exitTargets.Add(endOfLoop);
   this.VisitBlock(doWhile.Body);
   ExpressionList invariants = doWhile.Invariants;
   if (invariants != null && invariants.Count > 0)
     statements.Add(VisitLoopInvariants(invariants));
   statements.Add(doWhile.Body);
   statements.Add(conditionStart);
   if (doWhile.Condition != null)
     statements.Add(this.VisitBranchCondition(doWhile.Condition, doWhileBlock, doWhile.Condition.SourceContext));
   statements.Add(endOfLoop);
   this.continueTargets.Count--;
   this.exitTargets.Count--;
   return doWhileBlock;
 }
예제 #17
0
파일: Visitor.cs 프로젝트: lulzzz/sito
 protected internal virtual T Visit(DoWhile node)
 {
     return(Visit(node as CodeNode));
 }
예제 #18
0
 public virtual void Visit(DoWhile node)
 {
     if (node != null)
     {
          AcceptChildren(node);
     }
 }
예제 #19
0
 protected override EP_VP1 Visit(DoWhile node)
 {
     node.Body.Visit(this);
     node.Condition.Visit(this);
     return(this);
 }
예제 #20
0
 public virtual Statement VisitDoWhile(DoWhile doWhile1, DoWhile doWhile2)
 {
     if (doWhile1 == null) return null;
     if (doWhile2 == null)
     {
         doWhile1.Invariants = this.VisitExpressionList(doWhile1.Invariants, null);
         doWhile1.Body = this.VisitBlock(doWhile1.Body, null);
         doWhile1.Condition = this.VisitExpression(doWhile1.Condition, null);
     }
     else
     {
         doWhile1.Invariants = this.VisitExpressionList(doWhile1.Invariants, doWhile2.Invariants);
         doWhile1.Body = this.VisitBlock(doWhile1.Body, doWhile2.Body);
         doWhile1.Condition = this.VisitExpression(doWhile1.Condition, doWhile2.Condition);
     }
     return doWhile1;
 }
예제 #21
0
 public override Statement VisitDoWhile(DoWhile doWhile)
 {
     throw new ApplicationException("unimplemented");
 }
예제 #22
0
 /// <summary>
 /// Creates a vector using a DO-WHILE statement.
 /// </summary>
 /// <param name="Elements">Elements.</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public VectorDoWhileDefinition(DoWhile Elements, int Start, int Length, Expression Expression)
     : base(Elements.LeftOperand, Elements.RightOperand, Start, Length, Expression)
 {
 }
예제 #23
0
        private async void Test_Click(object sender, EventArgs e)
        {
            int       nAxisNo   = textBox_AxisNo.Text.ToInt();
            double    dLen      = textBox_MoveDistance.Text.ToDouble();
            int       nCount    = textBox_Count.Text.ToInt();
            int       speedSel  = 0;
            SpeedType speedType = SpeedType.Low;

            if (radioButton_HighSpeed.Checked)
            {
                speedType = SpeedType.High;
                speedSel  = 1;
            }

            if (radioButton_MidSpeed.Checked)
            {
                speedSel  = 2;
                speedType = SpeedType.Mid;
            }

            if (radioButton_LowSpeed.Checked)
            {
                speedSel  = 3;
                speedType = SpeedType.Low;
            }
            if (speedSel == 0)
            {
                return;
            }
            Task task = Task.Run(() => {
                try
                {
                    DoWhile.ResetCirculate();
                    for (int i = 0; i < nCount; i++)
                    {
                        MotionMgr.GetInstace().RelativeMove(nAxisNo, (int)dLen, (int)speedType);
                        DoWhile doWhile = new DoWhile((time, dowhile, bmanual2, obj) =>
                        {
                            AxisState axisState = MotionMgr.GetInstace().IsAxisNormalStop(nAxisNo);
                            if (axisState == AxisState.NormalStop)
                            {
                                return(WaranResult.Run);
                            }
                            else if (axisState == AxisState.Moving)
                            {
                                return(WaranResult.CheckAgain);
                            }
                            else
                            {
                                logger.Warn(string.Format("{0}轴状态:{1}", nAxisNo, axisState));
                                throw new Exception("电机测试报警停止" + string.Format("{0}轴状态:{1}", nAxisNo, axisState));
                            }
                        }, 3000000);

                        doWhile.doSomething(null, doWhile, true, null);
                        Thread.Sleep(textBox_InPosDelay.Text.ToInt());

                        MotionMgr.GetInstace().RelativeMove(nAxisNo, (int)(-dLen), (int)speedType);

                        DoWhile doWhile2 = new DoWhile((time, dowhile, bmanual2, obj) =>
                        {
                            AxisState axisState = MotionMgr.GetInstace().IsAxisNormalStop(nAxisNo);
                            if (axisState == AxisState.NormalStop)
                            {
                                return(WaranResult.Run);
                            }
                            else if (axisState == AxisState.Moving)
                            {
                                return(WaranResult.CheckAgain);
                            }
                            else
                            {
                                logger.Warn(string.Format("{0}轴状态:{1}", nAxisNo, axisState));
                                throw new Exception("电机测试报警停止" + string.Format("{0}轴状态:{1}", nAxisNo, axisState));
                            }
                        }, 3000000);

                        doWhile2.doSomething(null, doWhile2, true, null);
                        Thread.Sleep(textBox_InPosDelay.Text.ToInt());
                    }
                }
                catch (Exception ex)
                {
                    MotionMgr.GetInstace().StopAxis(nAxisNo);
                    MessageBox.Show(ex.Message, "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            });
            await task;
        }
예제 #24
0
 public virtual void VisitDoWhile(DoWhile doWhile)
 {
   if (doWhile == null) return;
   this.VisitLoopInvariantList(doWhile.Invariants);
   this.VisitBlock(doWhile.Body);
   this.VisitExpression(doWhile.Condition);
 }
예제 #25
0
 public virtual bool Walk(DoWhile node) { return true; }
예제 #26
0
 public virtual Statement VisitDoWhile(DoWhile doWhile){
   if (doWhile == null) return null;
   doWhile.Invariants = this.VisitLoopInvariantList(doWhile.Invariants);
   doWhile.Body = this.VisitBlock(doWhile.Body);
   doWhile.Condition = this.VisitExpression(doWhile.Condition);
   return doWhile;
 }
예제 #27
0
 public virtual void PostWalk(DoWhile node) { }
예제 #28
0
 public virtual Statement VisitDoWhile(DoWhile doWhile, DoWhile changes, DoWhile deletions, DoWhile insertions){
   this.UpdateSourceContext(doWhile, changes);
   if (doWhile == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
       doWhile.Body = this.VisitBlock(doWhile.Body, changes.Body, deletions.Body, insertions.Body);
       doWhile.Condition = this.VisitExpression(doWhile.Condition, changes.Condition, deletions.Condition, insertions.Condition);
     }
   }else if (deletions != null)
     return null;
   return doWhile;
 }
예제 #29
0
        public static WaranResult JumpInPos(this ScaraRobot scaraRobot, Coordinate coordinate, HandDirection direction, bool bCheckHandleSys = false, bool bmauanl = false, int nTimeout = 20000)
        {
            logger.Info($"JumpInPos start pos{coordinate.X},{coordinate.Y},{coordinate.Z},{coordinate.U}");
            try
            {
                WaranResult waran   = WaranResult.Failture;
                bool        bcmd    = ScaraRobot.GetInstance().Jump(coordinate, direction, getLimit(coordinate));
                DoWhile     doWhile = new DoWhile((nTimeed, doWhile2, bmanual, objs) =>
                {
                    double dfine = 0.05;
                    bool bInPosX = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.X - coordinate.X) < dfine;
                    bool bInPosY = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.Y - coordinate.Y) < dfine;
                    // bool bInPosZ = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.Z - coordinate.Z) < dfine;
                    bool bInPosU = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.U - coordinate.U) < 0.1;
                    bool bInPos  = bInPosX && bInPosY && true && bInPosU;

                    if (!bmanual)
                    {
                        if (GlobalVariable.g_StationState == StationState.StationStatePause)
                        {
                            logger.Info($"JumpInPos  程序状态: {GlobalVariable.g_StationState }");
                            ScaraRobot.GetInstance().SetStopActionFlag();
                            return(WaranResult.CheckAgain);
                        }
                        else if (GlobalVariable.g_StationState == StationState.StationStateRun)
                        {
                            Thread.Sleep(50);
                            bInPosX = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.X - coordinate.X) < dfine;
                            bInPosY = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.Y - coordinate.Y) < dfine;
                            //  bInPosZ = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.Z - coordinate.Z) < dfine;
                            bInPosU = Math.Abs(ScaraRobot.GetInstance().CurrentPosition.U - coordinate.U) < 0.1;
                            bInPos  = bInPosX && bInPosY && true && bInPosU;
                            if (!bInPos)
                            {
                                Coordinate coordinatetemp = ScaraRobot.GetInstance().GetCurrentImmediately();
                                bInPosX = Math.Abs(coordinatetemp.X - coordinate.X) < dfine;
                                bInPosY = Math.Abs(coordinatetemp.Y - coordinate.Y) < dfine;
                                // bInPosZ = Math.Abs(coordinatetemp.Z - coordinate.Z) < dfine;
                                bInPosU = Math.Abs(coordinatetemp.U - coordinate.U) < 0.1;
                                bInPos  = bInPosX && bInPosY && true && bInPosU;
                            }
                            logger.Info($"JumpInPos  程序状态:{GlobalVariable.g_StationState} bInPos {bInPos}, 目标位置 {coordinate.X},{coordinate.Y},{coordinate.Z},{coordinate.U}" +
                                        $"实际位置: {ScaraRobot.GetInstance().CurrentPosition.X},{ScaraRobot.GetInstance().CurrentPosition.Y},{ScaraRobot.GetInstance().CurrentPosition.Z},{ScaraRobot.GetInstance().CurrentPosition.U}");

                            if (bInPos)
                            {
                                return(WaranResult.Run);
                            }
                            else if (ScaraRobot.GetInstance().InPos&& !bInPos)
                            {
                                ScaraRobot.GetInstance().ReasetStopActionFlag();
                                ScaraRobot.GetInstance().Jump(coordinate, direction, getLimit(coordinate));
                                return(WaranResult.CheckAgain);
                            }
                        }
                    }

                    if (nTimeed > nTimeout)
                    {
                        logger.Info($"JumpInPos  程序状态:{GlobalVariable.g_StationState} bInPos {bInPos}, 超时, 目标位置 {coordinate.X},{coordinate.Y},{coordinate.Z},{coordinate.U}" +
                                    $"实际位置: {ScaraRobot.GetInstance().CurrentPosition.X},{ScaraRobot.GetInstance().CurrentPosition.Y},{ScaraRobot.GetInstance().CurrentPosition.Z},{ScaraRobot.GetInstance().CurrentPosition.U}");

                        ScaraRobot.GetInstance().SetStopActionFlag();
                        ScaraRobot.GetInstance().SetStopActionFlag();
                        ScaraRobot.GetInstance().ReasetStopActionFlag();
                        logger.Info($"JumpInPos  程序状态:{GlobalVariable.g_StationState} bInPos {bInPos}, 复位, 目标位置 {coordinate.X},{coordinate.Y},{coordinate.Z},{coordinate.U}" +
                                    $"实际位置: {ScaraRobot.GetInstance().CurrentPosition.X},{ScaraRobot.GetInstance().CurrentPosition.Y},{ScaraRobot.GetInstance().CurrentPosition.Z},{ScaraRobot.GetInstance().CurrentPosition.U}");

                        return(WaranResult.TimeOut);
                    }

                    if (ScaraRobot.GetInstance().InPos&& bInPos)
                    {
                        return(WaranResult.Run);
                    }
                    else
                    {
                        return(WaranResult.CheckAgain);
                    }
                }
                                                  , 30000);
                return(doWhile.doSomething2(null, doWhile, bmauanl, null));
            }
            catch (Exception ex)
            {
                ScaraRobot.GetInstance().SetStopActionFlag();
                ScaraRobot.GetInstance().SetStopActionFlag();
                ScaraRobot.GetInstance().ReasetStopActionFlag();
                throw ex;
            }
        }