示例#1
0
        internal NCProgram Interpret(out string[] errors)
        {
            List<string> lines = new List<string>();
            string line;
            System.IO.StreamReader file = new System.IO.StreamReader(filepath);
            while ((line = file.ReadLine()) != null)
            {
                line = line.ToUpper();
                lines.Add(line);
            }

            file.Close();

            SinumerikProgram prog = new SinumerikProgram();
            string pattern = @"[A-Z\d.-]+";
            for (int i = 0; i < lines.Count; i++)
            {
                string l = lines[i];
                SearchComment(ref l);
                var matches = Regex.Matches(l, pattern);
                if(matches.Count == 0)
                    continue;
                checkMatchesLine(prog, matches, i, prog);
            }
            CheckProgramEnd(prog.Sentences);
            CheckProgramSemantics(prog);
            errors = new string[Errors.Count + 1];
            errors[0] = Errors.Count + " error(s) detected";
            for (int i = 1; i <= Errors.Count; i++)
                errors[i] = Errors[i-1].ToString();
            IsErrorFree = Errors.Count == 0;
            return prog;
        }
示例#2
0
 private void CheckProgramSemantics(SinumerikProgram prog)
 {
     short currentTool = -1;
     for (int i = 0; i < prog.Sentences.Count; i++)
     {
         Sentence s = prog.Sentences[i];
         if (s.Y < 0)
             Errors.Add(new Error(i + 1, 0, "X coordinates must not be negative"));
         if (s.G[0] || s.G[1] || s.G[2] || s.G[3])
         {
             if (currentTool < 0)
                 Errors.Add(new Error(i + 1, 0, "No tool was specified"));
         }
         if (s.T >= 0)
             currentTool = s.T;
     }
 }
示例#3
0
 private void checkMatchesLine(NCProgram prog, MatchCollection matches, int line, SinumerikProgram p)
 {
     SinumerikSentence s = new SinumerikSentence();
     foreach (Match m in matches)
     {
         switch (m.Value[0])
         {
             case 'N': CheckFourDigitWord(out s.NWord, m, line, m.Index, "N");  break;
             case 'G': CheckTwoDigitWord(ref s.GWords, m, line, m.Index, "G"); break;
             case 'X': CheckDecimalWord(out s.YWord, m, line, m.Index, "X");  break;
             case 'Z': CheckDecimalWord(out s.XWord, m, line, m.Index, "Z"); break;
             case 'I': CheckDecimalWord(out s.IWord, m, line, m.Index, "I"); break;
             case 'K': CheckDecimalWord(out s.KWord, m, line, m.Index, "K"); break;
             case 'F': CheckFourDigitWord(out s.FWord, m, line, m.Index, "F"); break;
             case 'T': CheckFourDigitWord(out s.TWord, m, line, m.Index, "T"); CheckTool(s.TWord, line, m.Index);  break;
             case 'S': CheckFourDigitWord(out s.SWord, m, line, m.Index, "S"); break;
             case 'M': CheckTwoDigitWord(ref s.MWords, m, line, m.Index, "M"); break;
             default: Errors.Add(new Error(line+1, 0, "Illegal sentence")); break;
         }
     }
     prog.AddSentence(s);
 }