コンパイラ

出典: フリー百科事典『ウィキペディア(Wikipedia)』

: compiler [1][2]

[]


Alfred V.Aho Compilers, Principles, Techniques, and Tools[ 1]11translate1[3]

"compile"[1] 

[4]

[5]""

[3]使FORTRAN使[ 2][3]

1en:Multi-pass compiler[3] #

使[6]

 / 2Java1Java

compile[7][8]compiler[9][10][11][12]

[]


1940EDSAC1940

1950

1952A-0 System1957IBMFORTRANFORTRAN

1960COBOL1



1962 Hart  Levin LISP[13]1970PascalCPascalCHart  Levin  LISP

[]




mnm×nmn1980GCCCOINSLLVM

OSOSOSPDA


[]




Pascal

2010







OpenMPFORTRAN DOALL 

Stage CompilerProlog[]Java  Python 

Java  Smalltalk 使JIT

[]


Microsoft Visual StudioF#/C# InteractiveJITJavaMicrosoft Visual BasicJITAOT

Common Lisp(Common Lisp)APLSNOBOL4eval

[]



[]


2

 - Ahead-Of-Time (AOT)

 - Just-In-Time (JIT)

[]


1970 PL/0 [14]PL/0 PL/0 Pascal1996OberonOberonOberon-0

(一)[]

(二)

(三)BNF

(四)P

(五)Ten:Tombstone diagram

[]


使[15][16]

[]


phase(s)[17] [18]

[17]
ソースプログラム(ソースコード字句解析器構文解析器セマンティック解析器中間コード生成器コード最適化器コード生成器ターゲットプログラム(オブジェクトコード)

[ 3]

lex[19][20]使使



 Production Quality Compiler-Compiler Project 使

22



OS

//CPUGNU Amsterdam Compiler KitLLVM 

[]


 IR

(一)(Line reconstruction) - 1960Atlas AutocodeEdinburgh IMPALGOL使%

(二) - 10365[21][22]lexical analyzer

(三) - 使[23]CLISP使

(四) - [24][25]

(五) - [22]

[]






(一) - 使UD

(二) - [26]

(三) - -





/IBMSGIGCCOpen64


簡単な例[編集]


C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define MODE_POSTFIX     0
#define MODE_ASSEMBLY    1

char    lookahead;
int     pos;
int     compile_mode;
char    expression[20+1];

void error()
{
        printf("Syntax error!\n");
}

void match( char t )
{
        if( lookahead == t )
        {
                pos++;
                lookahead = expression[pos];
        }
        else
                error();
}

void digit()
{
        switch( lookahead )
        {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                        if( compile_mode == MODE_POSTFIX )
                                printf("%c", lookahead);
                        else
                                printf("\tPUSH %c\n", lookahead);
                        
                        match( lookahead );
                        break;
                default:
                        error();
                        break;
        }
}

void term()
{
        digit();
        while(1)
        {
                switch( lookahead )
                {
                        case '*':
                                match('*');
                                digit();
                                
                                printf( "%s", compile_mode == MODE_POSTFIX ? "*"
                                        : "\tPOP B\n\tPOP A\n\tMUL A, B\n\tPUSH A\n");
                                
                                break;
                        case '/':
                                match('/');
                                digit();
                                
                                printf( "%s", compile_mode == MODE_POSTFIX ? "/"
                                        : "\tPOP B\n\tPOP A\n\tDIV A, B\n\tPUSH A\n");
                                break;
                        default:
                                return;
                }
        }
}

void expr()
{
        term();
        while(1)
        {
                switch( lookahead )
                {
                        case '+':
                                match('+');
                                term();

                                printf( "%s", compile_mode == MODE_POSTFIX ? "+"
                                        : "\tPOP B\n\tPOP A\n\tADD A, B\n\tPUSH A\n");
                                break;
                        case '-':
                                match('-');
                                term();

                                printf( "%s", compile_mode == MODE_POSTFIX ? "-"
                                        : "\tPOP B\n\tPOP A\n\tSUB A, B\n\tPUSH A\n");
                                break;
                        default:
                                return;
                }
        }
}

int main ( int argc, char** argv )
{
        printf("Please enter an infix-notated expression with single digits:\n\n\t");
        scanf("%20s", expression);
        
        printf("\nCompiling to postfix-notated expression:\n\n\t");
        compile_mode = MODE_POSTFIX;
        pos = 0;
        lookahead = *expression;
        expr();
        
        printf("\n\nCompiling to assembly-notated machine code:\n\n");
        compile_mode = MODE_ASSEMBLY;
        pos = 0;
        lookahead = *expression;
        expr();
        
        return 0;
}

この単純なコンパイラの実行例を以下に示す。

Please enter an infix-notated expression with single digits:

        3-4*2+2

Compiling to postfix-notated expression:

        342*-2+

Compiling to assembly-notated machine code:

        PUSH 3
        PUSH 4
        PUSH 2
        POP B
        POP A
        MUL A, B
        PUSH A
        POP B
        POP A
        SUB A, B
        PUSH A
        PUSH 2
        POP B
        POP A
        ADD A, B
        PUSH A

脚注[編集]

注釈[編集]

  1. ^ この本の表紙には赤いドラゴンの絵が描かれているのでドラゴンブックと呼ばれている。
  2. ^ オブジェクトコードの記述に使われる言語は、要は、その言語から最終的に機械語に翻訳する道筋が1筋(1本)でもあるものであればよい。理論上、機械語にたどり着くまでに途中で何種類もの言語にコンパイル(翻訳)する必要があっても、ともかく最終的に機械語に翻訳するまでの道筋が1本あれば良い。オブジェクトコードの記述に使われる言語は必ずしもアセンブリ言語や機械語でなくてもよい。たとえばC++で書かれたオブジェクトコードを出力するコンパイラやC言語で書かれたオブジェクトコードを出力するコンパイラもある。それぞれ、C++を機械語に、あるいはC言語を機械語に変換するコンパイラを別途用意すれば最終的にCPUが実行できる機械語に変換できる。よくあるのはアセンブリ言語で書かれたオブジェクトコードを出力するコンパイラである。アセンブリ言語で書かれたプログラムも通常そのままでは実行できないが、アセンブラを使ってやはりCPUが実行できる機械語に変換できる。
  3. ^ 最終的に出力されるターゲットプログラムは、機械語やアセンブリ言語で記述したものが多いが、それらに限るわけではなく、中間コードや高級言語のプログラムを出力するコンパイラもある。

出典[編集]



(一)^ abMerriam Webstertranslates an entire set of instructions[1] 

(二)^  - IT. IT e-Words. 2023222

(三)^ abcdAlfred V. Aho, Compilers, Principles, Techniques, and Tools. Reprinted with corrections March, 1988.Copyright 1986,Bell Telephone Laboratories, Incorporated, pp.1-2. Chapter 1.1 "COMPILERS" 

(四)^ ASCII.jp,,IT. (). . 2020426

(五)^ CPUGPU

(六)^ . www3.nit.ac.jp. 2020427

(七)^ compile

(八)^ Oxford Dictionary; Produce (a list or book) by assembling information collected from other sources 

(九)^ compiler

(十)^ 

(11)^ Oxford Dictionary; compiler: A person who produces a list or book by assembling information or written material collected from other sources.

(12)^ bit bit 199081582ISBN 4-320-02526-1 

(13)^ CSAIL Publications. publications.csail.mit.edu. 2020616

(14)^ https://www.246.dk/ (). 2020616

(15)^ 20204138. . . 2020427

(16)^ . nyumon-info.com. 2020427

(17)^ abAlfred V. Aho, Compilers, Principles, Techniques, and Tools. 1988., pp.10-15. 1.313 THE PHASES OF A COMPILER 

(18)^  | Shinta's Site. www.gadgety.net. 2020427

(19)^ :lex: UNIX/Linux. x68000.q-e-d.net. 2020427

(20)^  - Weblio. www.weblio.jp. 2020427

(21)^  (1/3). IT. 2020427

(22)^ ab . Nakata, Ikuo, 1935-, , , 1935-. Tōkyō: Asakurashoten. (2009). ISBN 978-4-254-12177-3. OCLC 675837876. https://www.worldcat.org/oclc/675837876 

(23)^  - IT. IT e-Words. 2020427

(24)^ . home.a00.itscom.net. 2020427

(25)^ VU - exp. - compiler-general. www.is.s.u-tokyo.ac.jp. 2020427

(26)^ MaryCore. . MaryCore . 2020427

[]


Compiler textbook references 

Compilers: Principles, Techniques and ToolsbyAlfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman (ISBN 0-201-10088-6)
 <1>1990ISBN 4781905854

 <2>1990ISBN 4781905862

Advanced Compiler Design and Implementation by Steven Muchnick (ISBN 1-55860-320-4).

 Engineering a Compiler by Keith D. Cooper and Linda Torczon . Morgan Kaufmann 2004, ISBN 1-55860-699-8.

Understanding and Writing Compilers: A Do It Yourself Guide (ISBN 0-333-21732-2) by Richard Bornat - PDF

An Overview of the Production Quality Compiler-Compiler Project by Leverett, Cattel, Hobbs, Newcomer, Reiner, Schatz and Wulf. Computer 13(8):38-49 (August 1980)

Compiler ConstructionbyNiklaus Wirth (ISBN 0-201-40353-6) Addison-Wesley 1996, 176 pages, PDFOberon-0

"Programming Language Pragmatics" by Michael Scott (ISBN 0-12-633951-1) Morgan Kaufmann 2005, 2nd edition, 912 pages. 

"A History of Language Processor Technology in IBM", by F.E. Allen, IBM Journal of Research and Development, v.25, no.5, September 1981.

ISBN 4-7952-9706-119971128

ISBN 978-4-254-12177-3(2)(1999915200911152)

A.V.M.S.R.J.D.[2]ISBN 978-4-7819-1229-52009525219901010

JavaCC for JavaISBN 4-924998-64-820031020

Andrew W. AppelISBN 978-4-7981-1468-2(20091029)

ISBN 978-4-254-12173-52008625

LLVM ISBN 978-4-8443-3415-62013621

  ISBN 978-4-274-22116-320171025

[]

外部リンク[編集]