diff options
Diffstat (limited to 'docs/chapter05/05-grammar.ja.md')
| -rw-r--r-- | docs/chapter05/05-grammar.ja.md | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/docs/chapter05/05-grammar.ja.md b/docs/chapter05/05-grammar.ja.md new file mode 100644 index 00000000..65b293f9 --- /dev/null +++ b/docs/chapter05/05-grammar.ja.md @@ -0,0 +1,86 @@ +# 第5章の文法 + +[English](05-grammar.md) | 日本語 + +この文書は [原文](05-grammar.md) の日本語訳です。 + + +[第5章に戻る](README.ja.md) + +```antlrv4 +grammar SimpleLanguage; + +program + : statement+ EOF + ; + +statement + : returnStatement + | declStatement + | blockStatment + | expressionStatement + | ifStatement + ; + +ifStatement + : 'if' '(' expression ')' statement ('else' statement)? + ; + + +expressionStatement + : IDENTIFIER '=' expression ';' + ; + +blockStatement + : '{' statement+ '}' + ; + +declStatement + : 'int' IDENTIFIER '=' expression ';' + ; + +returnStatement + : 'return' expression ';' + ; + +expression + : comparisonExpression + ; + +comparisonExpression + : additiveExpression (('==' | '!='| '>'| '<'| '>='| '<=') additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + ; + +multiplicativeExpression + : unaryExpression (('*' | '/') unaryExpression)* + ; + +unaryExpression + : ('-') unaryExpression + | primaryExpression + ; + +primaryExpression + : IDENTIFIER + | INTEGER_LITERAL + | 'true' + | 'false' + | '(' expression ')' + ; + +INTEGER_LITERAL + : [1-9][0-9]* + | [0] + ; + +IDENTIFIER + : NON_DIGIT (NON_DIGIT | DIGIT)* + ; + +NON_DIGIT: [a-zA-Z_]; +DEC_DIGIT: [0-9]; +``` |
