示例#1
0
        static void Main(string[] args)
        {
            string input = "log(10 + A1 * 35 + (5.4 - 7.4))";

            ICharStream       inputStream       = CharStreams.fromString(input);
            SpreadsheetLexer  spreadsheetLexer  = new SpreadsheetLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(spreadsheetLexer);
            SpreadsheetParser spreadsheetParser = new SpreadsheetParser(commonTokenStream);

            SpreadsheetParser.ExpressionContext expressionContext = spreadsheetParser.expression();
            DoubleSpreadsheetVisitor            visitor           = new DoubleSpreadsheetVisitor();

            Console.WriteLine(visitor.Visit(expressionContext));
        }
示例#2
0
        public static void Main()
        {
            const string input = "log(10 + A1 * 35 + (5.4 - 7.4))";

            // C# uses Antlr4.Runtime.AntlrInputStream instead of Java's org.antlr.v4.runtime.CharStream
            var inputStream       = new AntlrInputStream(input);
            var spreadsheetLexer  = new SpreadsheetLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(spreadsheetLexer);
            var spreadsheetParser = new SpreadsheetParser(commonTokenStream);

            var expressionContext = spreadsheetParser.expression();
            var visitor           = new SpreadsheetVisitor();

            // we output on the screen the result of our visitor
            Console.WriteLine(visitor.Visit(expressionContext));
        }
示例#3
0
        // if you need to output something during tests
        // private readonly ITestOutputHelper output;
        //
        // public SpreadsheetTests(ITestOutputHelper output)
        // {
        //     this.output = output;
        // }

        private void Setup(string input)
        {
            var inputStream = new AntlrInputStream(input);

            lexer = new SpreadsheetLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(lexer);

            parser = new SpreadsheetParser(commonTokenStream);

            var writer = new StringWriter();

            errorListener = new SpreadsheetErrorListener(writer);
            lexer.RemoveErrorListeners();
            //markupLexer.addErrorListener(errorListener);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(errorListener);
        }
    // Start is called before the first frame update
    void Start()
    {
        instance         = this;
        promptDictionary = new Dictionary <int, string[]>();
        string[] rowEntries = promptSpreadsheet.text.Split('\n');

        foreach (string row in rowEntries)
        {
            string[] rowCells = row.Split('\t');
            promptDictionary.Add(dictionaryIDAssigner, rowCells);
            dictionaryIDAssigner++;
        }

        Debug.Log("The count of promptDictionary is " + promptDictionary.Count);

        path = Application.dataPath + "/AssignmentLog.txt";
    }
        // if you need to output something during tests
        // private readonly ITestOutputHelper output;
        //
        // public SpreadsheetTests(ITestOutputHelper output)
        // {
        //     this.output = output;
        // }

        private void setup(String input)
        {
            ICharStream inputStream = CharStreams.fromString(input);

            lexer = new SpreadsheetLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);

            parser = new SpreadsheetParser(commonTokenStream);

            StringWriter writer = new StringWriter();

            errorListener = new SpreadsheetErrorListener(writer);
            lexer.RemoveErrorListeners();
            // uncomment this if you want to see errors from the lexer
            //lexer.addErrorListener(errorListener);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(errorListener);
        }
示例#6
0
 public Repository(SpreadsheetParser spreadsheetParser, string summaryFilePrefix)
 {
     _spreadsheetParser = spreadsheetParser;
     _summaryFilePrefix = summaryFilePrefix;
 }
示例#7
0
        static void TypecheckFile(string file)
        {
            var ext = Path.GetExtension(file);

            if (ext != ".xl")
            {
                Logger.DebugLine("====================================================", 10);
                Logger.DebugLine($"Skipping file {file}, invalid extension!", 10);
                Logger.DebugLine("====================================================", 10);
                return;
            }

            Logger.DebugLine("====================================================", 10);
            Logger.DebugLine($"Going to parse file {file}", 10);
            if (GlobalSettings.TypecheckerStopAtNextFile)
            {
                Logger.DebugLine("Enter to continue", 10);
                Console.ReadLine();
            }

            Logger.DebugLine("====================================================", 10);
            StreamReader      reader            = File.OpenText(file);
            ErrorHandler      handler           = new ErrorHandler();
            AntlrInputStream  inputStream       = new AntlrInputStream(reader);
            SpreadsheetLexer  spreadsheetLexer  = new SpreadsheetLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(spreadsheetLexer);
            SpreadsheetParser spreadsheetParser = new SpreadsheetParser(commonTokenStream);

            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            Logger.DebugLine(reader.ReadToEnd(), 5);
            Logger.DebugLine("====================================================", 5);
            reader.BaseStream.Seek(0, SeekOrigin.Begin);


            SpreadsheetParser.SpreadSheetContext context = spreadsheetParser.spreadSheet();
            if (spreadsheetParser.NumberOfSyntaxErrors > 0)
            {
                Logger.DebugLine("===================================", 10);
                Logger.DebugLine("Found Syntax Error - Dont processing file", 10);
                if (GlobalSettings.TypecheckerStopSyntaxError)
                {
                    Logger.DebugLine("Enter to continue", 10);
                    Console.ReadLine();
                }
                Logger.DebugLine("===================================", 10);
                return;
            }

            SpreadsheetVisitor visitor = new TypecheckVisitor(handler);

            Logger.DebugLine("", 0);
            PrintContext(context, 0, 0);
            Logger.DebugLine("", 0);
            bool result = visitor.Visit(context);

            Logger.DebugLine("Basic Typechecking has returned result: " + result, 10);
            Logger.DebugLine("===================================", 10);
            if (result)
            {
                Logger.DebugLine($"Count Cells: {visitor.Repository.CellTypes.Count}", 7);
                Logger.DebugLine($"Count Formulas: {visitor.Repository.Formulas.CellFormulas.Count}", 7);
                Logger.DebugLine("===================================", 7);
                Logger.DebugLine("", 5);
                Logger.DebugLine("CellTypes:", 5);
                foreach (var value in visitor.Repository.CellTypes)
                {
                    Logger.DebugLine($"{value.Key.Item1}, {value.Key.Item2}: {value.Value.Type.ToString()}", 5);
                }
                Logger.DebugLine("", 5);
                Logger.DebugLine("CellFormulas:", 5);
                foreach (var formula in visitor.Repository.Formulas.CellFormulas)
                {
                    Logger.Debug($"{formula.Key.Item1}, {formula.Key.Item2}: {formula.Value.ToString()}", 5);
                    formula.Value.Simplify();
                    Logger.DebugLine($" - Simplified: {formula.Value.ToString()}", 5);
                }
                Logger.DebugLine("===================================", 5);
            }
            Logger.DebugLine($"Detected Errors: {handler.fileData.Errors} (Invocations: {handler.fileData.ErrorInvocations})", 10);

            LastCells            = visitor.Repository.CellTypes.Count;
            LastFormulas         = visitor.Repository.Formulas.CellFormulas.Count;
            LastErrors           = handler.fileData.Errors;
            LastErrorInvocations = handler.fileData.ErrorInvocations;
            Logger.DebugLine("", 10);
        }