A far-from-complete C compiler, including a lexer and an expression parser so far, project for course Compiler Principle and Technology
. For details please refer to Lab Report for Lexer Design and Implementation and Lab Report for LL(1) Parser Design and Implementation.
Constructor
//constructs a lexer which stops analysis at end_char, typically EOF or '\n'
Lexer(char end_char = EOF);
Input
//returns a ref of lexer in order to be followed by a parser
//nothing more than a grammar sugar
const Lexer& operator >>(std::istream& in, Lexer& lexer);
Example
Lexer lexer;
std::cin >> lexer;
The grammar for parsing C codes hasn't completed yet. Nevertheless, it can now be configured in ../Compiler/Parser/Grammar.ini
in the form of:
nonterminals = {
E T F ...
}
terminals = {
+ / if for ...
}
start_symbol = {E}
productions = {
{E -> E+T | E-T | ...}
...
}
Input
Parser& operator >>(const Lexer& lexer, Parser& parser);
Example
Lexer lexer;
Parser parser;
std::cin >> lexer >> parser;