Example #1
0
 public SintaxController(ISymbolsHelper symbolsHelper)
 {
     _result         = new List <SintaxResponseViewModel>();
     _toValidate     = new ToValidateViewModel();
     _symbolsHelper  = symbolsHelper;
     _sintaxResponse = new SintaxResponseViewModel();
 }
Example #2
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            txtResult.Text = "";
            ToValidateViewModel view = new ToValidateViewModel
            {
                Text = txtCode.Text + " "
            };
            LexerController lexer = new LexerController();
            IEnumerable <TokenViewModel> result = lexer.FindToken(view);

            foreach (var item in result)
            {
                txtResult.Text += $"The token type for {item.Text} is {item.TypeToken.ToString()} \n";
            }
        }
Example #3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            txtResult.Text = "";
            ToValidateViewModel view = new ToValidateViewModel
            {
                Text = txtCode.Text + " "
            };
            SintaxController sintax = new SintaxController(_symbolsHelper);
            List <SintaxResponseViewModel> result2 = sintax.GetSintaxAnalisis(txtCode.Text);
            LexerController       lexer            = new LexerController(_symbolsHelper);
            List <TokenViewModel> result           = lexer.FindToken(view);

            foreach (var item in result)
            {
                txtResult.Text += $"Token for {item.Text} is {item.TypeToken.ToString()} and {item.TextToIdentifier}\n";
            }
        }
Example #4
0
        public List <TokenViewModel> FindToken(string text)
        {
            bool ban;
            bool IsQuote = false;

            ToValidateViewModel toValidate = new ToValidateViewModel
            {
                Text = text
            };

            List <TokenViewModel> tokenList = new List <TokenViewModel>();

            toValidate.StringPosition = FirstCharacterPosition(toValidate.Text);

            for (int i = toValidate.StringPosition; i < toValidate.Text.Length; i++)
            {
                ban = false;

                toValidate.CharToValidate = toValidate.Text[i];

                if (_symbolsHelper.IsQuote(toValidate.CharToValidate))
                {
                    IsQuote = !IsQuote;
                }

                if ((char.IsWhiteSpace(toValidate.CharToValidate) || _symbolsHelper.IsParen(toValidate.CharToValidate) ||
                     _symbolsHelper.IsComma(toValidate.CharToValidate)) && (!IsQuote) && toValidate.TextToValidate != "")
                {
                    tokenList.Add(ToToken(toValidate.TextToValidate));
                    toValidate.TextToValidate = "";
                    ban = true;
                }

                if (!ban && !char.IsWhiteSpace(toValidate.CharToValidate))
                {
                    toValidate.TextToValidate += toValidate.CharToValidate;
                }
            }

            return(tokenList);
        }
Example #5
0
        public IEnumerable <TokenViewModel> FindToken(ToValidateViewModel toValidate)
        {
            bool ban;
            bool IsQuote = false;

            AddLanguage();

            List <TokenViewModel> tokenList = new List <TokenViewModel>();

            toValidate.StringPosition = FirstCharacterPosition(toValidate.Text);

            for (int i = toValidate.StringPosition; i < toValidate.Text.Length; i++)
            {
                ban = false;

                toValidate.CharToValidate = toValidate.Text[i];

                if (toValidate.CharToValidate.ToString().Equals("'"))
                {
                    IsQuote = !IsQuote;
                }

                if (char.IsWhiteSpace(toValidate.CharToValidate) && (!IsQuote))
                {
                    tokenList.Add(ToToken(toValidate.TextToValidate));
                    toValidate.TextToValidate = "";
                    ban = true;
                }

                if (!ban)
                {
                    toValidate.TextToValidate += toValidate.CharToValidate;
                }
            }

            return(tokenList);
        }