libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
2
3#include <stdio.h>
4#include <stdlib.h>
5#include "pulsar.h"
6
7int main(int argc, const char* argv[]) {
8 ps_project_print();
10
11 if (argc != 2) {
12 fprintf(stderr, "usage: %s FILE\n", argv[0]);
13 exit(1);
14 }
15
16 // read the file contents
17 const char* filename = argv[1];
19 char* buffer = ps_read_file_safe(filename, &length);
20 if (!buffer) {
21 exit(1);
22 }
23
24 printf("\nBEGIN MAIN OUTPUT\n\n");
25
26 // create the file context
27 struct ps_file_ctx file_ctx;
29
30 {
32
33 // lex the file
34 struct ps_token_arr* tokens = ps_lex(&file_ctx);
35 if (!tokens) {
37 exit(1);
38 }
39 printf("tokens:\n");
40 /* clang-format off */
41 $for(tokens, $(token) in {
42 ps_token_print(&token, '\n');
43 });
44 /* clang-format on */
45
46 // construct the ast
47 struct ps_node_arr* nodes = ps_parse(tokens, &file_ctx);
48 if (!nodes) {
50 exit(1);
51 }
52 printf("\nast:\n");
53 /* clang-format off */
54 $for(nodes, $(node) in {
55 ps_node_print(node, '\n', 0);
56 });
57 /* clang-format on */
58
60 }
61
62 printf("\nEND MAIN OUTPUT\n");
63
64 free(buffer);
65
66 return 0;
67}
void ps_arena_open(enum ps_arena_domain domain)
Initializes the given arena for allocation.
Definition arena.c:24
void ps_arena_close(enum ps_arena_domain domain)
Destroys any allocated objects in the given arena.
Definition arena.c:45
@ PS_ARENA_AST
Definition arena.h:25
#define in
void ps_configure(void)
Run at the start of your program.
Definition configure.c:13
#define isize
Definition def.h:49
#define ps_print_errors()
Definition error.h:82
void ps_file_ctx_init(struct ps_file_ctx *file_ctx, STR filename, char *buffer, usize length)
Initializes file_ctx to describe the given file (filename, buffer, length).
Definition io.c:7
char * ps_read_file_safe(const char *filename, isize *length_ext)
Definition io.c:14
char buffer[ITOA_BUFFER_SIZE]
Definition itoa.c:11
struct ps_token_arr * ps_lex(const struct ps_file_ctx *file_ctx)
Lexes the given source code into tokens.
Definition lexer.c:559
static void usize length
Definition lexer.h:71
int main(int argc, const char *argv[])
Definition main.c:7
struct ps_node_arr * ps_parse(struct ps_token_arr *tokens, const struct ps_file_ctx *file_ctx)
Constructs a series of nodes from the given tokens.
Definition parser.c:761
Relevant public includes.
Information captured in a file necessary for effective info/error reporting.
Definition io.h:15
STR filename
Definition io.h:16