Files
carbon-lang/executable_semantics/syntax/syntax_helpers.cpp
T
Dave AbrahamsandGeoff Romer 07a37933c6 [executable semantics] Add Syntax driver (#362)
Slowly bringing this into line with Bison's C++ example parser
so we can use strong semantic values for symbols rather than
leaking pointers.  First step is to thread a `ParseAndLexContext` 
object through the whole syntactic analysis state, like the 
example has.  In the example, it's called `driver`.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-03-09 19:46:30 -08:00

44 lines
1.4 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "executable_semantics/syntax/syntax_helpers.h"
#include <iostream>
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/typecheck.h"
#include "executable_semantics/tracing_flag.h"
namespace Carbon {
void ExecProgram(std::list<Declaration>* fs) {
if (tracing_output) {
std::cout << "********** source program **********" << std::endl;
for (const auto& decl : *fs) {
decl.Print();
}
std::cout << "********** type checking **********" << std::endl;
}
state = new State(); // Compile-time state.
std::pair<TypeEnv, Env> p = TopLevel(fs);
TypeEnv top = p.first;
Env ct_top = p.second;
std::list<Declaration> new_decls;
for (const auto& decl : *fs) {
new_decls.push_back(decl.TypeChecked(top, ct_top));
}
if (tracing_output) {
std::cout << std::endl;
std::cout << "********** type checking complete **********" << std::endl;
for (const auto& decl : new_decls) {
decl.Print();
}
std::cout << "********** starting execution **********" << std::endl;
}
int result = InterpProgram(&new_decls);
std::cout << "result: " << result << std::endl;
}
} // namespace Carbon