[dox] Fixing the lexical rule for BinaryInteger

Andre Artus andre.artus at gmail.com
Fri Aug 16 15:43:11 PDT 2013


On Friday, 16 August 2013 at 20:00:35 UTC, Brian Schott wrote:
> I've been doing some work with the language grammar 
> specification. You may find these resources useful:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=10233
> https://github.com/Hackerpilot/DGrammar/blob/master/D.g4

You have done impressive work on your grammar; I just have some 
small issues.

1. I run into a number of errors trying to generate the Java 
code, I'm using ANTLR 4.1

2. Your BinaryInteger and HexadecimalInteger only allow for one 
of the following (reduced) cases:

0b1__ : works
0b_1_ : fails
0b__1 : fails

Same with HexadecimalInteger.

3. The imports don't allow for all cases.

4. how are you handling the scope attribute specifier in the 
"attribute ':'" case, e.g. "public:"?

There seems to be a few more places where it diverges a bit from 
what the compiler currently accepts.

I'm not arguing for the wisdom of writing code as I am about to 
show, but the following compiles with the current release build 
of DMD, but may not parse with DGrammar, quite likely balk in the 
scanner:

module main;

public:
static:
import std.stdio;

int main(string[] argv)
{
	auto myBin = 0b0011_1101;

	writefln("%1$x\t%1$.8b\t%1$s", myBin);

	auto myBin2 = 0b_______1;

	writefln("%1$x\t%1$.8b\t%1$s", myBin2);

	auto myBin3 = 0b____1___;

	writefln("%1$x\t%1$.8b\t%1$s", myBin3);

	auto myHex1 = 0x1__;
	writefln("%1$x\t%1$.8b\t%1$s", myHex1);

	auto myHex2 = 0x_1_;
	writefln("%1$x\t%1$.8b\t%1$s", myHex2);

	auto myHex3 = 0x__1;
	writefln("%1$x\t%1$.8b\t%1$s", myHex3);

	
	return 0;
}


More information about the Digitalmars-d mailing list