PR description:
I modified C++ code related with issue #293 .
PR contents
Makefile changes:
If bnfc received --ansi flag, Makefile would have -std=c++14 compile option otherwise --ansi.
If bnfc not received --ansi flag, bnfc will generate .ll and .yy files
Fix PARSER_HEADER_FILE
C++ source should have same name interface like "psProgram" in header file and source file. But, currently it looks Parser.H doesn't match function name.
C++ AST/Test code generator switching
If bnfc not received --ansi flag, bnfc would genrate codes using smart-pointer (std::unique_ptr), otherwise bnfc generate codes same as before.
Sample code:
use using instead of typedef
/******************** TypeDef Section ********************/
using Integer = int;
using Char = char;
using Double = double;
using String = std::string;
using Ident = std::string;
clone() returns instance wrapped std::unique_ptr
/******************** Abstract Syntax Classes ********************/
class Program : public Visitable
{
public:
virtual std::unique_ptr<Program> clone() const = 0;
};
Impl classes have each copy constructors
I referred the book "More Effective C++" to implement it.
class Prog : public Program
{
private:
std::unique_ptr<ListStatement> liststatement_;
- [WIP] Bison/Flex code genrator switching
- Still work in progress, but code might require [Bison3.2](https://lwn.net/Articles/770138/)
- I think I will modify process switching some code in bison
- Use smart pointer in test C++ source
- This enables test.C to use unique_ptr, however this is just a example. I think this kind of smart-pointer can apply for other C++ code generated by bnfc also. To use smart pointer, I added `#include <memory>`.
- will generate following code
```cpp
if (parse_tree)
{
printf("\nParse Successful!\n");
if (!quiet) {
printf("\n[Abstract Syntax]\n");
std::unique_ptr<ShowAbsyn> s(new ShowAbsyn());
printf("%s\n\n", s->show(parse_tree));
printf("[Linearized Tree]\n");
std::unique_ptr<PrintAbsyn> p(new PrintAbsyn());
printf("%s\n\n", p->print(parse_tree));
}
delete(parse_tree);
return 0;
}
ref #293
PR description: I modified C++ code related with issue #293 .
PR contents
Makefile changes:
--ansi
flag, Makefile would have-std=c++14
compile option otherwise--ansi
.--ansi
flag, bnfc will generate.ll
and.yy
filesFix PARSER_HEADER_FILE
C++ AST/Test code generator switching
--ansi
flag, bnfc would genrate codes using smart-pointer (std::unique_ptr), otherwise bnfc generate codes same as before.Sample code:
use
using
instead oftypedef
clone()
returns instance wrappedstd::unique_ptr
public: // for "std::move" Prog(Prog&& rhs); Prog& operator=(Prog&& rhs); // for normal copy Prog(const Prog& rhs); Prog& operator=(const Prog& rhs); Prog(const ListStatement& p1); ~Prog(); virtual void accept(Visitor *v); std::unique_ptr clone() const override;
};