Giter Site home page Giter Site logo

principles-of-compiler's Introduction

This is a C- Lexical and Syntax Analyzer which is the curriculum project of Principles of Complier.

Implemented C- Syntax Analyzer by using C++. Removed the left recursion of grammar first, made analysis through top-down and built an Abstract Syntax Tree coded from C-.

The code to implement it is in compiler file. The /report/2015141462312_赵文腾_《编译原理课程设计》课程报告.doc shows how to realize compiler syntax.

For lexical analyzer, here is the DFA. relation

For syntax analyzer, here is the BCNF grammar, 29 productions.

  1. program → declaration-list
  2. declaration-list → declaration-list declaration | declaration
  3. declaration → var-declaration | fun-declaration
  4. var-declaration → type-specifierID ; | type-specifierID [NUM];
  5. type-specifier→ int | void
  6. fun-declaration → type-specifierID (params)compound-stmt
  7. params→ param-list | void
  8. param-list→ param-list , param| param
  9. param→ type-specifierID | type-specifierID [ ]
  10. compound-stmt → { local-declarations statement-list }
  11. local-declarations → local-declarations var-declaration | empty
  12. statement-list → statement-list statement | empty
  13. statement → expression-stmt | compound-stmt| selection-stmt | iteration-stmt | return-stmt
  14. expression-stmt → expression ;| ;
  15. selection-stmt → if( expression ) statement | if ( expression ) statement else statement
  16. iteration-stmt → while( expression ) statement
  17. return-stmt → return ; | return expression ;
  18. expression → var = expression | simple-expression
  19. var → ID| ID[ expression ]
  20. simple-expression → additive-expression relop additive- expression | additive-expression
  21. relop → <= | < | > | >= | == | !=
  22. additive-expression → additive-expression addop term | term
  23. addop → + | -
  24. term → term mulop factor | factor 25. mulop → * | /
  25. factor → ( expression ) | var | call | NUM
  26. call → ID( args )
  27. args → arg-list | empty
  28. arg-list → arg-list , expression | expression

principles-of-compiler's People

Contributors

noneszzft avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.