For Chinese readme, see README_CN.md
- A compiler that compiles a C-and-Java-like language Mx* to LLVM Language Reference and RISC-V (RV32M) assembly (.sfile), written in Java.
- The output can be executed by interpreter Ravel.
- This project is the assignment for the sophomore year of the ACM class of 2020. See assignment description at Compiler-2022.
- 
This project consists of four parts: - Semantic, Codegen, Optimization, and Bonus.
 
- 
No third-party libraries are used except for Antlr4. - Basic parser and lexer are generated by Antlr4.
 
- 
For detailed implementation descriptions for each part, see DETAIL.md (Chinese only). 
- 
Additional features not required by the assignment description: - Support \* *\comment;
- Support optional comma at the end of list (e.g.: fun(1, 2, 3,););
- Support ++/--expressions as left value;
- Support constructor with parameters (not support semantic check);
- Support escaped character \".
 
- Support 
- 
How to run - Run make <cmd>in a terminal in the root directory of this project. See Makefile for details.- build/- clean: Build the project / clean the runtime content;
- semantic: Run grammar and semantic analysis;
- ir: Compile to LLVM IR;
- run: Compile to RISC-V assembly;
- test_ir: Evaluate the correctness of generated LLVM IR.- Run make test_ir TESTCASE=<name>to evaluate a single test case. See ir_local_judge.py for the evaluation script.
 
- Run 
 
 
- Run 
Italic denotes package names, and bold class names indicate that subsequent classes have implementation or inheritance relationships with that class.
- 
Main 
- 
frontend - parser (generated by Antlr4)
- MxxLexer
- MxxParser
- MxxParserListener, MxxParserBaseListener
- MxxParserVisitor, MxxParserBaseVisitor
 
- ast
- node
- AstNode, NodeRoot, NodeProgramSection, NodeClassDefine, NodeFunctionDefine, NodeVariableDefine, NodeType, NodeArgumentList, NodeSuite, NodeVariableTerm, NodeExpression, NodeBracket, NodeStatement, NodeExpressionList, NodeAtom
 
- scope
- VariableScope, BroadScope, ClassScope, FunctionScope
 
- AstPosition, AstType
- AstBuilder, ForwardCollector, SemanticChecker
 
- node
- ir
- node
- IrNode, IrTop, IrClass, IrFunction, IrBlock, IrInsturction
 
- IrType, IrId
- IrBuilder
 
- node
 
- parser (generated by Antlr4)
- 
backend - asm
- node
- AsmNode, AsmTop, AsmFunction, AsmBlock, AsmInstruction
 
- AsmId, AsmStackFrame
- AsmBuilder
 
- node
- optimization
- IrOptimizer, AsmOptimiz
 
 
- asm
- 
utility - error
- Error, SyntaxError, SemanticError, InternalError
 
- Constant
- CmdArgument
 
- error
