Skip to content

eubnara/flex-bison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

miniC (using flex&bison)

This project is compiler project using flex and bison by Yubi Lee, Sungmin Kim by pair-programming.

1. Building

make

or

flex miniC.l
bison -d miniC.y
gcc -o miniC miniC.tab.c print.c symboltable.c lex.yy.c -g -lfl

2. How to run

miniC < input.txt

3. Results

Abstract Syntax Tree (AST): tree.txt
Symbol table: table.txt

4. We follow the rule below.

Program := (DeclList)? (FuncList)?   // DeclList FuncList | DeclList | FuncList | ε
DeclList := (Declaration)+          // Declaration | DeclList Declaration
FuncList := (Function)+
Declaration := Type IdentList ;
IdentList := identifier (, identifier)*  // identifier | IdentList , identifier
identifier := id | id [ intnum ]      // (Note) [, ] are not symbols used in regular expression
Function := Type id ( (ParamList)? ) CompoundStmt
ParamList := Type identifier (, Type identifier)*
Type := int | float
CompoundStmt := { (DeclList)? StmtList }
StmtList := (Stmt)*
Stmt := AssignStmt | CallStmt | RetStmt | WhileStmt | ForStmt | IfStmt | CompoundStmt | ;
AssignStmt :=Assign ; 
Assign := id = Expr | id [ Expr ] = Expr
CallStmt := Call ;
Call := id ( (ArgList)? )
RetStmt := return (Expr)? ; 

So, Our miniC program doesn't follow the rule below.
    1. ++, --
    2. According to this rule 
        CompoundStmt := { (DeclList)? StmtList }
        
       Followings are illegal: 
        int main()
        {
            int a;
            {
                int b; // this is wrong because there is no "StmtList".
            }
        }

About

2016-2 compiler project in SKKU

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages