public void IsArithmeticVMCommand_InputInvalidAdditionCommand_ReturnsFalse()
        {
            string vmCommand = "addition";

            bool isArithmeticVMCommand = SyntaxValidator.IsArithmeticVMCommand(vmCommand);

            Assert.AreEqual(false, isArithmeticVMCommand);
        }
        public void IsConvertableToInteger_InputInvalidString_ReturnsFalse()
        {
            string vmCommand = "two";

            bool isConvertableToInteger = SyntaxValidator.IsConvertableToInteger(vmCommand);

            Assert.AreEqual(false, isConvertableToInteger);
        }
        public void IsArithmeticVMCommand_InputRandomSymbolsAndNumbers_ReturnsFalse()
        {
            string vmCommand = "%^$&432*^%231324";

            bool isArithmeticVMCommand = SyntaxValidator.IsArithmeticVMCommand(vmCommand);

            Assert.AreEqual(false, isArithmeticVMCommand);
        }
        public void IsArithmeticVMCommand_InputCommandWithSpace_ReturnsFalse()
        {
            string vmCommand = "    gt";

            bool isArithmeticVMCommand = SyntaxValidator.IsArithmeticVMCommand(vmCommand);

            Assert.AreEqual(false, isArithmeticVMCommand);
        }
        public void IsMemoryAccessVMCommand_InputValidPopStaticCommand_ReturnsTrue()
        {
            string vmCommand = "pop static 200";

            bool isMemoryAccessVMCommand = SyntaxValidator.IsMemoryAccessVMCommand(vmCommand);

            Assert.AreEqual(true, isMemoryAccessVMCommand);
        }
        public void IsMemoryAccessVMCommand_InputValidPushConstantCommand_ReturnsTrue()
        {
            string vmCommand = "push constant 909";

            bool isMemoryAccessVMCommand = SyntaxValidator.IsMemoryAccessVMCommand(vmCommand);

            Assert.AreEqual(true, isMemoryAccessVMCommand);
        }
        public void IsMemoryAccessVMCommand_InputInvalidPopConstantCommand_ReturnsFalse()
        {
            string vmCommand = "pop constant 200";

            bool isMemoryAccessVMCommand = SyntaxValidator.IsMemoryAccessVMCommand(vmCommand);

            Assert.AreEqual(false, isMemoryAccessVMCommand);
        }
        public void IsMemoryAccessVMCommand_InputInvalidPushCommand_ReturnsFalse()
        {
            string vmCommand = "push stack 245";

            bool isMemoryAccessVMCommand = SyntaxValidator.IsMemoryAccessVMCommand(vmCommand);

            Assert.AreEqual(false, isMemoryAccessVMCommand);
        }
        public void IsArithmeticVMCommand_InputAddCommand_ReturnsTrue()
        {
            string vmCommand = "add";

            bool isArithmeticVMCommand = SyntaxValidator.IsArithmeticVMCommand(vmCommand);

            Assert.AreEqual(true, isArithmeticVMCommand);
        }
        public void IsConvertableToInteger_InputValidString_ReturnsTrue()
        {
            string vmCommand = "2345";

            bool isConvertableToInteger = SyntaxValidator.IsConvertableToInteger(vmCommand);

            Assert.AreEqual(true, isConvertableToInteger);
        }
        public void IsMemoryAccessVMCommand_InputPushTempCommandWithoutValue_ReturnsFalse()
        {
            string vmCommand = "push temp";

            bool isMemoryAccessVMCommand = SyntaxValidator.IsMemoryAccessVMCommand(vmCommand);

            Assert.AreEqual(false, isMemoryAccessVMCommand);
        }
Ejemplo n.º 12
0
        private void SyntaxCheck(object sender, RoutedEventArgs e)
        {
            Button_Click(sender, e);
            var validator = new SyntaxValidator(_parsingResult);

            try
            {
                validator.CheckStatement();
            }catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error occured", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Validates the specified TOML document.
        /// </summary>
        /// <param name="doc">The TOML document to validate</param>
        /// <returns>The same instance as the parameter. Check <see cref="DocumentSyntax.HasErrors"/> and <see cref="DocumentSyntax.Diagnostics"/> for details.</returns>
        public static DocumentSyntax Validate(DocumentSyntax doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }
            if (doc.HasErrors)
            {
                return(doc);
            }
            var validator = new SyntaxValidator(doc.Diagnostics);

            validator.Visit(doc);
            return(doc);
        }
Ejemplo n.º 14
0
        public static void Main()
        {
            var language = Languages.Pascal;
            var filePath = "pascalDefinition.xml";

            language.Save(filePath);
            var loadedLanguage = Language.Load(filePath);

            Console.WriteLine($"Check if serialized and stored languages are equal: {language.Equals(loadedLanguage)}");
            var file      = @"TestData\test_code.pas";
            var fsm       = new StateMachine(filePath);
            var result    = fsm.Process(file);
            var validator = new SyntaxValidator(result);

            validator.CheckStatement();
            Console.ReadLine();
        }
        public void IsAddressInstruction_InputInvalidAddressInstruction_ReturnFalse()
        {
            bool isAddressInstruction = SyntaxValidator.IsAddressInstruction("@InvalidAddressInstruction");

            Assert.AreEqual(false, isAddressInstruction);
        }
        public void IsAddressInstructionWithSymbol_InputValidAddressInstructionWithSymbol_ReturnTrue()
        {
            bool isAddressInstructionWithLabel = SyntaxValidator.IsAddressInstructionWithSymbol("@R0");

            Assert.AreEqual(true, isAddressInstructionWithLabel);
        }
        public void IsAddressInstructionWithSymbol_InputAddressInstructionWithSymbolAndRightWhitespacePadding_ReturnFalse()
        {
            bool isAddressInstructionWithLabel = SyntaxValidator.IsAddressInstructionWithSymbol("@R0           ");

            Assert.AreEqual(false, isAddressInstructionWithLabel);
        }
        public void IsAddressInstructionWithSymbol_InputInvalidAddressInstructionWithSymbol_ReturnFalse()
        {
            bool isAddressInstructionWithLabel = SyntaxValidator.IsAddressInstructionWithSymbol("@1InvalidLabel");

            Assert.AreEqual(false, isAddressInstructionWithLabel);
        }
        public void IsComputationInstruction_InputValidComputationInstruction_ReturnTrue()
        {
            bool isComputationInstrucation = SyntaxValidator.IsComputationInstruction("D=D+M");

            Assert.AreEqual(true, isComputationInstrucation);
        }
        public void IsComputationInstruction_InputInvalidComputationInstruction_ReturnFalse()
        {
            bool isComputationInstrucation = SyntaxValidator.IsComputationInstruction("D=SCREEN");

            Assert.AreEqual(false, isComputationInstrucation);
        }
        public void IsLabel_InputValidLabel_ReturnTrue()
        {
            bool isLabel = SyntaxValidator.IsLabel("(TESTLABEL)");

            Assert.AreEqual(true, isLabel);
        }
        public void IsAddressInstruction_InputValidAddressInstruction_ReturnTrue()
        {
            bool isAddressInstruction = SyntaxValidator.IsAddressInstruction("@1234");

            Assert.AreEqual(true, isAddressInstruction);
        }
        public void IsLabel_InputInvalidLabel_ReturnFalse()
        {
            bool isLabel = SyntaxValidator.IsLabel("D=D+1");

            Assert.AreEqual(false, isLabel);
        }
        public void IsAddressInstruction_InputAddressInstructionWithRightWhitespacePadding_ReturnFalse()
        {
            bool isAddressInstruction = SyntaxValidator.IsAddressInstruction("@1234     ");

            Assert.AreEqual(false, isAddressInstruction);
        }