CS420 Spring 2014: Programming Assignment 1 & 2
CS420 Spring 2014: Programming Assignment 1 & 2
CS420 Spring 2014: Programming Assignment 1 & 2
Due & files to included in your submission Please submit your source code packaged together through KLMS. Source code must be handed in one zip file and it also needs to include a README file which describes how to build and run your submission. The zip file also needs to include source codes, and test C code. Your grade will be mainly based on your program outputs which will be built and tested according to your instructions. First step: Due on April 15 Build your parser for miniC grammar. Write your input for parser generator and scanner generator you like. Submit your package. The second step: Due on May 2 Design your AST specification. Modify your parser specification to generate the proper AST for miniC. Write the visitor to print your AST in C like format. Write a module to dump your symbol table in proper format, which will be useful debug emitted machine instruction later.
miniC Grammar
// (a)+ : one or more repetition of a // (a)* : zero or more repetition of a // (a)? : a optionally exists // unop : - // binop : *, /, +, -, <, >, <=, >=, ==, != // id : [A-Za-z][A-Za-z0-9_]* // intnum : [0-9]+ // floatnum : [0-9]+.[0-9]+
Program := (DeclList)? (FuncList)? // DeclList FuncList | DeclList | FuncList | 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 | SwitchStmt | CompoundStmt | ; AssignStmt :=Assign ; Assign := id = Expr | id [ Expr ] = Expr CallStmt := Call ; Call := id ( (ArgList)? ) RetStmt := return (Expr)? ; WhileStmt := while ( Expr ) Stmt | do Stmt while ( Expr ) ; ForStmt := for ( Assign ; Expr ; Assign ) Stmt IfStmt := if ( Expr ) Stmt (else Stmt)? SwitchStmt := switch (identifier) { CaseList } CaseList:= (case intnum: StmtList (break;)?)* (default: StmtList (break;)?)? Expr := unop Expr | Expr binop Expr | Call | intnum | floatnum | id | id [ Expr ] | ( Expr ) ArgList := Expr (, Expr)*