Skip to content

A far-from-complete C compiler, including a lexer, an LL(1) parser and an SLR(1) parser with type checker and evaluator for expression so far, project for course Compiler Principle and Technology.

Notifications You must be signed in to change notification settings

YangXuanyue/Compiler-Frontend

Repository files navigation

Compiler

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.

Lexer

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;

Grammar Configuration

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 | ...}
	...
}

Parser

Input

Parser& operator >>(const Lexer& lexer, Parser& parser);

Example

Lexer lexer;
Parser parser;
std::cin >> lexer >> parser;

About

A far-from-complete C compiler, including a lexer, an LL(1) parser and an SLR(1) parser with type checker and evaluator for expression so far, project for course Compiler Principle and Technology.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages