1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // RunParser.cpp -- External interface to the parser. |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Mon Dec 19 11:00:00 2022 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Mon Dec 19 11:15:00 2022 |
---|
13 | // Update Count : 0 |
---|
14 | // |
---|
15 | |
---|
16 | #include "RunParser.hpp" |
---|
17 | |
---|
18 | #include "Parser/ParseNode.h" // for DeclarationNode, buildList |
---|
19 | #include "Parser/TypedefTable.h" // for TypedefTable |
---|
20 | |
---|
21 | // Variables global to the parsing code. |
---|
22 | LinkageSpec::Spec linkage = LinkageSpec::Cforall; |
---|
23 | TypedefTable typedefTable; |
---|
24 | DeclarationNode * parseTree = nullptr; |
---|
25 | |
---|
26 | void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit ) { |
---|
27 | extern int yyparse( void ); |
---|
28 | extern FILE * yyin; |
---|
29 | extern int yylineno; |
---|
30 | |
---|
31 | // Set global information. |
---|
32 | ::linkage = linkage; |
---|
33 | yyin = input; |
---|
34 | yylineno = 1; |
---|
35 | |
---|
36 | int parseStatus = yyparse(); |
---|
37 | fclose( input ); |
---|
38 | if ( alwaysExit || parseStatus != 0 ) { |
---|
39 | exit( parseStatus ); |
---|
40 | } // if |
---|
41 | } // parse |
---|
42 | |
---|
43 | void dumpParseTree( std::ostream & out ) { |
---|
44 | parseTree->printList( out ); |
---|
45 | delete parseTree; |
---|
46 | parseTree = nullptr; |
---|
47 | } |
---|
48 | |
---|
49 | std::list<Declaration *> buildUnit(void) { |
---|
50 | std::list<Declaration *> translationUnit; |
---|
51 | buildList( parseTree, translationUnit ); |
---|
52 | |
---|
53 | delete parseTree; |
---|
54 | parseTree = nullptr; |
---|
55 | |
---|
56 | return translationUnit; |
---|
57 | } |
---|
58 | |
---|
59 | // Local Variables: // |
---|
60 | // tab-width: 4 // |
---|
61 | // mode: c++ // |
---|
62 | // compile-command: "make install" // |
---|
63 | // End: // |
---|