diff options
Diffstat (limited to 'chapter19')
| -rw-r--r-- | chapter19/README.ja.md | 2 | ||||
| -rw-r--r-- | chapter19/README.md | 2 | ||||
| -rw-r--r-- | chapter19/docs/18-grammar.ja.md | 138 | ||||
| -rw-r--r-- | chapter19/docs/18-grammar.md | 132 |
4 files changed, 4 insertions, 270 deletions
diff --git a/chapter19/README.ja.md b/chapter19/README.ja.md index f1de1079..5d33a73a 100644 --- a/chapter19/README.ja.md +++ b/chapter19/README.ja.md @@ -9,6 +9,8 @@ [linear](https://github.com/SeaOfNodes/Simple/tree/linear) ブランチ上の直線的な Git リビジョン履歴で [この章](https://github.com/SeaOfNodes/Simple/tree/linear-chapter19) を読み、前の章と [比較](https://github.com/SeaOfNodes/Simple/compare/linear-chapter18...linear-chapter19) することもできます。 +文法は[第18章](../chapter18/docs/18-grammar.ja.md)から変わりません。 + ## 命令選択、レジスタ割り当て、命令エンコーディングにまつわる全体的な問題と開発上の問題 命令選択の出力、すなわち理想化された Simple ノードからマシン固有のノードへの対応付けは、実行方法がないと大量にテストするのが困難です。命令選択、レジスタ割り当て、命令エンコーディングの3つすべてが完成するまでは、実行方法が得られません。そのため、エンコーディングの完成前後には、命令選択とレジスタ割り当てで多くのバグが見つかると予想しています。もちろん出力を手作業で調べて明らかな問題は修正しますが、実際にコードを動かせるようになるまで、多くのバグが残ります。 diff --git a/chapter19/README.md b/chapter19/README.md index e3d13b57..d8f7c9e1 100644 --- a/chapter19/README.md +++ b/chapter19/README.md @@ -8,6 +8,8 @@ English | [日本語](README.ja.md) You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter19) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter18...linear-chapter19) it to the previous chapter. +The grammar is unchanged from [Chapter 18](../chapter18/docs/18-grammar.md). + ## Meta-Issues / Code-Dev Issues of Instruction Selection, Register Allocation and Encodings The output of Instruction Selection - the mapping from idealized Simple Nodes diff --git a/chapter19/docs/18-grammar.ja.md b/chapter19/docs/18-grammar.ja.md deleted file mode 100644 index 0e944f06..00000000 --- a/chapter19/docs/18-grammar.ja.md +++ /dev/null @@ -1,138 +0,0 @@ -# 第19章の文法 - -[English](18-grammar.md) | 日本語 - -この文書は [原文](18-grammar.md) の日本語訳です。 - -> 訳注: 原文の見出しは「Grammar for Chapter 16」です。この日本語版では、配置されている第19章に合わせた見出しにしています。 - -[第19章に戻る](../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/chapter19/docs/18-grammar.md b/chapter19/docs/18-grammar.md deleted file mode 100644 index 51539d0b..00000000 --- a/chapter19/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]; -``` |
