SlideShare una empresa de Scribd logo
1 de 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.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Similar a 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
 

Similar a 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
 

Último

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Último (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

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.