Separate definitions in compiler series

This commit is contained in:
2020-03-24 21:08:02 -07:00
parent 6714e18e7c
commit 0efa05142f
6 changed files with 194 additions and 134 deletions

View File

@@ -5,7 +5,9 @@
#include "definition.hpp"
#include "parser.hpp"
std::vector<definition_ptr> program;
std::vector<definition_data_ptr> defs_data;
std::vector<definition_defn_ptr> defs_defn;
extern yy::parser::symbol_type yylex();
%}
@@ -34,11 +36,11 @@ extern yy::parser::symbol_type yylex();
%define api.token.constructor
%type <std::vector<std::string>> lowercaseParams uppercaseParams
%type <std::vector<definition_ptr>> program definitions
%type <std::vector<branch_ptr>> branches
%type <std::vector<constructor_ptr>> constructors
%type <ast_ptr> aAdd aMul case app appBase
%type <definition_ptr> definition defn data
%type <definition_data_ptr> data
%type <definition_defn_ptr> defn
%type <branch_ptr> branch
%type <pattern_ptr> pattern
%type <constructor_ptr> constructor
@@ -48,22 +50,22 @@ extern yy::parser::symbol_type yylex();
%%
program
: definitions { program = std::move($1); }
: definitions { }
;
definitions
: definitions definition { $$ = std::move($1); $$.push_back(std::move($2)); }
| definition { $$ = std::vector<definition_ptr>(); $$.push_back(std::move($1)); }
: definitions definition { }
| definition { }
;
definition
: defn { $$ = std::move($1); }
| data { $$ = std::move($1); }
: defn { defs_defn.push_back(std::move($1)); }
| data { defs_data.push_back(std::move($1)); }
;
defn
: DEFN LID lowercaseParams EQUAL OCURLY aAdd CCURLY
{ $$ = definition_ptr(
{ $$ = definition_defn_ptr(
new definition_defn(std::move($2), std::move($3), std::move($6))); }
;
@@ -125,7 +127,7 @@ pattern
data
: DATA UID EQUAL OCURLY constructors CCURLY
{ $$ = definition_ptr(new definition_data(std::move($2), std::move($5))); }
{ $$ = definition_data_ptr(new definition_data(std::move($2), std::move($5))); }
;
constructors