Inheritance: MessageProducer
示例#1
0
        public Token(Source source)
        {
            this.source = source;
            this.lineNumber = source.lineNum;
            this.position = source.currentPos;

            extract();
        }
 public static Parser createParser(string language, string type, Source source)
 {
     if (StringComparer.CurrentCultureIgnoreCase.Equals(language, "Pascal") && StringComparer.CurrentCultureIgnoreCase.Equals(type, "top-down"))
     {
         Scanner scanner = new PascalScanner(source);
         return new PascalParserTD(scanner);
     }
     else if (!StringComparer.CurrentCultureIgnoreCase.Equals(language, "Pascal"))
         throw new Exception("Parser factory: Invalid language '" + language + "'");
     else
         throw new Exception("Parser factory: Invalid type '" + type + "'");
 }
示例#3
0
        public Pascal(string operation, string filePath, string flags)
        {
            try
            {
                bool intermediate = flags.IndexOf('i') > -1;
                bool xref = flags.IndexOf('x') > -1;

                source = new Source(new StreamReader(filePath));
                source.addMessageListener(new SourceMessageListener());

                parser = FrontendFactory.createParser("Pascal", "top-down", source);
                parser.addMessageListener(new ParserMessageListener());

                backend = BackendFactory.createBackend(operation);
                backend.addMessageListener(new BackendMessageListener());

                parser.parse();
                source.close();

                iCode = parser.iCode;
                symbolTableStack = Parser.symbolTableStack;

                if (xref)
                {
                    CrossReferencer crossReferencer = new CrossReferencer();
                    crossReferencer.Print(symbolTableStack);
                }

                if (intermediate)
                {
                    ParseTreePrinter treePrinter =  new ParseTreePrinter(Console.Out);
                    treePrinter.Print(iCode);
                }
                backend.process(iCode, symbolTableStack);
            }

            catch (Exception e)
            {
                Console.WriteLine("***** Internal translator error. *****");
                Console.WriteLine(e.StackTrace);
            }
        }
示例#4
0
 public Scanner(Source source)
 {
     this.source = source;
 }
示例#5
0
 // Do nothing. Do not consume any source characters.
 protected void extract(Source source)
 {
 }
示例#6
0
 public EofToken(Source source)
     : base(source)
 {
 }