LanguageData construction very very very slowly

Oct 14, 2012 at 5:19 PM
Edited Oct 15, 2012 at 3:19 AM

Hi, I'm using Irony to create a C# parser, and create Roslyn syntax tree from the parse tree.
Here is the grammar I wrote. If you run it in GrammarExplorer, GrammarExplorer will be dead.
In line 1123:

expression.Choice(non_assignment_expression, assignment_expression);
//expression.Choice(primary_expression);

If you comment first line and uncomment second line, LanguageData will be constructed, and GrammarExplorer will show some conflicts.

Any help?Thanks!!! 

Oct 15, 2012 at 8:39 AM

The disadvantage of writing a single constructor approaching 1500 lines long is that only the author will ever appreciate the beauty of such a colossus; or even bother to attempting to read it.

If you can't break the solution into well-organized pieces less than 100 lines long, then you don't understand the problem yet.

Oct 16, 2012 at 3:30 AM

Hi pgeerkens, the grammar I wrote is perfectly clear :)

I think it's Irony's bug...

Coordinator
Oct 16, 2012 at 5:01 PM
Edited Oct 16, 2012 at 5:01 PM

man, just downloaded your full project sources, tried to compile, stuff is missing... after some fixes and workarounds, finally got to launch grammar explorer - and it fails to load the grammar. DID YOU EVER load it into Grammar Explorer?! it gives an error on load, but this is another issue. The thing is, before you completely test the grammar in explorer - don't even think about using it for parsing

Roman

Oct 17, 2012 at 3:53 AM
Edited Oct 17, 2012 at 4:11 AM

Hi Roman, please try these steps:

1. Launch Visual Studio 2012, new Console Application project
2. add CSGrammar.cs to project
3. Manage NuGet Packages, search "Roslyn", install "Roslyn.Compilers.CSharp"
4. Add reference to Irony project or dll
5. Modify Program.cs:

using System;
using Irony.Parsing;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var languageData = new LanguageData(new CSGrammar());//DEAD in LanguageData ctor!!!
        }
    }
}

 

6. open CSGrammar.cs, goto line 1123:

expression.Choice(non_assignment_expression, assignment_expression);
//expression.Choice(primary_expression);


comment line 1123 and uncomment line 1124, run again, OK.

 

Coordinator
Oct 17, 2012 at 4:48 AM

sorry man, but have no time for debugging such monsters. Can only give you an advice - load grammar in Grammar explorer! It does not matter what happens with this trouble line - it might be just the last straw that breaks the camel's back. Load it, look at errors, conflicts, state map etc. Pretty damn sure there are a lot of conflicts. Work with them, cleanup the grammar. I would suggest initially trim the grammar, use some simpler version, and gradually add stuff while removing conflicts. For the troubled line - enable it and step into parser data builder, see if it drops into infinite loop somewhere.  

One question - what's the purpose of this? Roslyn IS a parser for c#, so why do another one?!

Roman

Oct 17, 2012 at 3:21 PM
Edited Oct 17, 2012 at 3:51 PM

Good question :)

Because I want to extend C# syntax and semantics,  Axum is a good case study. Roslyn is all about C#/VB, but nothing else, I have to create a C# parser.

Inventing a new language based on C#, or, integrating DSL with C#, very cool, aha?

(TypeScript is a new language based on JavaScript)

Thanks! Roman and Pieter.

Coordinator
Oct 17, 2012 at 4:33 PM

in that case, are you sure you need to reproduce the exact tree that Roslyn's parser does? I mean, can you live with lists with delimiters filtered out?

Oct 18, 2012 at 3:21 PM

Punctuations in roslyn is not really important :) , delimiters is a small problem. The biggest challenge right now is implementing a almost complete and correct C# parser.