Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 5.22 KB

our_syntax.md

File metadata and controls

65 lines (54 loc) · 5.22 KB

our syntax

  1. program $\rightarrow$ declaration-list
  2. declaration-list $\rightarrow$ declaration-list declaration | declaration
  3. declaration $\rightarrow$ var-declaration | fun-declaration
  4. var-declaration $\rightarrow$ base-type id-list ; | base-type ID array-post ; | base-type ID array-post = { array-const-list } ;
  5. id-list $\rightarrow$ id-list , ID | id-list , ID = expression | ID | ID = expression
  6. array-const-list $\rightarrow$ array-const-list , single | single
  7. base_type $\rightarrow$ int | double | float | char | bool
  8. fun-declaration $\rightarrow$ base-type ID ( params ) compound-stmt | void ID ( params ) compound-stmt | extern base-type ID ( params ) | extern void ID ( params )
  9. params $\rightarrow$ param-list | void
  10. param-list $\rightarrow$ param-list , param | param
  11. param $\rightarrow$ base-type ID | base-type ID array-post-param
  12. array-post-param $\rightarrow$ [ ] | [ NUM ] | array-post-param [ NUM ]
  13. compound-stmt $\rightarrow$ { local-declarations statement-list } | { local-declarations } | { statement-list } | { }
  14. local-declarations $\rightarrow$ local-declarations var-declaration | var-declaration
  15. statement-list $\rightarrow$ statement-list statement | statement
  16. statement $\rightarrow$ expression-stmt | compound-stmt | selection-stmt | iteration-stmt | return-stmt
  17. expression-stmt $\rightarrow$ expression ; | ;
  18. selection-stmt $\rightarrow$ if ( expression ) statement | if ( expression ) statement else statement
  19. iteration-stmt $\rightarrow$ while-stmt | for-stmt
  20. while-stmt $\rightarrow$ while ( expression ) statement
  21. for-stmt $\rightarrow$ for ( expression ; expression ; expression ) statement
  22. return-stmt $\rightarrow$ return ; | return expression ;
  23. expression $\rightarrow$ var assop expression | operand
  24. assop $\rightarrow$ = | += | -= | *= | /=| %=|^= | &= | |= | <<= | >>=
  25. ==var $\rightarrow$ ID | ID [ expression ]== 注意修改
  26. operand $\rightarrow$ operand || operand | operand && operand | operand | operand |operand ^ operand | operand & operand | operand = operand | operand != operand| operand < operand | operand > operand | operand <= operand | operand >= operand | operand << operand | operand >> operand | operand + operand | operand - operand | operand * operand | operand / operand | operand % operand | prefix ( operand ) | ( operand ) | prefix single | single
  27. prefix $\rightarrow$ ! | ~ | -
  28. single $\rightarrow$ var | call | NUM| DOUBLE | CHAR | TURE | FALSE
  29. call $\rightarrow$ ID ( args )
  30. args $\rightarrow$ arg-list | $\boldsymbol{\epsilon}$
  31. arg-list $\rightarrow$ arg-list , expression | expression

以下下均为注释: