1 / 15

SPECS Translator

SPECS Translator. A Aniruddha. Introduction. SPECS (Significantly Prettier and Easier C++ Syntax) Alternate syntactic binding for C++. Reduces syntactic errors. Includes new syntax for declaration/definition for types, functions and objects. Changes operators and control structures.

phong
Télécharger la présentation

SPECS Translator

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SPECS Translator A Aniruddha

  2. Introduction SPECS (Significantly Prettier and Easier C++ Syntax) • Alternate syntactic binding for C++. • Reduces syntactic errors. • Includes new syntax for declaration/definition for types, functions and objects. • Changes operators and control structures. • Better syntactic differentiation of dissimilar constructs.

  3. SPECS syntactic design principles • Syntactic consistency. • Syntactic differentiation of dissimilar constructs. • Better readability.

  4. Syntactic consistency Creation of types in C++: Class Base {…} ; typedef struct {…} vector; typedef int (*fp) (); enum result {…} ; In SPECS: type Base : class {…} type vector : class {[public] …} type fp : ^((void)->int); type result : enum {…}

  5. Syntactic differentiation of dissimilar constructs C++ - insufficient differentiation Declaration of functions and objects: int (f) (int, char); int (*fp) (int, char); In SPECS: func f : ((int, char) -> int); obj fp : ^((int, char) -> int);

  6. Syntax : class (pure virtual functions) SPECS : type Base : class { func print_func : abstract ((& ostream) -> void) ; } // Note : no ; C++ : Class Base { virtual void print_func (ostream&) = 0; };

  7. Syntax : class(inheritance and static members) type Derived : class inherits public Base { obj a : common int; } class Derived : public Base { static int a; }

  8. Syntax: class (access control, constructors, destructors and friends) type TestClass : class { [private] obj a : int ; [friend] func operator << : ((& ostream, & TestClass) -> & ostream ); [public] func ctor : (int) ; func dtor : (void); }

  9. Syntax: class(Operators and cast) type MyInt : class { [public] func operator pre ++ : ((void)-> & MyInt); func operator post ++ : ((void)-> & MyInt); funcdefined_cast : ((void) -> int); } class MyInt { public: MyInt & operator ++ (); // pre MyInt & operator ++ (int); // Dummy int for post operator int (); };

  10. Syntax: Templates type GenericClass <[class X]> : class {…} template <class X> class GenericClass {…}; Advantages: • Keyword ‘template’ not required. • C++: TemplateClass<(1>2)> // Parens required SPECS: TemplateClass<[1>2]> • C++ : array<auto_ptr<X> > // Space required SPECS: array<[auto_ptr<[X]>]>

  11. Syntax: Operators

  12. Syntax: Statements • Loop body must be block. • switch • No break required. • No default fall-through. • case can have a list of constant-expression. • case/defaultmust be followed by a block. Example: switch (i) { case 1,2,3 : { cout << “1/2/3” ;} case 4: {cout << “4”; } }

  13. Commonalities with C++ • All inbuilt types are identically named. Literal values are specified in exactly the same way. • The operators have the same precedence and associativity. • Scope rules, function call resolution, implicit conversion, access default and control structure semantics(except switch) are identical. • The same preprocessor and standard libraries are used for both languages. • RTTI, namespaces, exception handling are identical in syntax and semantics.

  14. Implementation • Implemented using TXL(Turing Xtender/Tree Transformation Language). • Parse : construct parse tree based on input grammar. • Transform : based on defined rules. • Unparse : In-order traverse of parse tree with formatting. • Can convert • Simple object and type declarations. • Simple Function declaration and definitions. • Assignment statements. • Switch and class syntax.

  15. Thank You

More Related