Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ANTLR 3的C#语法_C#_Parsing_Antlr_Bnf - Fatal编程技术网

使用ANTLR 3的C#语法

使用ANTLR 3的C#语法,c#,parsing,antlr,bnf,C#,Parsing,Antlr,Bnf,我现在正在使用基于的Antlr 3编写C#语法 但是,我发现了一些我不理解的定义 NUMBER: Decimal_digits INTEGER_TYPE_SUFFIX? ; // For the rare case where 0.ToString() etc is used. GooBall @after { CommonToken int_literal = new CommonToken(NUMBER, $dil.text); CommonToken

我现在正在使用基于的Antlr 3编写C#语法

但是,我发现了一些我不理解的定义

NUMBER:
    Decimal_digits INTEGER_TYPE_SUFFIX? ;
// For the rare case where 0.ToString() etc is used.
GooBall
@after        
{
    CommonToken int_literal = new CommonToken(NUMBER, $dil.text);
    CommonToken dot = new CommonToken(DOT, ".");
    CommonToken iden = new CommonToken(IDENTIFIER, $s.text);

    Emit(int_literal); 
    Emit(dot); 
    Emit(iden); 
    Console.Error.WriteLine("\tFound GooBall {0}", $text); 
}
    :
    dil = Decimal_integer_literal d = '.' s=GooBallIdentifier
    ;

fragment GooBallIdentifier
    : IdentifierStart IdentifierPart* ;
上述片段包含“GooBall”的定义。 我对这个定义有一些疑问

为什么需要GooBall?
为什么这个语法定义lexer规则来解析“0.ToString()”而不是解析规则?

这是因为这是一个有效的表达式,其他任何规则都不能处理它-我想你会称它为类似匿名对象的东西,因为没有更好的术语。类似于“hello world”.ToUpper()。通常,方法调用仅对变量标识符或返回值ala GetThing().method()或其他变量有效

对不起。我从中找到了原因

现在,如果您想添加“..”范围运算符,那么1..10是有意义的,ANTLR很难区分1。(范围的起点)从1开始。无回溯的浮动。因此,在NUM_FLOAT中匹配“1..”,并只发出两个非FLOAT标记: