User Guide
main_units.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 Blue Brain Project, EPFL.
3
* See the top-level LICENSE file for details.
4
*
5
* SPDX-License-Identifier: Apache-2.0
6
*/
7
8
#include "
config/config.h
"
9
#include "
lexer/unit_lexer.hpp
"
10
#include "
parser/unit_driver.hpp
"
11
#include "
utils/logger.hpp
"
12
13
#include <CLI/CLI.hpp>
14
15
#include <fstream>
16
17
/**
18
* \file
19
* Example of standalone lexer program for Units that
20
* demonstrate use of UnitLexer and UnitDriver classes.
21
*/
22
23
using namespace
nmodl
;
24
using
Token
= parser::UnitParser::token;
25
26
int
main
(
int
argc,
const
char
* argv[]) {
27
CLI::App app{fmt::format(
"Unit-Lexer : Standalone Lexer for Units({})"
,
Version::to_string
())};
28
29
std::vector<std::string> files;
30
app.add_option(
"file"
, files,
"One or more units files to process"
)
31
->required()
32
->check(CLI::ExistingFile);
33
34
CLI11_PARSE(app, argc, argv);
35
36
for
(
const
auto
& f: files) {
37
nmodl::logger
->info(
"Processing {}"
, f);
38
std::ifstream file(f);
39
nmodl::parser::UnitDriver
driver
;
40
nmodl::parser::UnitLexer
scanner(
driver
, &file);
41
42
/// parse Units file and print token until EOF
43
while
(
true
) {
44
auto
sym = scanner.
next_token
();
45
auto
token_type
= sym.type_get();
46
if
(
token_type
== parser::UnitParser::by_type(Token::END).type_get()) {
47
break
;
48
}
49
std::cout << sym.value.as<std::string>() << std::endl;
50
}
51
}
52
return
0;
53
}
nmodl
encapsulates code generation backend implementations
Definition:
ast_common.hpp:26
unit_driver.hpp
nmodl::logger
logger_type logger
Definition:
logger.cpp:34
driver
nmodl::parser::UnitDriver driver
Definition:
parser.cpp:28
main
int main(int argc, const char *argv[])
Definition:
main_units.cpp:26
unit_lexer.hpp
nmodl::Version::to_string
static std::string to_string()
return version string (version + git id) as a string
Definition:
config.h:39
Token
parser::CParser::token Token
Definition:
main_c.cpp:28
nmodl::parser::UnitLexer::next_token
virtual UnitParser::symbol_type next_token()
Function for lexer to scan token (replacement for yylex())
logger.hpp
Implement logger based on spdlog library.
config.h
Version information and units file path.
nmodl::parser::UnitLexer
Represent Lexer/Scanner class for Units parsing.
Definition:
unit_lexer.hpp:49
nmodl::parser::UnitDriver
Class that binds all pieces together for parsing C units.
Definition:
unit_driver.hpp:39
nmodl::token_type
TokenType token_type(const std::string &name)
Return token type for given token name.
Definition:
token_mapping.cpp:284
src
lexer
main_units.cpp