diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-07 10:14:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-07 10:14:20 -0700 |
| commit | 8a20d5238855de5479d84e7fd8e84561844e2dc4 (patch) | |
| tree | bbeab7de6ac8b556911d117989ab4bbc0324ecb5 /chapter10/docs | |
| parent | 81b654d76444d747fdf1d053760e507b50f26e18 (diff) | |
| parent | b2862f980f3d78012066ef1cc09d4ad58f886c0f (diff) | |
| download | Simple-8a20d5238855de5479d84e7fd8e84561844e2dc4.tar.gz Simple-8a20d5238855de5479d84e7fd8e84561844e2dc4.zip | |
Merge pull request #262 from com-junkawasaki/docs/japanese-chapters
docs: add Japanese translations for all chapters
Diffstat (limited to 'chapter10/docs')
| -rw-r--r-- | chapter10/docs/10-grammar.ja.md | 131 | ||||
| -rw-r--r-- | chapter10/docs/10-grammar.md | 2 |
2 files changed, 133 insertions, 0 deletions
diff --git a/chapter10/docs/10-grammar.ja.md b/chapter10/docs/10-grammar.ja.md new file mode 100644 index 00000000..aac4be58 --- /dev/null +++ b/chapter10/docs/10-grammar.ja.md @@ -0,0 +1,131 @@ +# 第10章の文法 + +[English](10-grammar.md) | 日本語 + +この文書は [原文](10-grammar.md) の日本語訳です。 + +[第10章に戻る](../README.ja.md) + +```antlrv4 +grammar SimpleLanguage; + +program + : statement+ EOF + ; + +statement + : returnStatement + | structDeclaration + | declStatement + | blockStatment + | expressionStatement + | ifStatement + | whileStatement + | breakStatement + | continueStatment + ; + +field + : 'int' IDENTIFIER ';' + ; + +fields + : field+ + ; + +structDeclaration + : 'struct' IDENTIFIER '{' fields '}' + ; + +whileStatement + : 'while' '(' expression ')' statement + ; + +breakStatement + : 'break' ';' + ; + +continueStatement + : 'continue' ';' + ; + +ifStatement + : 'if' '(' expression ')' statement ('else' statement)? + ; + + +expressionStatement + : IDENTIFIER '=' expression ';' + | fieldExpression '=' expression ';' + ; + +blockStatement + : '{' statement+ '}' + ; + +structName + : IDENTIFIER + ; + +declStatement + : 'int' IDENTIFIER '=' expression ';' + | structName ('?')? IDENTIFIER '=' expression ';' + ; + +returnStatement + : 'return' expression ';' + ; + +expression + : comparisonExpression + ; + +comparisonExpression + : additiveExpression (('==' | '!='| '>'| '<'| '>='| '<=') additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + ; + +multiplicativeExpression + : unaryExpression (('*' | '/') unaryExpression)* + ; + +unaryExpression + : ('-') unaryExpression + | '!' unaryExpression + | primaryExpression + ; + +newExpression + : 'new' IDENTIFIER + ; + +fieldExpression + : primaryExpresson '.' IDENTIFIER + ; + +primaryExpression + : IDENTIFIER + | INTEGER_LITERAL + | 'true' + | 'false' + | 'null' + | newExpression + | '(' expression ')' + | fieldExpression + ; + +INTEGER_LITERAL + : [1-9][0-9]* + | [0] + ; + +IDENTIFIER + : NON_DIGIT (NON_DIGIT | DIGIT)* + ; + +NON_DIGIT: [a-zA-Z_]; +DEC_DIGIT: [0-9]; +``` diff --git a/chapter10/docs/10-grammar.md b/chapter10/docs/10-grammar.md index b76531d5..0c6fe7e0 100644 --- a/chapter10/docs/10-grammar.md +++ b/chapter10/docs/10-grammar.md @@ -1,5 +1,7 @@ # Grammar for Chapter 10 +English | [日本語](10-grammar.ja.md) + ```antlrv4 grammar SimpleLanguage; |
