Esempio n. 1
0
 /// <summary>
 /// Translates the source using <paramref name="Resultbuilder"/> to output the result,
 /// <paramref name="outputMessage"/> and <paramref name="outputMessageAndPosition"/>
 /// to output additional information.
 /// </summary>
 /// <param name="Resultbuilder"></param>
 /// <param name="SourceReader">The source</param>
 /// <param name="outputMessage">A method to output messages </param>
 /// <param name="outputMessageAndPosition">A method to output messages with an associated poition in the source</param>
 public static void Execute(
     StringBuilder Resultbuilder,
     SpanReaderWithCharacterAndLineCounter SourceReader,
     Action <MessageTypeOrDestinationEnum, String> outputMessage,
     Action <MessageTypeOrDestinationEnum, String, Int32> outputMessageAndPosition,
     out Int32 sumOfConflictsNotSolvedByExplicitPriority)
 => Go(Resultbuilder, SourceReader, outputMessage, outputMessageAndPosition,
       out sumOfConflictsNotSolvedByExplicitPriority);
Esempio n. 2
0
 public P1bLexer(SpanReaderWithCharacterAndLineCounter sourceReader,
                 StackOfMultiTypeElements attributeStack, Stack <Int32> stateStack)
     : base(attributeStack, stateStack)
 {
     Source          = sourceReader.Source;
     inputClassifier = new P1cInputClassifier(sourceReader, attributeStack);
     LexerTextPos    = 0;
     Accepted        = true;
 }
Esempio n. 3
0
    /* TODO Grammlator:
     *
     * Compare with other implementations: https://en.wikipedia.org/wiki/Comparison_of_parser_generators
     *
     * Allow multile grammar parts in the same file
     *
     * Test dynamic priorities and provide access to context attributes
     *
     * Use names for labels instead of numbers so that small grammar changes do not cause lots of changed labels
     *
     *
     * */

    private static void Go(
        StringBuilder Resultbuilder,
        SpanReaderWithCharacterAndLineCounter SourceReader,
        Action <MessageTypeOrDestinationEnum, String> outputMessage,
        Action <MessageTypeOrDestinationEnum, String, Int32> outputMessageAndPos,
        out Int32 sumOfConflictsNotSolvedByExplicitPriority
        )
    {
        // ----- Set initial values
        ResetGlobalVariables(outputMessage, outputMessageAndPos);
        var SymbolDictionary = new Dictionary <UnifiedString, Symbol>(1000);

        // ----- Copy input up to and including line starting with "#region grammar"
        Int32 StartOfGrammlatorLines =
            SourceReader.ReadAndCopyUntilMarkedLineFound(Resultbuilder, copy: true, copyLineWithMarkers: true,
                                                         RegionBegin.Value, RegionGrammarMarker.Value);

        if (StartOfGrammlatorLines >= 0)
        {
            Int32 StartOfRegion = StartOfGrammlatorLines
                                  + SourceReader.Source.Span[StartOfGrammlatorLines..].IndexOf('#');
Esempio n. 4
0
{ //GrammlatorInput<ClassifierResult> {
  // TODO use the Rune struct https://docs.microsoft.com/en-gb/dotnet/api/system.text.rune?view=netcore-3.1
  // and the EnumerateRunes Method
  // https://docs.microsoft.com/en-gb/dotnet/api/system.memoryextensions.enumeraterunes?view=netcore-3.1
  //  foreach (Rune r in s){}
  // or explicit call of iterators https://docs.microsoft.com/de-de/dotnet/csharp/iterators

    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="SourceReader">the reader provides "ReadOnlyMemory<Char> ReadLine()" and "int LineNumber", "int Position" "int EoLLength"</param>
    /// <param name="attributeStack">The <paramref name="attributeStack"/> is used to store the attributes of the recognized character</param>
    public P1cInputClassifier(
        SpanReaderWithCharacterAndLineCounter SourceReader,
        StackOfMultiTypeElements attributeStack)
    {
        this.SourceReader = SourceReader;
        this._a           = attributeStack;
        Accepted          = true;
        InputLine         = ReadOnlyMemory <Char> .Empty;
        CurrentColumn     = InputLine.Length + 1; // Alike end of line had been recognized and accepted
        StartOf1stGrammlatorGeneratedLine = -1;

        // Grammlator parameterization
        GrammarlineMarker       = GlobalSettings.CSharpGrammarLineMarker.Value; // = "//|"
        CSharpCommentlineMarker = GlobalSettings.CSharpCommentlineMarker.Value; // = "//"
        CSharpPragma            = GlobalSettings.CSharpPragmaMarker.Value;      // = "#pragma"

        for (int i = 0; i < ClassifierTable.Length; i++)
        {
            ClassifierTable[i] = GetResultFromChar((char)i);
        }
    }