digitalmars.D - Porting RE2C to D
- Carlos (22/22) Mar 09 2005 I am porting RE2C to D.
- Ben Hinkle (17/39) Mar 09 2005 I don't think 'virtual' is allowed before member function definitions. T...
- Ben Hinkle (4/22) Mar 09 2005 I should add you probably want Stream or OutputStream instead of File or...
- pragma (13/30) Mar 09 2005 Might I reccomend this:
- Zz (8/46) Mar 10 2005 look at yasm, they converted re2c from c++ to some pretty clean 'c', it ...
- Carlos (11/14) Mar 10 2005 Yes, i know about Yasm.
- Carlos (43/43) Mar 10 2005 Thanks for the help to the 3 of you.
- Kris (36/79) Mar 10 2005 Mango uses an Interface to extent the basic I/O system ~ if your class
I am porting RE2C to D. Things are going well, but there are some C++ constructs for which i needs some help. What do i do with (const and =0 ): I translated them to: The body of the function will be inserted in the class. By the way. In D, the function bodies must be defined inside the class ? Right ? or may i define them outside the class, but in the same module ? Also, what to do with the overloaded stream << operator for the State class: This my first real work with D. I find the language fun. It ask for less typing.... Thanks for any advice.
Mar 09 2005
"Carlos" <carlos2003nov yahoo.ca> wrote in message news:d0notu$72k$1 digitaldaemon.com...I am porting RE2C to D. Things are going well, but there are some C++ constructs for which i needs some help. What do i do with (const and =0 ): I translated them to:I don't think 'virtual' is allowed before member function definitions. Try abstract void emit( File of, bit flag ); bool isRule( ) {...}The body of the function will be inserted in the class. By the way. In D, the function bodies must be defined inside the class ? Right ?yesor may i define them outside the class, but in the same module ?noAlso, what to do with the overloaded stream << operator for the State class:override the function char[] toString() See "writef" and "doFormat" in http://www.digitalmars.com/d/std_format.html, http://www.digitalmars.com/d/phobos.html#stdio and http://www.digitalmars.com/d/std_stream.html or one of the various libraries that do io (eg, Mango: http://www.dsource.org/projects/mango/ and probably others but I can't think of any right now)This my first real work with D. I find the language fun. It ask for less typing.... Thanks for any advice.good luck! -Ben
Mar 09 2005
"Ben Hinkle" <bhinkle mathworks.com> wrote in message news:d0npu1$8gb$1 digitaldaemon.com..."Carlos" <carlos2003nov yahoo.ca> wrote in message news:d0notu$72k$1 digitaldaemon.com...I should add you probably want Stream or OutputStream instead of File or something like that.I am porting RE2C to D. Things are going well, but there are some C++ constructs for which i needs some help. What do i do with (const and =0 ): I translated them to:I don't think 'virtual' is allowed before member function definitions. Try abstract void emit( File of, bit flag ); bool isRule( ) {...}
Mar 09 2005
In article <d0notu$72k$1 digitaldaemon.com>, Carlos says...I am porting RE2C to D. Things are going well, but there are some C++ constructs for which i needs some help. What do i do with (const and =0 ): I translated them to:Might I reccomend this: .. just don't forget to "import std.stream" to get the OutputStream class.By the way. In D, the function bodies must be defined inside the class ? Right ? or may i define them outside the class, but in the same module ?Declare them inside the class, as though you were inlining the whole thing. It feels wierd at first, but you'll begin to notice the convienence of not having separate header files for everything.Also, what to do with the overloaded stream << operator for the State class:D uses special names to denote operators (http://www.digitalmars.com/d/operatoroverloading.html). For the two signatures above, you'd only need one override: - EricAnderton at yahoo
Mar 09 2005
look at yasm, they converted re2c from c++ to some pretty clean 'c', it may be easier to work from there. Zz "pragma" <pragma_member pathlink.com> wrote in message news:d0nqmo$9ev$1 digitaldaemon.com...In article <d0notu$72k$1 digitaldaemon.com>, Carlos says...virtual.I am porting RE2C to D. Things are going well, but there are some C++ constructs for which i needs some help. What do i do with (const and =0 ): I translated them to:Might I reccomend this:.. just don't forget to "import std.stream" to get the OutputStream class.thing. ItBy the way. In D, the function bodies must be defined inside the class ? Right ? or may i define them outside the class, but in the same module ?Declare them inside the class, as though you were inlining the wholefeels wierd at first, but you'll begin to notice the convienence of nothavingseparate header files for everything.Also, what to do with the overloaded stream << operator for the State class:D uses special names to denote operators (http://www.digitalmars.com/d/operatoroverloading.html). For the two signatures above, you'd only need one override: - EricAnderton at yahoo
Mar 10 2005
Zz wrote:look at yasm, they converted re2c from c++ to some pretty clean 'c', it may be easier to work from there.Yes, i know about Yasm. Thanks for the tip and your attention. Over the year i found 4 versions of RE2C: 1 - Sourceforge 2 - Yasm 3 - OpenWatcom has one also. + a 4th who has since vanished. I have invested some time anf effort with the C++ version so, i'l stick with it. Whatever the difficulties .
Mar 10 2005
Thanks for the help to the 3 of you. I downloaded Mango and had a better look at Phobos. I am not D strong enough to use this. After may essais, here what i camed up with: class State { public: char[] text; this(char[]txt){text=txt;} ostream put(ostream out) { out.writef( "State: ", text ); return out; } } class ostream : File { alias put opShl; this( ) { super( ); } ostream put(byte X) { writef(X); return this; } ostream put(ubyte X){ writef(X); return this; } ostream put(short X){ writef(X); return this; } ... etc ..., and then: ostream put( State s ) { s.put( this ); return this; } } Now if i declare: State S = new state("some text"); ostream os; os = new File( "out.log", FileMode.OutNew ); I can do this: os << "text" << "\n"; Well, this work, but this is less than perfect. If ostream is buried in a library, how can i add new data structures to it without modifying it ? Can i add something to each class (like State) i want to be able to send to stream with the << operator ? Or, what is the best way to do this ? I may use Mango to do this. But Mango is big library and i would like re2d to be standalone exe with no dependencies Thanks.
Mar 10 2005
Inline: In article <d0qbaq$309h$1 digitaldaemon.com>, Carlos says...Thanks for the help to the 3 of you. I downloaded Mango and had a better look at Phobos. I am not D strong enough to use this. After may essais, here what i camed up with: class State { public: char[] text; this(char[]txt){text=txt;} ostream put(ostream out) { out.writef( "State: ", text ); return out; } } class ostream : File { alias put opShl; this( ) { super( ); } ostream put(byte X) { writef(X); return this; } ostream put(ubyte X){ writef(X); return this; } ostream put(short X){ writef(X); return this; } ... etc ..., and then: ostream put( State s ) { s.put( this ); return this; } } Now if i declare: State S = new state("some text"); ostream os; os = new File( "out.log", FileMode.OutNew ); I can do this: os << "text" << "\n"; Well, this work, but this is less than perfect. If ostream is buried in a library, how can i add new data structures to it without modifying it ?Mango uses an Interface to extent the basic I/O system ~ if your class implements the IReadable and/or IWritable interface, the mango.io subsystem will treat your class just like a native type. For example: Substitute the () parens for >> if you prefer the iostream syntax. The same notion is used for writing also ~ encapsulation is nicely maintained and the setup is rather trivial, as you can see. This pattern extends to serializing, sending, and re-instantiating an entire class-tree across a network (via IPickle and friends).Can i add something to each class (like State) i want to be able to send to stream with the << operator ? Or, what is the best way to do this ? I may use Mango to do this. But Mango is big library and i would like re2d to be standalone exe with no dependencies Thanks.If you want to make a standalone exe using Mango, just go ahead. The linker will exclude anything you don't use, and the resultant program should be equivalent to the size of a Phobos-based application with similar functionality (and probably a bit smaller once Walter finally gets around to removing printf() from Object.print ...). Point Build.exe at the Mango path (via -I) and compile with -nounittest. - Kris
Mar 10 2005