c.gbnf 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. root ::= (declaration)*
  2. declaration ::= dataType identifier "(" parameter? ")" "{" statement* "}"
  3. dataType ::= "int" ws | "float" ws | "char" ws
  4. identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
  5. parameter ::= dataType identifier
  6. statement ::=
  7. ( dataType identifier ws "=" ws expression ";" ) |
  8. ( identifier ws "=" ws expression ";" ) |
  9. ( identifier ws "(" argList? ")" ";" ) |
  10. ( "return" ws expression ";" ) |
  11. ( "while" "(" condition ")" "{" statement* "}" ) |
  12. ( "for" "(" forInit ";" ws condition ";" ws forUpdate ")" "{" statement* "}" ) |
  13. ( "if" "(" condition ")" "{" statement* "}" ("else" "{" statement* "}")? ) |
  14. ( singleLineComment ) |
  15. ( multiLineComment )
  16. forInit ::= dataType identifier ws "=" ws expression | identifier ws "=" ws expression
  17. forUpdate ::= identifier ws "=" ws expression
  18. condition ::= expression relationOperator expression
  19. relationOperator ::= ("<=" | "<" | "==" | "!=" | ">=" | ">")
  20. expression ::= term (("+" | "-") term)*
  21. term ::= factor(("*" | "/") factor)*
  22. factor ::= identifier | number | unaryTerm | funcCall | parenExpression
  23. unaryTerm ::= "-" factor
  24. funcCall ::= identifier "(" argList? ")"
  25. parenExpression ::= "(" ws expression ws ")"
  26. argList ::= expression ("," ws expression)*
  27. number ::= [0-9]+
  28. singleLineComment ::= "//" [^\n]* "\n"
  29. multiLineComment ::= "/*" ( [^*] | ("*" [^/]) )* "*/"
  30. ws ::= ([ \t\n]+)