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 SyntaxAnalysisResult Parse()
        {
            SyntaxAnalysisResult result = new SyntaxAnalysisResult();

            try
            {
                result.SyntaxParsed = ParseSyntax();
            }
            catch (Exception ex)
            {
                result.SyntaxParsed = false;
                result.Exception    = ex;
            }

            return(result);
        }