diff options
Diffstat (limited to 'chapter20')
| -rw-r--r-- | chapter20/README.ja.md | 2 | ||||
| -rw-r--r-- | chapter20/README.md | 2 | ||||
| -rw-r--r-- | chapter20/docs/18-grammar.ja.md | 138 | ||||
| -rw-r--r-- | chapter20/docs/18-grammar.md | 132 |
4 files changed, 4 insertions, 270 deletions
diff --git a/chapter20/README.ja.md b/chapter20/README.ja.md index c33630e2..550844ca 100644 --- a/chapter20/README.ja.md +++ b/chapter20/README.ja.md @@ -7,6 +7,8 @@ [前の章: 第19章](../chapter19/README.ja.md) | [次の章: 第21章](../chapter21/README.ja.md) +文法は[第18章](../chapter18/docs/18-grammar.ja.md)から変わりません。 + ## 参考資料 これは Briggs-Chaitin-Click 型の割り当て器であり、過去25年間にわたり大きな成功を収めてきた HotSpot の C2 割り当て器に非常によく似ています。 diff --git a/chapter20/README.md b/chapter20/README.md index b4d4209f..e11dcff2 100644 --- a/chapter20/README.md +++ b/chapter20/README.md @@ -5,6 +5,8 @@ English | [日本語](README.ja.md) [Previous: Chapter 19](../chapter19/README.md) | [Next: Chapter 21](../chapter21/README.md) +The grammar is unchanged from [Chapter 18](../chapter18/docs/18-grammar.md). + ## Some Reading Material This is a Briggs-Chaitin-Click allocator, and is very similar to the one used diff --git a/chapter20/docs/18-grammar.ja.md b/chapter20/docs/18-grammar.ja.md deleted file mode 100644 index f0b12acb..00000000 --- a/chapter20/docs/18-grammar.ja.md +++ /dev/null @@ -1,138 +0,0 @@ -# 第20章の文法 - -[English](18-grammar.md) | 日本語 - -この文書は [原文](18-grammar.md) の日本語訳です。 - -> 訳注: 原文の見出しは「Grammar for Chapter 16」です。この日本語版では、配置されている第20章に合わせた見出しにしています。 - -[第20章に戻る](../README.ja.md) - -```antlrv4 -grammar SimpleLanguage; - -program : block EOF ; - -block : statement+ ; - - -statement - : '{' block '}' - | returnStatement - | ifStatement - | whileStatement - | breakStatement - | continueStatement - | structDeclaration - | expressionStatement - ; - - -returnStatement : 'return' expression ';' ; - -ifStatement : 'if' '(' expression ')' statement ('else' statement)? ; - -whileStatement : 'while' '(' expression ')' statement ; - -breakStatement : 'break' ';' ; - -continueStatement : 'continue' ';' ; - - -structDeclaration : 'struct' IDENTIFIER '{' block '}' ; - -expressionStatement - : type IDENTIFIER ';' - | type IDENTIFIER '=' expression ';' - | IDENTIFIER '=' expression ';' - | expression - ; - -PRIMTYPE - : 'int' - | 'i8' - | 'i16' - | 'i32' - | 'i64' - | 'u8' - | 'u16' - | 'u32' - | 'flt' - | 'f32' - | 'f64' - | 'bool' - ; - -type - : PRIMTYPE - | typeName '?'? - | typeName nestedArray+ - ; - -nestedArray : '?'? '[]'* ; - -typeName : IDENTIFIER ; - - -expression : bitWiseExpression ; - -bitWiseExpression - : comparisonExpression ( '&' | '|' | '^' ) comparisonExpression)* - ; - -comparisonExpression - : shiftExpression (('==' | '!='| '>'| '<'| '>='| '<=') shiftExpression)* - ; - -shiftExpression - : additiveExpression ( '<<' | '>>>' | '>>' ) additiveExpression)* - ; - -additiveExpression - : multiplicativeExpression (('+' | '-') multiplicativeExpression)* - ; - -multiplicativeExpression - : unaryExpression (('*' | '/') unaryExpression)* - ; - -unaryExpression - : ('-') unaryExpression - | '!' unaryExpression - | primaryExpression postAssign - ; - -primaryExpression - : INTEGER_LITERAL - | FLOAT_LITERAL - | '(' expression ')' - | 'true' - | 'false' - | 'null' - | newExpression - | IDENTIFIER - ; - -newExpression - : 'new' IDENTIFIER [ '{' block '}' ] - | 'new' IDENTIFIER '[' expression ']' - ; - -postAssign : postFix [ '=' expression ] | [ '#' ]; - -postFix - : '.' IDENTIFIER postFix - | '[' expression ']' postFix - ; - - -IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ; - -INTEGER_LITERAL - : [1-9]DIGIT* - | [0] - ; - -NON_DIGIT: [a-zA-Z_]; -DIGIT: [0-9]; -``` diff --git a/chapter20/docs/18-grammar.md b/chapter20/docs/18-grammar.md deleted file mode 100644 index 51539d0b..00000000 --- a/chapter20/docs/18-grammar.md +++ /dev/null @@ -1,132 +0,0 @@ -# Grammar for Chapter 16 - -English | [日本語](18-grammar.ja.md) - -```antlrv4 -grammar SimpleLanguage; - -program : block EOF ; - -block : statement+ ; - - -statement - : '{' block '}' - | returnStatement - | ifStatement - | whileStatement - | breakStatement - | continueStatement - | structDeclaration - | expressionStatement - ; - - -returnStatement : 'return' expression ';' ; - -ifStatement : 'if' '(' expression ')' statement ('else' statement)? ; - -whileStatement : 'while' '(' expression ')' statement ; - -breakStatement : 'break' ';' ; - -continueStatement : 'continue' ';' ; - - -structDeclaration : 'struct' IDENTIFIER '{' block '}' ; - -expressionStatement - : type IDENTIFIER ';' - | type IDENTIFIER '=' expression ';' - | IDENTIFIER '=' expression ';' - | expression - ; - -PRIMTYPE - : 'int' - | 'i8' - | 'i16' - | 'i32' - | 'i64' - | 'u8' - | 'u16' - | 'u32' - | 'flt' - | 'f32' - | 'f64' - | 'bool' - ; - -type - : PRIMTYPE - | typeName '?'? - | typeName nestedArray+ - ; - -nestedArray : '?'? '[]'* ; - -typeName : IDENTIFIER ; - - -expression : bitWiseExpression ; - -bitWiseExpression - : comparisonExpression ( '&' | '|' | '^' ) comparisonExpression)* - ; - -comparisonExpression - : shiftExpression (('==' | '!='| '>'| '<'| '>='| '<=') shiftExpression)* - ; - -shiftExpression - : additiveExpression ( '<<' | '>>>' | '>>' ) additiveExpression)* - ; - -additiveExpression - : multiplicativeExpression (('+' | '-') multiplicativeExpression)* - ; - -multiplicativeExpression - : unaryExpression (('*' | '/') unaryExpression)* - ; - -unaryExpression - : ('-') unaryExpression - | '!' unaryExpression - | primaryExpression postAssign - ; - -primaryExpression - : INTEGER_LITERAL - | FLOAT_LITERAL - | '(' expression ')' - | 'true' - | 'false' - | 'null' - | newExpression - | IDENTIFIER - ; - -newExpression - : 'new' IDENTIFIER [ '{' block '}' ] - | 'new' IDENTIFIER '[' expression ']' - ; - -postAssign : postFix [ '=' expression ] | [ '#' ]; - -postFix - : '.' IDENTIFIER postFix - | '[' expression ']' postFix - ; - - -IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ; - -INTEGER_LITERAL - : [1-9]DIGIT* - | [0] - ; - -NON_DIGIT: [a-zA-Z_]; -DIGIT: [0-9]; -``` |
