Aleph-w
7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
compiler_parser_example.cc
Go to the documentation of this file.
1
/*
2
Aleph_w
3
4
Data structures & Algorithms
5
version 2.0.0b
6
https://github.com/lrleon/Aleph-w
7
8
This file is part of Aleph-w library
9
10
Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files (the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions:
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
*/
30
31
37
# include <iostream>
38
39
# include <
Compiler_Parser.H
>
40
41
using namespace
Aleph
;
42
43
int
main
()
44
{
45
Source_Manager
sm;
46
const
auto
file_id = sm.
add_virtual_file
(
47
"demo.aw"
,
48
"import \"math.aw\";\n"
49
"fn inc(x) {\n"
50
" let y = x + 1;\n"
51
" return y;\n"
52
"}\n"
53
"let value = inc(41);\n"
);
54
55
Diagnostic_Engine
dx(sm);
56
Compiler_Ast_Context
ctx(1 << 16);
57
Compiler_Parser
parser(ctx, sm, file_id, &dx);
58
59
const
auto
*
module
= parser.parse_module();
60
61
std::cout <<
compiler_dump_module
(module);
62
if
(dx.
size
() > 0)
63
{
64
std::cout <<
"\nDiagnostics:\n"
;
65
dx.
render_plain
(std::cout);
66
return
dx.
has_errors
() ? 1 : 0;
67
}
68
69
return
0;
70
}
Compiler_Parser.H
Recursive-descent parser for the compiler-support MVP grammar.
Aleph::Compiler_Ast_Context
Arena-backed ownership context for AST nodes.
Definition
Compiler_AST.H:329
Aleph::Compiler_Parser
Recursive-descent parser that produces an AST in Compiler_Ast_Context.
Definition
Compiler_Parser.H:76
Aleph::Diagnostic_Engine
Diagnostic accumulator and renderer.
Definition
ah-diagnostics.H:152
Aleph::Diagnostic_Engine::render_plain
void render_plain(std::ostream &out) const
Renders all diagnostics as deterministic plain text.
Definition
ah-diagnostics.H:334
Aleph::Diagnostic_Engine::has_errors
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
Definition
ah-diagnostics.H:320
Aleph::Diagnostic_Engine::size
size_t size() const noexcept
Returns the number of stored diagnostics.
Definition
ah-diagnostics.H:302
Aleph::Source_Manager
Stores source files and resolves offsets into human-readable data.
Definition
ah-source.H:184
Aleph::Source_Manager::add_virtual_file
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
Definition
ah-source.H:258
main
int main()
Definition
compiler_parser_example.cc:43
Aleph
Main namespace for Aleph-w library functions.
Definition
Adaptive_Huffman.H:61
Aleph::compiler_dump_module
std::string compiler_dump_module(const Compiler_Module *module)
Dumps a parsed module in a deterministic text format.
Definition
Compiler_AST.H:1558
Examples
compiler_parser_example.cc
Generated by
1.9.8