Address listed flaws in implementation
This commit is contained in:
parent
9a89f075b2
commit
329d547f56
18
02/ast.hpp
18
02/ast.hpp
|
@ -24,6 +24,16 @@ struct branch {
|
||||||
|
|
||||||
using branch_ptr = std::unique_ptr<branch>;
|
using branch_ptr = std::unique_ptr<branch>;
|
||||||
|
|
||||||
|
struct constructor {
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::string> types;
|
||||||
|
|
||||||
|
constructor(std::string n, std::vector<std::string> ts)
|
||||||
|
: name(std::move(n)), types(std::move(ts)) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
using constructor_ptr = std::unique_ptr<constructor>;
|
||||||
|
|
||||||
struct definition {
|
struct definition {
|
||||||
virtual ~definition() = default;
|
virtual ~definition() = default;
|
||||||
};
|
};
|
||||||
|
@ -108,3 +118,11 @@ struct definition_defn : public definition {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct definition_data : public definition {
|
||||||
|
std::string name;
|
||||||
|
std::vector<constructor_ptr> constructors;
|
||||||
|
|
||||||
|
definition_data(std::string n, std::vector<constructor_ptr> cs)
|
||||||
|
: name(std::move(n)), constructors(std::move(cs)) {}
|
||||||
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
|
||||||
void yy::parser::error(const std::string& msg) {
|
void yy::parser::error(const std::string& msg) {
|
||||||
std::cout << "An error occured: " << std::endl;
|
std::cout << "An error occured: " << msg << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern std::vector<definition_ptr> program;
|
extern std::vector<definition_ptr> program;
|
||||||
|
|
26
02/parser.y
26
02/parser.y
|
@ -35,10 +35,12 @@ extern yy::parser::symbol_type yylex();
|
||||||
%type <std::vector<std::string>> lowercaseParams
|
%type <std::vector<std::string>> lowercaseParams
|
||||||
%type <std::vector<definition_ptr>> program definitions
|
%type <std::vector<definition_ptr>> program definitions
|
||||||
%type <std::vector<branch_ptr>> branches
|
%type <std::vector<branch_ptr>> branches
|
||||||
|
%type <std::vector<constructor_ptr>> constructors
|
||||||
%type <ast_ptr> aAdd aMul case app appBase
|
%type <ast_ptr> aAdd aMul case app appBase
|
||||||
%type <definition_ptr> definition
|
%type <definition_ptr> definition defn data
|
||||||
%type <branch_ptr> branch
|
%type <branch_ptr> branch
|
||||||
%type <pattern_ptr> pattern
|
%type <pattern_ptr> pattern
|
||||||
|
%type <constructor_ptr> constructor
|
||||||
|
|
||||||
%start program
|
%start program
|
||||||
|
|
||||||
|
@ -54,6 +56,11 @@ definitions
|
||||||
;
|
;
|
||||||
|
|
||||||
definition
|
definition
|
||||||
|
: defn { $$ = std::move($1); }
|
||||||
|
| data { $$ = std::move($1); }
|
||||||
|
;
|
||||||
|
|
||||||
|
defn
|
||||||
: DEFN LID lowercaseParams EQUAL OCURLY aAdd CCURLY
|
: DEFN LID lowercaseParams EQUAL OCURLY aAdd CCURLY
|
||||||
{ $$ = definition_ptr(
|
{ $$ = definition_ptr(
|
||||||
new definition_defn(std::move($2), std::move($3), std::move($6))); }
|
new definition_defn(std::move($2), std::move($3), std::move($6))); }
|
||||||
|
@ -109,3 +116,20 @@ pattern
|
||||||
| UID lowercaseParams
|
| UID lowercaseParams
|
||||||
{ $$ = pattern_ptr(new pattern_constr(std::move($1), std::move($2))); }
|
{ $$ = pattern_ptr(new pattern_constr(std::move($1), std::move($2))); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
data
|
||||||
|
: DATA UID EQUAL OCURLY constructors CCURLY
|
||||||
|
{ $$ = definition_ptr(new definition_data(std::move($2), std::move($5))); }
|
||||||
|
;
|
||||||
|
|
||||||
|
constructors
|
||||||
|
: constructors COMMA constructor { $$ = std::move($1); $$.push_back(std::move($3)); }
|
||||||
|
| constructor
|
||||||
|
{ $$ = std::vector<constructor_ptr>(); $$.push_back(std::move($1)); }
|
||||||
|
;
|
||||||
|
|
||||||
|
constructor
|
||||||
|
: UID lowercaseParams
|
||||||
|
{ $$ = constructor_ptr(new constructor(std::move($1), std::move($2))); }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user