[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>
This commit is contained in:
Dave Abrahams
2021-03-09 19:46:30 -08:00
committed by GitHub
co-authored by Geoff Romer
parent 5375c01056
commit 07a37933c6
12 changed files with 187 additions and 50 deletions
@@ -0,0 +1,40 @@
// 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
#ifndef EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
#define EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
#include <variant>
#include "executable_semantics/ast/abstract_syntax_tree.h"
#include "executable_semantics/syntax/parser.h" // from parser.ypp
namespace Carbon {
// The state and functionality that is threaded "globally" through the
// lexing/parsing process.
class ParseAndLexContext {
public:
// Creates an instance analyzing the given input file.
ParseAndLexContext(const std::string& inputFile) : inputFileName(inputFile) {}
// Writes a syntax error diagnostic, containing message, for the input file at
// the given line, to standard error.
auto PrintDiagnostic(const char* message, int lineNumber) -> void;
private:
// A path to the file processed, relative to the current working directory
// when *this is called.
const std::string inputFileName;
};
} // namespace Carbon
// Gives flex the yylex prototype we want.
#define YY_DECL int yylex(Carbon::ParseAndLexContext& context)
// Declares yylex for the parser's sake.
YY_DECL;
#endif // EXECUTABLE_SYNTAX_DRIVER_H_