qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
177 stars 25 forks source link

Pointer-to-pointer/exponentiation operator ambiguity #50

Closed jonathanvdc closed 7 years ago

jonathanvdc commented 7 years ago

I was doing some low-level programming just now and thought I'd write a simple echo program:

public static unsafe class Program
{
    public static extern int puts(byte* str);

    public static int Main(int argc, byte** argv)
    {
        for (int i = 1; i < argc; i++)
        {
            puts(argv[i]);
        }
        return 0;
    }
}

Seems reasonable, right? Well actually, the EC# parser parses byte** argv as @'**(#uint8, argv) instead of #var(#of(@'*, #of(@'*, #uint8)), argv). (I guess any expression a ** b is ambiguous in this way.)

I've resorted to writing byte* * argv for now, but that's just poor style. Would you consider dropping the @'** from EC#? There's not even a macro for @'** right now: removing the operator shouldn't break any code.

qwertie commented 7 years ago

I've just fixed this bug. I'm sorry that it took so long, despite being pretty easy to fix (just 5 lines added to the parser).

The exponentiation operator has not been removed. Treating Foo** x as a variable declaration, rather than an expression, is the same problem as treating Foo* x as a variable declaration rather than an expression. The relatively complicated trickery (TentativeVarDecl, TentativeExpr) that resolves Foo* x is implicitly re-used for Foo** x.

jonathanvdc commented 7 years ago

Awesome! Thanks!