Advertisement
Guest User

Pencil Grammar

a guest
Mar 6th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BNF 1.83 KB | None | 0 0
  1. <program> ::= <declaration>*;
  2. <declaration> ::= <classDeclaration> | <funDeclaration> | <varDeclaration> | <statement>;
  3. <classDeclaration> ::= "class" <identifier> ( ":" <identifier> )? "{" <function>* "}" ;
  4. <funDeclaration> ::= "fun" <function>;
  5. <varDeclaration> ::= "let" <identifier> ("=" <expression>)? ("," <identifier> \1?)* ";";
  6. <function> ::= <identifier> "(" <parameters>? ")" <block>;
  7. <statement> ::= <expressionStmt> | <block>| <ifThenStatement> | <whileStatement> | <forStatement>;
  8. <ifThenStatement> ::= "if" "(" <expression> ")" <statement> ("else" <statement>)?;
  9. <whileStatement> ::= "while" "(" <expression> ")" <statement>;
  10. <forStatement> ::= "for" "(" (<varDeclaration> | <expressionStmt> | ";") <expression>? ";" <expression>? ")" <statement>;
  11. <block> ::= "{" <declaration>* "}";
  12. <expressionStmt> ::= <arguments> ";";
  13. <arguments> ::= <expression> ("," <expression>)* ;
  14. <expression> ::= <assignment>;
  15. <assignment> ::= <identifier> ("=" | "+=" | "-=" | "*=" | "/=") <expression> | <trinary> | <logicalOr>;
  16. <logicalOr> ::= <logicalAnd> ("or" <logicalAnd>)?;
  17. <logicalAnd> ::= <trinary> ("and" <trinary>)?;
  18. <trinary> ::= <equality> ("?" <trinary> ":" <trinary>)?;
  19. <equality> ::= <comparision> (("==" | "!=") <comparision>)*;
  20. <comparison> ::= <addition> ((">" | ">=" | "<" | "<=") <addition>)*;
  21. <addition> ::= <multiplication> (("+" | "-") <multiplication>)*;
  22. <multiplication> ::= <unary> (("+" | "-") <unary>)*;
  23. <unary> ::= ("!" | "-" | "+" | "typeof" | "++" | "--") <unary> | <postfix>;
  24. <postfix> ::= <call> ("++" | "--")?;
  25. <call> ::= <literal> ("(" arguments? ")" | "." <identifier>)*;
  26. <literal> ::= "(" <expression> ")" | <string> | <number> | "true" | "false" | "null" | <parameters>;
  27. <parameters> ::= <identifier> ("," <identifier>)* ;
  28. <identifier> ::= "@" \[A-z]\w\;
  29. <number> ::= \\d\*;
  30. <string> ::= (\[“’`]\) (\[^\1]\)* \1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement