Rascal ambiguity not resolved by disambiguation rules

梦想与她 提交于 2019-12-07 07:15:24

I've been making this ambiguity diagnostics tool, and here's what it came up with for your grammar. It seems you've discovered more things we need to document and write little checkers for.

Well-formedness of \ is murky.

The problem is that the \ operator only accepts literal strings, such as A \ "a" \ "b" or a keyword non-terminal defined like keyword Hello = "a" | "b";, used as A \ Hello, and nothing else. So also A \ ("a" | "b") is not allowed, and also indirect non-terminals like A \ Hello where lexical Hello = Bye; lexical Bye = "if" | "then"; also not allowed. Only the simplest of the simplest forms.

Well-formedness of follow-restrictions

Similar rules for !>> disallow any non-terminal to the right of the !>> operator.

So [a-z]+ !>> [a-z] or [a-z]+ !>> "*", but not [a-z]+ \ myCharClass where lexical myCharClass = [a-z];

Names for character-classes is on our todoy list; but they will not be like non-terminals. More like aliases which will be substituted at parser generator time.

Whole words

Keyword reservation only works if you subtract the sentence from the whole word. Sometimes you have to group non-terminals to get this right:

  • lexical Ex = ([a-z]+ "*") \ "https*" instead of lexical Ex = [a-z]+ "*" \ "https*")

The latter would try to subtract the "https*" language from the "*" language. The first works.

case-insensitivity

  • 'if' is defined by lexical 'if' = [iI][fF];
  • "if" is defined by lexical "if" = [i][f];
  • '*' is defined by lexical '*' = [*];
  • "*" is defined by lexical "*" = [*];

New grammar

I used a random generator to generate all the ambiguities I could find, and resolved them step by step by adding keyword reservation:

lexical Scheme = AnyScheme ; 
lexical AnyScheme = KnownScheme > UnknownScheme ;
lexical AnySchemeChar = [a-z*];
lexical KnownScheme = KnownSchemes !>> AnySchemeChar ;  
keyword KnownSchemes = "http" | "https" | "http*" | "javascript" ;
lexical UnknownScheme = UnknownFixedScheme | UnknownWildScheme ;
lexical UnknownFixedScheme = [a-z]+ !>> AnySchemeChar \ KnownSchemes ;
lexical UnknownWildScheme = ([a-z]* '*' AnySchemeChar*) !>> AnySchemeChar  \ KnownSchemes ;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!