melt-umn / copper

An integrated context-aware scanner and parser generator
http://melt.cs.umn.edu/copper
GNU Lesser General Public License v3.0
18 stars 4 forks source link

Copper hangs when compiling a simple grammar #42

Closed krame505 closed 5 years ago

krame505 commented 5 years ago

See title, Copper didn't terminate when trying to compile the attached .copper file Parser_edu_umn_cs_melt_metaocaml_driver_parse.copper.txt (renamed so github lets me upload it). This corresponds to the Silver grammar


terminal Identifier_t /[A-Za-z_\$][A-Za-z_0-9\$]*/;
terminal LParen_t '(';
terminal RParen_t ')';

terminal App_t '' association = left, precedence = 10;

nonterminal Expr_c with ast<Expr>, location;

concrete productions top::Expr_c
| e1::Expr_c e2::Expr_c
  operator=App_t
  { top.ast = appExpr(e1.ast, e2.ast, location=top.location); }
| id::Identifier_t
  { top.ast = varExpr(id.lexeme, location=top.location); }

Also, as a side question, does Copper support setting the associativity of a production lacking terminals using the <Operator> field? It seems like it should but the behavior I am seeing seems to indicate not.

krame505 commented 5 years ago

It also appears that this issue persists even removing the <Operator> field.

schwerdf commented 5 years ago

This grammar produces an LR DFA with a state that has a goto transition to itself -- something Copper has apparently never encountered before.

You should be able to set the associativity of a terminal-less production the same way as you set the precedence.

krame505 commented 5 years ago

Interesting, thanks for taking a look.

Associativity and precedence are both specified on a production using <Operator>, right? Then why does the above grammar still yield a shift-reduce conflict when using the new version of Copper?

schwerdf commented 5 years ago

Because the shift-reduce conflict is on Identifier_t (the only used terminal in the grammar), and Identifier_t has no assigned precedence.

krame505 commented 5 years ago

Ah, nevermind then. Thanks.

ericvanwyk commented 5 years ago

But should Copper ever fail to terminate when compiling a grammar? Even if the grammar has problems Copper should not hang.

On Mon, Apr 15, 2019 at 10:32 PM Lucas Kramer notifications@github.com wrote:

Ah, nevermind then. Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/melt-umn/copper/issues/42#issuecomment-483498010, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOhd7MbdO0DBiJGI6TT8fz6ElTdkHvXks5vhURmgaJpZM4cxHrN .

schwerdf commented 5 years ago

The non-terminating behavior was a bug (fixed in commit ddfe1dd) unrelated to the precedence issue.

ericvanwyk commented 5 years ago

OK, thanks. I was reading this in its email form and that didn't include the mention about the commit. But I see it only when I go to the web interface for this. Thanks.