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 /chapter12/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 'chapter12/docs')
| -rw-r--r-- | chapter12/docs/12-grammar.ja.md | 136 | ||||
| -rw-r--r-- | chapter12/docs/12-grammar.md | 2 |
2 files changed, 138 insertions, 0 deletions
diff --git a/chapter12/docs/12-grammar.ja.md b/chapter12/docs/12-grammar.ja.md new file mode 100644 index 00000000..afa19a08 --- /dev/null +++ b/chapter12/docs/12-grammar.ja.md @@ -0,0 +1,136 @@ +# 第12章の文法 + +[English](12-grammar.md) | 日本語 + +この文書は [原文](12-grammar.md) の日本語訳です。 + +[第12章に戻る](../README.ja.md) + +```antlrv4 +grammar SimpleLanguage; + +program + : statement+ EOF + ; + +statement + : returnStatement + | structDeclaration + | declStatement + | blockStatement + | expressionStatement + | ifStatement + | whileStatement + | breakStatement + | continueStatement + ; + +PRIMTYPE + : 'int' + ; + +field + : PRIMTYPE IDENTIFIER ';' + | structName ('?')? 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 + : PRIMTYPE 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 + : primaryExpression '.' IDENTIFIER + ; + +primaryExpression + : IDENTIFIER + | INTEGER_LITERAL + | 'true' + | 'false' + | 'null' + | newExpression + | '(' expression ')' + | fieldExpression + ; + +INTEGER_LITERAL + : [1-9][0-9]* + | [0] + ; + +IDENTIFIER + : NON_DIGIT (NON_DIGIT | DEC_DIGIT)* + ; + +NON_DIGIT: [a-zA-Z_]; +DEC_DIGIT: [0-9]; +``` diff --git a/chapter12/docs/12-grammar.md b/chapter12/docs/12-grammar.md index 24199ede..41a7e24e 100644 --- a/chapter12/docs/12-grammar.md +++ b/chapter12/docs/12-grammar.md @@ -1,5 +1,7 @@ # Grammar for Chapter 12 +English | [日本語](12-grammar.ja.md) + ```antlrv4 grammar SimpleLanguage; |
