This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.h
More file actions
54 lines (45 loc) · 1.7 KB
/
syntax.h
File metadata and controls
54 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <boost/functional/hash.hpp>
#include "lexeme.h"
#include "parse.h"
#include <unordered_map>
#include <stack>
#include <queue>
namespace std
{
template <>
struct hash< sap::lex >
{
size_t operator()( const sap::lex& lhs ) const
{
using pair = std::pair< sap::lex::type, boost::variant< sap::lex::symbol
, sap::lex::reserved_word
, sap::lex::rule
, uint
>
>;
boost::hash< pair > h{};
switch (lhs.type_) {
case sap::lex::type::SYMBOL:
return h( { lhs.type_, boost::get< sap::lex::symbol >( lhs.value_ ) } );
case sap::lex::type::RESERVED:
return h( { lhs.type_, boost::get< sap::lex::reserved_word >( lhs.value_ ) } );
case sap::lex::type::RULE:
return h( { lhs.type_, boost::get< sap::lex::rule >( lhs.value_ ) } );
default:
return h( { lhs.type_, 0u } );
}
}
};
} // namespace std
namespace sap
{
using Table = std::unordered_map< lex::rule, std::unordered_multimap< lex, int >, boost::hash< lex::rule > >;
using MIterator = std::unordered_multimap< lex, int >::const_iterator;
using Stack = std::stack< lex >;
using LIterator = Lexems::const_iterator;
using Queue = std::queue< uint >;
void push_rule( Stack& st, const int rule_number );
Queue parse( const Table& table, LIterator begin, const LIterator end, Stack ss, uint newline = 0 );
Table createTable();
} // namespace sap