Separate parsing from type-checking and evaluation. (#345)

This change caused the syntax error in undef2.6c ("fun" instead of "fn") to be
detected as one would expect, thus the changed golden file.
This commit is contained in:
Dave Abrahams
2021-03-05 15:00:44 -08:00
committed by GitHub
parent 62ff5597e4
commit 2f83c4be48
3 changed files with 32 additions and 8 deletions
+12 -3
View File
@@ -14,21 +14,30 @@
}
%code requires {
#include <optional>
#include "executable_semantics/ast/declaration.h"
#include "executable_semantics/ast/field_list.h"
#include "executable_semantics/ast/function_definition.h"
namespace Carbon {
// A representation of the parsed program.
using AST = std::list<Carbon::Declaration>*;
}
}
%code {
extern int yylineno;
extern int yylex();
void yyerror(char* error) {
void yyerror(std::optional<Carbon::AST> const& parsedProgram, char* error) {
Carbon::PrintSyntaxError(error, yylineno);
}
// void yyerror(char* error, ...);
}
%parse-param {std::optional<Carbon::AST>& parsedProgram}
%union {
char* str;
int num;
@@ -109,7 +118,7 @@ void yyerror(char* error) {
%locations
%%
input: declaration_list
{ Carbon::ExecProgram($1); }
{ parsedProgram = $1; }
;
pattern:
expression