Skip to content

Commit 6219bca

Browse files
committed
change naming
1 parent 1a23db6 commit 6219bca

File tree

10 files changed

+152
-154
lines changed

10 files changed

+152
-154
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
CXX = g++
2-
CXXFLAGS = -std=c++20 -O3
1+
CXX = clang++
2+
CXXFLAGS = -std=c++20 -O -Wall -Wextra -Wpedantic -Wshadow -Wold-style-cast -Wunused -Wcast-align -Wnull-dereference -Wconversion -fstrict-aliasing -fsanitize=address -fsanitize=undefined -fsanitize=leak
33
SRC_DIR = src
44
HPP_DIR = include
55
OBJ_DIR = out

include/grammar.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using production = std::vector<std::string>;
77

8-
struct grammar {
8+
struct Grammar {
99

1010
/**
1111
* @brief Constructs a grammar by reading from the specified file.
@@ -15,7 +15,7 @@ struct grammar {
1515
* Initializes the grammar by setting the filename for input. The actual
1616
* grammar data is read and processed through the `read_from_file` function.
1717
*/
18-
explicit grammar(std::string filename);
18+
explicit Grammar(std::string filename);
1919

2020
/**
2121
* @brief Reads and loads the grammar from a file.
@@ -27,7 +27,7 @@ struct grammar {
2727
* @throws GrammarError if there are errors reading symbols, parsing the
2828
* grammar, or splitting the rules as specified in the input file.
2929
*/
30-
void read_from_file();
30+
void ReadFromFile();
3131

3232
/**
3333
* @brief Adds a rule to the grammar.
@@ -39,7 +39,7 @@ struct grammar {
3939
* consequent production. This function processes and adds each rule for
4040
* parsing.
4141
*/
42-
void add_rule(const std::string& antecedent, const std::string& consequent);
42+
void AddRule(const std::string& antecedent, const std::string& consequent);
4343

4444
/**
4545
* @brief Sets the axiom (entry point) of the grammar.
@@ -49,7 +49,7 @@ struct grammar {
4949
* Defines the starting point for the grammar, which is used in parsing
5050
* algorithms and must be a non-terminal symbol present in the grammar.
5151
*/
52-
void set_axiom(const std::string& axiom);
52+
void SetAxiom(const std::string& axiom);
5353

5454
/**
5555
* @brief Checks if a given antecedent has an empty production.
@@ -61,7 +61,7 @@ struct grammar {
6161
* An empty production is represented as `<antecedent> -> ;`, indicating
6262
* that the antecedent can produce an empty string.
6363
*/
64-
bool has_empty_production(const std::string& antecedent);
64+
bool HasEmptyProduction(const std::string& antecedent);
6565

6666
/**
6767
* @brief Filters grammar rules that contain a specific token in their
@@ -75,15 +75,15 @@ struct grammar {
7575
* and returns those rules.
7676
*/
7777
std::vector<std::pair<const std::string, production>>
78-
filter_rules_by_consequent(const std::string& arg);
78+
FilterRulesByConsequent(const std::string& arg);
7979

8080
/**
8181
* @brief Prints the current grammar structure to standard output.
8282
*
8383
* This function provides a debug view of the grammar by printing out all
8484
* rules, the axiom, and other relevant details.
8585
*/
86-
void debug();
86+
void Debug();
8787

8888
/**
8989
* @brief Splits a production string into individual tokens.
@@ -96,7 +96,7 @@ struct grammar {
9696
* on the symbol table, allowing terminals and non-terminals to be
9797
* identified.
9898
*/
99-
static std::vector<std::string> split(const std::string& s);
99+
static std::vector<std::string> Split(const std::string& s);
100100

101101
/**
102102
* @brief Checks if a rule exhibits left recursion.
@@ -110,8 +110,8 @@ struct grammar {
110110
* first symbol in its consequent, which may cause issues in top-down
111111
* parsing algorithms.
112112
*/
113-
static bool has_left_recursion(const std::string& antecedent,
114-
const std::vector<std::string>& consequent);
113+
static bool HasLeftRecursion(const std::string& antecedent,
114+
const std::vector<std::string>& consequent);
115115

116116
/**
117117
* @brief Stores the grammar rules with each antecedent mapped to a list of
@@ -122,10 +122,10 @@ struct grammar {
122122
/**
123123
* @brief The axiom or entry point of the grammar.
124124
*/
125-
std::string AXIOM_;
125+
std::string axiom_;
126126

127127
/**
128128
* @brief The filename from which the grammar is read.
129129
*/
130-
const std::string filename_;
130+
const std::string kFilename;
131131
};

include/lexer.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <boost/spirit/include/lex_lexertl.hpp>
22
#include <vector>
3-
class lexer {
3+
class Lex {
44
std::string filename_;
55
std::vector<std::string> tokens_;
66
unsigned current_;
@@ -30,8 +30,8 @@ class lexer {
3030
* @see symbol_table::st_
3131
*/
3232
template <typename Lexer>
33-
struct parse_input : boost::spirit::lex::lexer<Lexer> {
34-
parse_input();
33+
struct ParseInput : boost::spirit::lex::lexer<Lexer> {
34+
ParseInput();
3535
};
3636

3737
/**
@@ -49,7 +49,7 @@ class lexer {
4949
*
5050
* @see symbol_table::token_types_r_
5151
*/
52-
struct add {
52+
struct Add {
5353
typedef bool result_type;
5454
template <typename Token>
5555
bool operator()(Token const& t, std::vector<std::string>& tks) const;
@@ -63,7 +63,7 @@ class lexer {
6363
* @note The program aborts if any errors occur during lexer creation or
6464
* tokenization.
6565
*/
66-
explicit lexer(std::string filename);
66+
explicit Lex(std::string filename);
6767

6868
/**
6969
* @brief Retrieves the next token from the token vector.
@@ -73,7 +73,7 @@ class lexer {
7373
*
7474
* This function allows sequential access to tokens processed by the lexer.
7575
*/
76-
std::string next();
76+
std::string Next();
7777

7878
private:
7979
/**
@@ -105,5 +105,5 @@ class lexer {
105105
* @see tokens_
106106
* @see filename_
107107
*/
108-
void tokenize();
108+
void Tokenize();
109109
};

include/ll1_parser.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LL1Parser {
2020
* @param gr Grammar object to parse with.
2121
* @param text_file Name of the file containing input to parse.
2222
*/
23-
LL1Parser(grammar gr, std::string text_file);
23+
LL1Parser(Grammar gr, std::string text_file);
2424

2525
/**
2626
* @brief Constructs an LL1Parser with a grammar file and an input file.
@@ -64,14 +64,14 @@ class LL1Parser {
6464
* to the LL(1) grammar; `false` if parsing fails due to a mismatch,
6565
* conflict, or unexpected input symbol.
6666
*/
67-
bool parse();
67+
bool Parse();
6868

6969
/**
7070
* @brief Print the LL(1) parsing table to standard output.
7171
*
7272
* Displays the LL(1) table for debugging and analysis.
7373
*/
74-
void print_table();
74+
void PrintTable();
7575

7676
/**
7777
* @brief Prints the remaining symbols in the parsing stack after the
@@ -83,15 +83,15 @@ class LL1Parser {
8383
* provides insight into where the parsing process may have diverged from
8484
* expected behavior.
8585
*/
86-
void print_stack_trace();
86+
void PrintStackTrace();
8787

8888
/**
89-
* @brief Prints the last TRACE_SIZE symbols processed.
89+
* @brief Prints the last kTraceSize symbols processed.
9090
*
9191
* Primarily used to identify the most recent tokens processed in case
9292
* of parsing errors.
9393
*/
94-
void print_symbol_hist();
94+
void PrintSymbolHist();
9595

9696
private:
9797
/**
@@ -120,7 +120,7 @@ class LL1Parser {
120120
* symbols that can start derivations of the rule, and possibly epsilon if
121121
* the rule can derive an empty string.
122122
*/
123-
void first(std::span<const std::string> rule,
123+
void First(std::span<const std::string> rule,
124124
std::unordered_set<std::string>& result);
125125

126126
/**
@@ -133,7 +133,7 @@ class LL1Parser {
133133
* expanding and updating the sets until no further changes occur (i.e., a
134134
* fixed-point is reached).
135135
*/
136-
void compute_first_sets();
136+
void ComputFirstSets();
137137

138138
/**
139139
* @brief Computes the FOLLOW set for a given non-terminal symbol in the
@@ -153,33 +153,33 @@ class LL1Parser {
153153
* @return An unordered set of strings containing symbols that form the
154154
* FOLLOW set for `arg`.
155155
*/
156-
std::unordered_set<std::string> follow(const std::string& arg);
156+
std::unordered_set<std::string> Follow(const std::string& arg);
157157

158158
/**
159-
* @brief Computes the director symbols (prediction symbols) for a given
159+
* @brief Computes the prediction symbols for a given
160160
* production rule.
161161
*
162-
* The director symbols for a rule, also called prediction symbols,
162+
* The prediction symbols for a rule,
163163
* determine the set of input symbols that can trigger this rule in the
164-
* parsing table. This function calculates the director symbols based on the
165-
* FIRST set of the consequent and, if epsilon (the empty symbol) is in the
166-
* FIRST set, also includes the FOLLOW set of the antecedent.
164+
* parsing table. This function calculates the prediction symbols based on
165+
* the FIRST set of the consequent and, if epsilon (the empty symbol) is in
166+
* the FIRST set, also includes the FOLLOW set of the antecedent.
167167
*
168168
* - If the FIRST set of the consequent does not contain epsilon, the
169-
* director symbols are simply the FIRST symbols of the consequent.
170-
* - If the FIRST set of the consequent contains epsilon, the director
169+
* prediction symbols are simply the FIRST symbols of the consequent.
170+
* - If the FIRST set of the consequent contains epsilon, the prediction
171171
* symbols are computed as (FIRST(consequent) - {epsilon}) ∪
172172
* FOLLOW(antecedent).
173173
*
174174
* @param antecedent The left-hand side non-terminal symbol of the rule.
175175
* @param consequent A vector of symbols on the right-hand side of the rule
176176
* (production body).
177-
* @return An unordered set of strings containing the director symbols for
177+
* @return An unordered set of strings containing the prediction symbols for
178178
* the specified rule.
179179
*/
180180
std::unordered_set<std::string>
181-
director_symbols(const std::string& antecedent,
182-
const std::vector<std::string>& consequent);
181+
PredictionSymbols(const std::string& antecedent,
182+
const std::vector<std::string>& consequent);
183183

184184
/**
185185
* @brief Recursive utility function to compute the FOLLOW set for a
@@ -203,9 +203,9 @@ class LL1Parser {
203203
* @param next_symbols An unordered set to accumulate symbols forming the
204204
* FOLLOW set of the target non-terminal as they are discovered.
205205
*/
206-
void follow_util(const std::string& arg,
207-
std::unordered_set<std::string>& visited,
208-
std::unordered_set<std::string>& next_symbols);
206+
void FollowUtil(const std::string& arg,
207+
std::unordered_set<std::string>& visited,
208+
std::unordered_set<std::string>& next_symbols);
209209

210210
/**
211211
* @brief Creates the LL(1) parsing table for the grammar.
@@ -228,25 +228,25 @@ class LL1Parser {
228228
* grammar is LL(1) compatible; `false` if any conflicts are detected,
229229
* showing that the grammar does not meet LL(1) requirements.
230230
*/
231-
bool create_ll1_table();
231+
bool CreateLL1Table();
232232

233233
/// @brief Size limit for symbol history trace, defaults to 5.
234-
const size_t TRACE_SIZE{5};
234+
const size_t kTraceSize{5};
235235

236236
/// @brief The LL(1) parsing table, mapping non-terminals and terminals to
237237
/// productions.
238238
ll1_table ll1_t_;
239239

240240
/// @brief Grammar object associated with this parser.
241-
grammar gr_;
241+
Grammar gr_;
242242

243243
/// @brief FIRST sets for each non-terminal in the grammar.
244244
std::unordered_map<std::string, std::unordered_set<std::string>> first_sets;
245245

246246
/// @brief Stack for managing parsing symbols.
247247
std::stack<std::string> symbol_stack_;
248248

249-
/// @brief Deque for tracking the most recent TRACE_SIZE symbols parsed.
249+
/// @brief Deque for tracking the most recent kTraceSize symbols parsed.
250250
std::deque<std::string> trace_;
251251

252252
/// @brief Path to the grammar file used in this parser.

include/symbol_table.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,51 +43,51 @@ struct symbol_table {
4343
* @param identifier Name of the terminal symbol.
4444
* @param regex Regular expression representing the terminal symbol.
4545
*/
46-
static void put_symbol(const std::string& identifier,
47-
const std::string& regex);
46+
static void PutSymbol(const std::string& identifier,
47+
const std::string& regex);
4848

4949
/**
5050
* @brief Adds a non-terminal symbol to the symbol table.
5151
*
5252
* @param identifier Name of the non-terminal symbol.
5353
*/
54-
static void put_symbol(const std::string& identifier);
54+
static void PutSymbol(const std::string& identifier);
5555

5656
/**
5757
* @brief Checks if a symbol exists in the symbol table.
5858
*
5959
* @param s Symbol identifier to search.
6060
* @return true if the symbol is present, otherwise false.
6161
*/
62-
static bool in(const std::string& s);
62+
static bool In(const std::string& s);
6363

6464
/**
6565
* @brief Checks if a symbol is a terminal.
6666
*
6767
* @param s Symbol identifier to check.
6868
* @return true if the symbol is terminal, otherwise false.
6969
*/
70-
static bool is_terminal(const std::string& s);
70+
static bool IsTerminal(const std::string& s);
7171

7272
/**
7373
* @brief Retrieves the regex pattern for a terminal symbol.
7474
*
7575
* @param terminal Terminal symbol identifier.
7676
* @return Regex pattern associated with the terminal symbol.
7777
*/
78-
static std::string get_value(const std::string& terminal);
78+
static std::string GetValue(const std::string& terminal);
7979

8080
/**
8181
* @brief Prints all symbols and their properties in the symbol table.
8282
*
8383
* Outputs the symbol table for debugging purposes.
8484
*/
85-
static void debug();
85+
static void Debug();
8686

8787
/**
8888
* @brief Sets the end-of-line symbol.
8989
*
9090
* @param eol String to use as the new end-of-line symbol.
9191
*/
92-
static void set_eol(const std::string& eol);
92+
static void SetEol(const std::string& eol);
9393
};

0 commit comments

Comments
 (0)