SlideShare une entreprise Scribd logo
1  sur  18
Fortran66     Java Byte Code

          Art Wilton
        Kevin Chase
        Alekhya Dulur
What is a Compiler?
 A compiler is a program that translates a high level
  programming language (called source code ) into
  machine language (the target language).
 Machine language is a sequence of 0’s and 1’s that
  the machine (computer) understands and can
  interpret into instructions.
Translator:
                    English     German
        “Where is Fred?”       “Wo ist Freidrich?”


  Programming Language       Machine Code

                           0000000   05ea   c000   8c07   8ec8   8ed8   8ec0
name = raw_input(          0000010   befc   002d   20ac   74c0   b409   bb0e
'What is your name?n')    0000020   f2eb   c031   16cd   19cd   f0ea   00ff
print 'Hi, %s.' % name     0000030   6365   2074   6f62   746f   6e69   2067
                           0000040   6620   6f6c   7070   2079   7369   6e20
                           0000050   676e   7265   7320   7075   6f70   7472
Programing before Compilers:

Mostly:
 Tedious
 Error prone
 Mechanical


Computers do this better than humans.
Fortran Punch Card
FORTRAN 66 – Brief History

 Fortran is an acronym for Formula Translation.


 Developed by a team led by John Backus of IBM in the
  1950’s for scientific calculations.

 Before Fortran, programmers wrote machine language
  (0’s and 1’s).
C
    DO 30 J = 1, 98
    I = 100 - J
    WRITE (6,100) I, I
    WRITE (6,110)
    I=I-1
    IF (I .GE. 2) GO TO 20
    WRITE (6,125) I
    GO TO 30
20 WRITE (6,120) I
30 CONTINUE
    I=1                                                An Example
    WRITE (6,105) I, I
    WRITE (6,110)
                                                            Of
    WRITE (6,130)                                     Fortran Code:
    CALL EXIT
C                                                     99 Bottles of
100 FORMAT (1H0,I2,30H BOTTLES OF BEER ON THE WALL,
   1,I2,16H BOTTLES OF BEER)                               Beer
105 FORMAT (1H0,I2,29H BOTTLE OF BEER ON THE WALL,
   1,I2,15H BOTTLE OF BEER)
110 FORMAT (33H TAKE ONE DOWN AND PASS IT AROUND)
120 FORMAT (1H ,I2,17H BOTTLES OF BEER.)
125 FORMAT (1H ,I2,16H BOTTLE OF BEER.)
130 FORMAT (20H NO BOTTLES OF BEER.)
    END
The basic Structure of a Compiler:


Source                                        Machine
 Code                  IR
                                               Code
         FRONT END             BACK END
 Create a Symbol Table which holds information
 about each identifier -which the AST can access (will
 be explained later).


        Identifier      Type           Value

            x            int             8

           test         String      “Begin Test”

         allows        boolean         false
Intermediate Representation: Abstract Syntax Tree
Represents the source code in a tree form without the
details of syntax (grammar specific to a programming
                      language).
Each node in the tree represents a type of structure.




    (a+n ) * 1
 The Abstract Syntax Tree is designed to hold
 instructions for any type of language.

 The initial goal of our project was to create a
 compiler that could take any source code and
 translate it into general instructions for any type of
 language with the help of the Abstract Syntax Tree.
The FRONT END of a compiler:



                              Lexical Analysis


                          • Tokenizing
FRONT END


                             Semantic Analysis


                          • Parsing /Parse Tree
                          • Symbol Table
Tokenizing a Program:

         X = absVal(-7);

LEXEME                TOKEN TYPE
  x                        variable

  =                    Assignment

absVal                     function

  -7                       Integer

  ;                    Punctuation
 Lexical Analysis (scanner): the process of reading a
  program from left to right and grouping it into tokens.
  Tokens are groups of characters that represent a
  certain symbol in a program.
For example: The English language can be
represented as tokens, two of them being nouns and
adjectives.
                    “The tree is tall.”

              Lexeme               Token Type
                tree                  Noun
                tall                Adjective
Semantic Analysis:
             Does this have any meaning?
Detect errors in the source code language that would
not make it executable.

 “Tree tall the is.”
x=3+


…but not all errors

x=3÷0
We focused on specifying our compiler to
translate Fortran 66 code into modern Java Byte Code.
 Java Byte Code is not Java…



                                 Java :


        for (int i = 2; i < 1000; i++) {
                  for (int j = 2; j < i; j++) {
                             if (i % j == 0) continue outer;
                   }
                  System.out.println (i);
       }
Java Byte Code

0: iconst_2                    18: irem
1: istore_1                    19: ifne 25
2: iload_1                     22: goto 38
3: sipush 1000                 25: iinc 2, 1
6: if_icmpge 44                28: goto 11
9: iconst_2                    31: getstatic #84;
10: istore_2                   34: iload_1
11: iload_2                    35: invokevirtual #85;
12: iload_1                    38: iinc 1, 1
13: if_icmpge 31               41: goto 2
16: iload_1                    44: return
17: iload_2




 …it is the last step before machine language.

Contenu connexe

Tendances

Tendances (19)

Ejemplo completo de integración JLex y CUP
Ejemplo completo de integración JLex y CUPEjemplo completo de integración JLex y CUP
Ejemplo completo de integración JLex y CUP
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
Test2 Sum05
Test2 Sum05Test2 Sum05
Test2 Sum05
 
Bitwise Operations in Programming
Bitwise Operations in ProgrammingBitwise Operations in Programming
Bitwise Operations in Programming
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Fpga 05-verilog-programming
Fpga 05-verilog-programmingFpga 05-verilog-programming
Fpga 05-verilog-programming
 
Space Time Varying Color Palettes
Space Time Varying Color PalettesSpace Time Varying Color Palettes
Space Time Varying Color Palettes
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
null Pune meet - Application Security: Code injection
null Pune meet - Application Security: Code injectionnull Pune meet - Application Security: Code injection
null Pune meet - Application Security: Code injection
 
Shruti
ShrutiShruti
Shruti
 
First c program
First c programFirst c program
First c program
 
Concept of scoping in programming languages
Concept of scoping in programming languagesConcept of scoping in programming languages
Concept of scoping in programming languages
 
Listen afup 2010
Listen afup 2010Listen afup 2010
Listen afup 2010
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 

Similaire à Compiler

Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linuxAjin Abraham
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیSaman Chitsazian
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topicsveningstonk
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingVijaySharma802
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackironSource
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathDennis Chung
 
The Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's PerspectiveThe Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's Perspectivekfrdbs
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1Abdul Haseeb
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentOOO "Program Verification Systems"
 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsOMWOMA JACKSON
 

Similaire à Compiler (20)

Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسی
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Python basics
Python basicsPython basics
Python basics
 
The walking 0xDEAD
The walking 0xDEADThe walking 0xDEAD
The walking 0xDEAD
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
C tutorial
C tutorialC tutorial
C tutorial
 
python-ch2.pptx
python-ch2.pptxpython-ch2.pptx
python-ch2.pptx
 
C Language Unit-1
C Language Unit-1C Language Unit-1
C Language Unit-1
 
Chap 01[1]
Chap 01[1]Chap 01[1]
Chap 01[1]
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainath
 
The Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's PerspectiveThe Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's Perspective
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
 

Dernier

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Compiler

  • 1. Fortran66 Java Byte Code Art Wilton Kevin Chase Alekhya Dulur
  • 2. What is a Compiler?  A compiler is a program that translates a high level programming language (called source code ) into machine language (the target language).  Machine language is a sequence of 0’s and 1’s that the machine (computer) understands and can interpret into instructions.
  • 3. Translator: English German “Where is Fred?” “Wo ist Freidrich?” Programming Language Machine Code 0000000 05ea c000 8c07 8ec8 8ed8 8ec0 name = raw_input( 0000010 befc 002d 20ac 74c0 b409 bb0e 'What is your name?n') 0000020 f2eb c031 16cd 19cd f0ea 00ff print 'Hi, %s.' % name 0000030 6365 2074 6f62 746f 6e69 2067 0000040 6620 6f6c 7070 2079 7369 6e20 0000050 676e 7265 7320 7075 6f70 7472
  • 4. Programing before Compilers: Mostly:  Tedious  Error prone  Mechanical Computers do this better than humans.
  • 6. FORTRAN 66 – Brief History  Fortran is an acronym for Formula Translation.  Developed by a team led by John Backus of IBM in the 1950’s for scientific calculations.  Before Fortran, programmers wrote machine language (0’s and 1’s).
  • 7. C DO 30 J = 1, 98 I = 100 - J WRITE (6,100) I, I WRITE (6,110) I=I-1 IF (I .GE. 2) GO TO 20 WRITE (6,125) I GO TO 30 20 WRITE (6,120) I 30 CONTINUE I=1 An Example WRITE (6,105) I, I WRITE (6,110) Of WRITE (6,130) Fortran Code: CALL EXIT C 99 Bottles of 100 FORMAT (1H0,I2,30H BOTTLES OF BEER ON THE WALL, 1,I2,16H BOTTLES OF BEER) Beer 105 FORMAT (1H0,I2,29H BOTTLE OF BEER ON THE WALL, 1,I2,15H BOTTLE OF BEER) 110 FORMAT (33H TAKE ONE DOWN AND PASS IT AROUND) 120 FORMAT (1H ,I2,17H BOTTLES OF BEER.) 125 FORMAT (1H ,I2,16H BOTTLE OF BEER.) 130 FORMAT (20H NO BOTTLES OF BEER.) END
  • 8. The basic Structure of a Compiler: Source Machine Code IR Code FRONT END BACK END
  • 9.  Create a Symbol Table which holds information about each identifier -which the AST can access (will be explained later). Identifier Type Value x int 8 test String “Begin Test” allows boolean false
  • 10. Intermediate Representation: Abstract Syntax Tree Represents the source code in a tree form without the details of syntax (grammar specific to a programming language). Each node in the tree represents a type of structure. (a+n ) * 1
  • 11.  The Abstract Syntax Tree is designed to hold instructions for any type of language.  The initial goal of our project was to create a compiler that could take any source code and translate it into general instructions for any type of language with the help of the Abstract Syntax Tree.
  • 12. The FRONT END of a compiler: Lexical Analysis • Tokenizing FRONT END Semantic Analysis • Parsing /Parse Tree • Symbol Table
  • 13. Tokenizing a Program: X = absVal(-7); LEXEME TOKEN TYPE x variable = Assignment absVal function -7 Integer ; Punctuation
  • 14.  Lexical Analysis (scanner): the process of reading a program from left to right and grouping it into tokens. Tokens are groups of characters that represent a certain symbol in a program. For example: The English language can be represented as tokens, two of them being nouns and adjectives. “The tree is tall.” Lexeme Token Type tree Noun tall Adjective
  • 15. Semantic Analysis: Does this have any meaning? Detect errors in the source code language that would not make it executable.  “Tree tall the is.” x=3+ …but not all errors x=3÷0
  • 16. We focused on specifying our compiler to translate Fortran 66 code into modern Java Byte Code.
  • 17.  Java Byte Code is not Java… Java : for (int i = 2; i < 1000; i++) { for (int j = 2; j < i; j++) { if (i % j == 0) continue outer; } System.out.println (i); }
  • 18. Java Byte Code 0: iconst_2 18: irem 1: istore_1 19: ifne 25 2: iload_1 22: goto 38 3: sipush 1000 25: iinc 2, 1 6: if_icmpge 44 28: goto 11 9: iconst_2 31: getstatic #84; 10: istore_2 34: iload_1 11: iload_2 35: invokevirtual #85; 12: iload_1 38: iinc 1, 1 13: if_icmpge 31 41: goto 2 16: iload_1 44: return 17: iload_2 …it is the last step before machine language.