Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Read file
            string       sampleFileName = "First.txt";
            MyFileReader myFileReader   = new MyFileReader(sampleFileName);
            string       text           = myFileReader.ReadFile();

            //Make tokens
            Token[] tokens = new LexicalAnalysis().ProcessTextAndGenerateTokens(text);
            tokens.ToList().ForEach(t => Console.WriteLine(t.ToString()));
            Console.WriteLine("--------------------------------------------------------------------\n\n");

            //Parse syntax analysis phase
            SyntaxAnalysis       syntaxAnalysis       = new SyntaxAnalysis(tokens);
            SyntaxAnalysisResult syntaxAnalysisResult = syntaxAnalysis.Parse();

            if (!syntaxAnalysisResult.SyntaxParsed)
            {
                Console.WriteLine(syntaxAnalysisResult.Exception.Message);
            }
            else
            {
                Console.WriteLine("Syntax Analysis phase passed");
            }



            Console.Read();
        }
Ejemplo n.º 2
0
 public CompareForm(SyntaxAnalysis sa, GPDictionary gpDict, LFDictionary lfDict)
 {
     this.sa     = sa;
     this.gpDict = gpDict;
     this.lfDict = lfDict;
     InitializeComponent();
 }
Ejemplo n.º 3
0
 public ImportGPForm(string fileName, SyntaxAnalysis sa, GPDictionary gpDict)
 {
     InitializeComponent();
     this.fileName = fileName;
     this.sa       = sa;
     this.gpDict   = gpDict;
 }
Ejemplo n.º 4
0
 public EditLFDictForm(LFDictionary lfDict, SyntaxAnalysis sa)
 {
     InitializeComponent();
     this.lfDict = lfDict;
     this.sa     = sa;
     lbLf.Items.AddRange(lfDict.GetList());
     labNum.Text = string.Format("Объем: {0}", lbLf.Items.Count);
 }
Ejemplo n.º 5
0
 public EditGPDictForm(GPDictionary gpDict, SyntaxAnalysis sa)
 {
     InitializeComponent();
     this.gpDict = gpDict;
     this.sa     = sa;
     lbGp.Items.AddRange(gpDict.GetList());
     lbGpFreq.Items.AddRange(gpDict.GetFreqList());
     labNum.Text = string.Format("Объем: {0}", lbGp.Items.Count);
 }
Ejemplo n.º 6
0
        public ImportLFForm(string fileName, SyntaxAnalysis sa, LFDictionary lfDict)
        {
            this.lfDict   = lfDict;
            this.sa       = sa;
            this.fileName = fileName;
            InitializeComponent();
            int valMax = Enum.GetValues(typeof(LexFunction)).Length;

            for (int i = 1; i < valMax; i++)
            {
                lvLf.Items.Add(((LexFunction)i).ToString());
            }
        }
Ejemplo n.º 7
0
        public ResForm(STNode[] arrRootX, STNode[] arrRootY,
                       double[,] matrCmp, double [,] matrParent, double[,] matr,
                       int[] arrIndex, SyntaxAnalysis sa, double res)
        {
            InitializeComponent();
            tvSa.Nodes.AddRange(sa.CreateTreeNodes(arrRootX));
            tvSa.ExpandAll();
            tbRes.Text = res.ToString();

            List <STNode> listNodeX = STNode.GetDescendants(arrRootX);
            List <STNode> listNodeY = STNode.GetDescendants(arrRootY);

            wbCmp.DocumentText  = MatrToHTML(matrCmp, listNodeX, listNodeY, arrIndex);
            wbPar.DocumentText  = MatrToHTML(matrParent, listNodeX, listNodeY, arrIndex);
            wbMatr.DocumentText = MatrToHTML(matr, listNodeX, listNodeY, arrIndex);
        }
Ejemplo n.º 8
0
        private bool Build()
        {
            try
            {
                LexicalAnalysis scanner;
                ClearAnalysersRichTextBoxes();

                string fileName = currentFileName ?? defaultFileName;

                var writeToFile = new StreamWriter(fileName, false, Encoding.Unicode);
                writeToFile.Write(textEditor.Text);
                writeToFile.Close();

                using (TextReader input = File.OpenText(fileName))
                {
                    scanner = new LexicalAnalysis(input);
                }

                FillLexicalAnalysisTab(scanner.Tokens);

                var parser = new SyntaxAnalysis(scanner.Tokens);
                FillSyntaxAnalysisTab(parser.Result);

                var generator = new Generator(parser.Result, Path.GetFileNameWithoutExtension(fileName) + ".exe");

                TextRange tr = new TextRange(outputRichTextBlock.Document.ContentStart, outputRichTextBlock.Document.ContentStart);
                tr.Text = DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff") + " | >>> " +
                          Path.GetFileNameWithoutExtension(fileName) + ".exe successfully build. \r\n";
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Black);
            }
            catch (Exception ex)
            {
                TextRange tr = new TextRange(outputRichTextBlock.Document.ContentStart, outputRichTextBlock.Document.ContentStart);
                tr.Text = DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff") + " | " + ex.GetType().Name + " >>> Error: " +
                          ex.Message + "\r\n";

                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);

                ClearAndFillDefaultValuesAnalysersRichTextBoxes();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
 void MainForm_Load(object sender, EventArgs e)
 {
     sa = new SyntaxAnalysis("dictionary.xml", false, false, 2);
 }