jhnaldo / mini-c-compiler Goto Github PK
View Code? Open in Web Editor NEWcompiler of mini-c
compiler of mini-c
// Copyright (c) 2014 Jihyeok Park // KAIST CS420 Project // NAME : Jihyeok Park // STUDENT NO : 20120484 // This is the parser for mini-c. // It follows below mini-c grammar. ######################### HOW TO RUN ########################## environment setting : make init build : make all test : make run < [filename].c clean : make clean ###################### mini-C 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 := \(Declaration\)\+ FuncList := \(Function\)\+ Declaration := Type IdentList ; IdentList := Identifier\(, Identifier\)* identifier := id \| id [ intnum ] Function := Type id (\(ParamList\)\?) CompoundStmt ParamList := Type Identifier \(, Type Identifier\)\* Type := int \| float CompoundStmt := { \(DeclList\)? StmtList } StmtList := \(Stmt\)\* Stmt := OpenStmt \| ClosedStmt OpenStmt := IfStmt \| IfOpenElseStmt \| ForOpenStmt \| WhileOpenStmt ClosedStmt := AssignStmt \| CallStmt \| RetStmt \| SwitchStmt \| CompStmt \| IfClosedElseStmt \| ForClosedStmt \| WhileClosedStmt \| DoWhileStmt \| ; AssignStmt := Assign ; Assign := id = Expr \| id [ Expr ] = Expr CallStmt := Call ; Call := id ( \(ArgList\)\? ) RetStmt := return \(Expr\)\? ; WhileOpenStmt := while ( Expr ) OpenStmt WhileClosedStmt := whlie ( Expr ) ClosedStmt ForOpenStmt := for ( Expr ) OpenStmt ForOpenStmt := for ( Expr ) ClosedStmt IfStmt := if ( Expr ) Stmt IfOpenElseStmt := if ( Expr ) ClosedStmt else OpenStmt IfClosedElseStmt:= if ( Expr ) ClosedStmt else ClosedStmt SwitchStmt := switch ( Identifier ) { CaseList \(default : StmtList \(break ;\)\?\)\? } CaseList := \(case intnum : StmtList \(break ;\)\?\)\* Expr := unop Expr \| Expr binop Expr \| Call \| intnum \| floatnum \| id \| id [ Expr ] \| ( Expr ) ArgList := Expr \(, Expr\)\* *** I modified the condition and loop production rule for removing dangling else problem with loop *** I modified the switch case rule for representing the default case ######################## SEMANTIC CHECK ####################### - Warning (Type Conversion) - int to float : __int2float__ float to int : __float2int__ ########################## RESULT ########################### Production Rule : prod.txt C-style AST : tree.txt Symbol Table : table.txt Final result : out.T #####################################################################
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.