Releases: MuttonYung/Iced-SysY-Compiler
Releases · MuttonYung/Iced-SysY-Compiler
Parser
Parser works by building a Parse Tree, with each single leaf node as a terminator and non-leaf node as a syntactic constituent.
Parser Test
Carry out lexical and syntactic analysis.
Output each symbol's token and itself, and syntactic constituents except <BlockItem>, <Decl> and <BType>.
Example
testfile.txt
int main(){
int c;
c= getint();
printf("%d",c);
return c;
}
output.txt
INTTK int
MAINTK main
LPARENT (
RPARENT )
LBRACE {
INTTK int
IDENFR c
<VarDef>
SEMICN ;
<VarDecl>
IDENFR c
<LVal>
ASSIGN =
GETINTTK getint
LPARENT (
RPARENT )
SEMICN ;
<Stmt>
PRINTFTK printf
LPARENT (
STRCON "%d"
COMMA ,
IDENFR c
<LVal>
<PrimaryExp>
<UnaryExp>
<MulExp>
<AddExp>
<Exp>
RPARENT )
SEMICN ;
<Stmt>
RETURNTK return
IDENFR c
<LVal>
<PrimaryExp>
<UnaryExp>
<MulExp>
<AddExp>
<Exp>
SEMICN ;
<Stmt>
RBRACE }
<Block>
<MainFuncDef>
<CompUnit>
Lexical Analysis
完成词法分析测试.
程序运行的入口为 src 目录下 Compiler.java 中的 main 方法.
Lexical analysis test passed.
Use main() in Compiler.java as entrance.
Example
testfile.txt
const int array[2] = {1,2};
int main(){
int c;
c = getint();
printf("output is %d",c);
return c;
}
output.txt
CONSTTK const
INTTK int
IDENFR array
LBRACK [
INTCON 2
RBRACK ]
ASSIGN =
LBRACE {
INTCON 1
COMMA ,
INTCON 2
RBRACE }
SEMICN ;
INTTK int
MAINTK main
LPARENT (
RPARENT )
LBRACE {
INTTK int
IDENFR c
SEMICN ;
IDENFR c
ASSIGN =
GETINTTK getint
LPARENT (
RPARENT )
SEMICN ;
PRINTFTK printf
LPARENT (
STRCON "output is %d"
COMMA ,
IDENFR c
RPARENT )
SEMICN ;
RETURNTK return
IDENFR c
SEMICN ;
RBRACE }