|
From: Baptiste L. <gai...@fr...> - 2003-08-25 22:17:00
|
Well, I glad to announce that the new C++ parser I was working on is now
working (at least the unit tests say so;-) ). It lives in
src/pyrfta/test/rfta/parser. I've wrotten a small document (readme.txt) that
provides an overview of the parser, as well as instructions to run the
tests.
At the current time, there is no template support, but there is a simple
'error recovery' mecanism for statements and declarations. It way more
flexible and compact than the current C++ parser (the statement parser is
about 30 lines of grammar long). It parses for all structures: declaration,
expression and statement. I want to stabilize the current grammar before
adding template support (which will probably means adding a few not so
predicatible twist to the grammar).
Here is a few samples of successfully parsed code:
// Ambiguity resolution example in ISO C++ Standard, p 129
struct S {
S(int x);
};
S w(int(a)); // function declaration
S x(int()); // function declaration
S y((int)a); // object declaration
S z = int(a); // object declaration
// Empty initializer list example in ISO C++ Standard, p 145
struct S { };
struct A {
S s;
static j;
int i;
} a = { {}, 3 };
// Typedef look up example 2 in ISO C++ Standard, p 154
typedef void fv(void);
typedef void fvc(void) const;
struct S {
fv memfunc1; // equivalent to: void memfunc1(void);
void memfunc2();
fvc memfunc3; // equivalent to: void memfunc3(void) const;
};
fv S::* pmfv1 = &S::memfunc1;
fv S::* pmfv2 = &S::memfunc2;
fvc S::* pmfv3 = &S::memfunc3;
class C : public A, public B {
int f() { return A::f() + B::f(); }
C();
explicit C( int );
~C();
friend C operator +( const C&, const C& );
};
// Local structure example in ISO C++ Standard, p 161
int x;
void f()
{
static int s;
int x;
extern int g();
struct local {
int h() { return s; }
int k() { return ::x; }
int l() { return g(); }
};
}
Notes that because of the nature of the parser (it does not know if a
identifier is a type, a variable...), in some case a code structure may be
misinterpreted. For example:
a f(x);
could be either a function declaration (return type a, takes type x as
argument), or a object instantiation (type a, name f, constructor paramter
x).
The same goes for expression:
f(x) may be a function call, a 'functional style' type conversion, or a
instiation of a object of type f.
This means that there will be a bit of analysis works to do to try and
fix the AST.
Next steps includes running the parser against 'real' code and come up
with some functional tests to detect regression.
Baptiste.
|
|
From: Baptiste L. <gai...@fr...> - 2003-08-26 12:11:33
|
I've added a small script in src/pyrfta/test: cppastdump.py. It dump the
generated ast to the output for the c++ file specified on the command line.
I've uploaded a few output examples to:
http://gaiacrtn.free.fr/temp/newparser_ast/
Not that some contains template, as well as non standard class
declaration (using macro for dll export). This cause the error recovery
mecanism to trigger.
Enjoy,
Baptiste.
----- Original Message -----
From: "Baptiste Lepilleur" <gai...@fr...>
To: "CppTool Mailing List" <Cpp...@li...>
Sent: Tuesday, August 26, 2003 12:22 AM
Subject: [Cpptool-develop] New C++ parser...
> Well, I glad to announce that the new C++ parser I was working on is
now
> working (at least the unit tests say so;-) ). It lives in
> src/pyrfta/test/rfta/parser. I've wrotten a small document (readme.txt)
that
> provides an overview of the parser, as well as instructions to run the
> tests.
>
> At the current time, there is no template support, but there is a
simple
> 'error recovery' mecanism for statements and declarations. It way more
> flexible and compact than the current C++ parser (the statement parser is
> about 30 lines of grammar long). It parses for all structures:
declaration,
> expression and statement. I want to stabilize the current grammar before
> adding template support (which will probably means adding a few not so
> predicatible twist to the grammar).
>
> Here is a few samples of successfully parsed code:
>
> // Ambiguity resolution example in ISO C++ Standard, p 129
> struct S {
> S(int x);
> };
> S w(int(a)); // function declaration
> S x(int()); // function declaration
> S y((int)a); // object declaration
> S z = int(a); // object declaration
>
> // Empty initializer list example in ISO C++ Standard, p 145
> struct S { };
> struct A {
> S s;
> static j;
> int i;
> } a = { {}, 3 };
>
> // Typedef look up example 2 in ISO C++ Standard, p 154
> typedef void fv(void);
> typedef void fvc(void) const;
> struct S {
> fv memfunc1; // equivalent to: void memfunc1(void);
> void memfunc2();
> fvc memfunc3; // equivalent to: void memfunc3(void) const;
> };
> fv S::* pmfv1 = &S::memfunc1;
> fv S::* pmfv2 = &S::memfunc2;
> fvc S::* pmfv3 = &S::memfunc3;
>
> class C : public A, public B {
> int f() { return A::f() + B::f(); }
> C();
> explicit C( int );
> ~C();
> friend C operator +( const C&, const C& );
> };
>
> // Local structure example in ISO C++ Standard, p 161
> int x;
> void f()
> {
> static int s;
> int x;
> extern int g();
>
> struct local {
> int h() { return s; }
> int k() { return ::x; }
> int l() { return g(); }
> };
> }
>
> Notes that because of the nature of the parser (it does not know if a
> identifier is a type, a variable...), in some case a code structure may be
> misinterpreted. For example:
>
> a f(x);
>
> could be either a function declaration (return type a, takes type x as
> argument), or a object instantiation (type a, name f, constructor paramter
> x).
>
> The same goes for expression:
> f(x) may be a function call, a 'functional style' type conversion, or a
> instiation of a object of type f.
>
> This means that there will be a bit of analysis works to do to try and
> fix the AST.
>
> Next steps includes running the parser against 'real' code and come up
> with some functional tests to detect regression.
>
> Baptiste.
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
> at the same time. Free trial click
here:http://www.vmware.com/wl/offer/358/0
> _______________________________________________
> Cpptool-develop mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cpptool-develop
>
|