0% found this document useful (0 votes)
147 views

BNF Grammar For C-Minus: ID Letter Letter NUM Digit Digit Letter A - .. - Z - A - .. - Z Digit 0 - .. - 9

This document provides a BNF grammar for C-Minus, defining the syntax rules for a C-Minus program. It specifies the allowed constructs for declarations, statements, expressions, and other elements. For example, it shows that a program consists of a declaration list, declarations can be variable or function declarations, statements include expression statements, selection statements like if/else, and iteration statements like while. Expressions are composed of variables, operators, and function calls.

Uploaded by

Ed Cornejo Mayta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

BNF Grammar For C-Minus: ID Letter Letter NUM Digit Digit Letter A - .. - Z - A - .. - Z Digit 0 - .. - 9

This document provides a BNF grammar for C-Minus, defining the syntax rules for a C-Minus program. It specifies the allowed constructs for declarations, statements, expressions, and other elements. For example, it shows that a program consists of a declaration list, declarations can be variable or function declarations, statements include expression statements, selection statements like if/else, and iteration statements like while. Expressions are composed of variables, operators, and function calls.

Uploaded by

Ed Cornejo Mayta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

BNF Grammar for C-Minus

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

Keywords: else if int return void while Special symbols: + - * / < <= > >= == != = ; , ( ) [ ] { } /* */ ID = letter letter* NUM = digit digit* letter = a | .. | z | A | .. | Z digit = 0 | .. | 9 Comments: /* ... */

You might also like