SlideShare ist ein Scribd-Unternehmen logo
1 von 24
How to Write Language “Compiler”



Philip Zhong



© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   1
• Language Compilers

• JAVACC

• SQL Parser




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   2
• ANTLR
• YACC
• JAVACC




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   3
• Another Tool for Language Recognition
• Java/C++/C/C#/Python/Ruby/object C
• BSD




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   4
• Yet Another Compiler Compile

• C++/C for Unix

• BSD




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   5
• Java Compiler Compile

• Java

• BSD




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   6
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   7
"n"                                      newline
                 *                                         zero or more copies of the preceding expression
                 +                                         one or more copies of the preceding expression
                 ?                                         zero or one copy of the preceding expression
                 |                                         or
                 []                                        optional
                 ˜[]                                       matches any single character that is not in the empty set
                 ()                                        must appear
                 EOF                                       end of line
                 "a"-"z"                                   any letter, from a to z
                 "0" - "9"                                 any numeric


© 2011 Cisco and/or its affiliates. All rights reserved.                                                          Cisco Confidential   8
• Options

• Program header

• Tokens

• Production




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   9
options {
       JDK_VERSION = "1.6";
       IGNORE_CASE=true ;
       JAVA_UNICODE_ESCAPE = true;
       UNICODE_INPUT=true;
       DEBUG_PARSER=false ;
         STATIC = false;
}




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   10
PARSER_BEGIN(SqlParser)
package com.webex.wddl.engine.parser.sql;
public class SqlParser implements Parser
{
          final public void setStatement(String sqlStatement) {
          InputStream stream = new ByteArrayInputStream(sqlStatement.getBytes());
         ...
         public SqlParser()
          {
          }
}
PARSER_END(SqlParser)

© 2011 Cisco and/or its affiliates. All rights reserved.                 Cisco Confidential   11
• TOKEN: The regular expressions in this regular expression
       production describe tokens in the grammar.
• SPECIAL_TOKEN: The regular expressions in this regular
       expression production describe special tokens.
• SKIP: Matches to regular expressions in this regular expression
       production are simply skipped (ignored) by the token manager.
• MORE: Sometimes it is useful to gradually build up a token to be
       passed on to the parser. Matches to this kind of regular
       expression are stored in a buffer until the next TOKEN or
       SPECIAL_TOKEN match.




© 2011 Cisco and/or its affiliates. All rights reserved.           Cisco Confidential   12
TOKEN:
{
         <X_AND:"AND">
| <X_FROM:"FROM">
| <X_IN:"IN">
| <X_LIKE:"LIKE">
| <X_SELECT:"SELECT">
| <X_WHERE:"WHERE">
...
}

© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   13
SPECIAL_TOKEN:
{
       <LINE_COMMENT: "--"(~["r","n"])*>
| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])*
  "*"))* "/">
}




© 2011 Cisco and/or its affiliates. All rights reserved.        Cisco Confidential   14
SKIP:
{
         ""
| "t"
| "r"
| "n"
}




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   15
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   16
Statement parse(String SQL):
...
{
      ...
      (
          statement = insert()
          |
          statement = merge()
          ...
          |
        statement = select()
       )(<EOF>|";")
       ...
}

© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   17
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   18
• Define tokens

• Define parser tree classes

• Write parser logic

• Create parser classes




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   19
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   20
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   21
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   22
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   23
Thank you.




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   24

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (20)

Evaluation questions
Evaluation questionsEvaluation questions
Evaluation questions
 
Seventhside présentation version site english
Seventhside présentation version site englishSeventhside présentation version site english
Seventhside présentation version site english
 
Am 04 track1--salvatore orlando--openstack-apac-2012-final
Am 04 track1--salvatore orlando--openstack-apac-2012-finalAm 04 track1--salvatore orlando--openstack-apac-2012-final
Am 04 track1--salvatore orlando--openstack-apac-2012-final
 
04 03 wh_chris_walker
04 03 wh_chris_walker04 03 wh_chris_walker
04 03 wh_chris_walker
 
Comicus2012
Comicus2012Comicus2012
Comicus2012
 
Fm1(a) genre
Fm1(a)   genreFm1(a)   genre
Fm1(a) genre
 
Millenium Development Goals
Millenium Development GoalsMillenium Development Goals
Millenium Development Goals
 
Integrity research
Integrity researchIntegrity research
Integrity research
 
Tarea4
Tarea4Tarea4
Tarea4
 
My MSc. Project
My MSc. ProjectMy MSc. Project
My MSc. Project
 
Security protocols
Security protocolsSecurity protocols
Security protocols
 
Social media security
Social media securitySocial media security
Social media security
 
Pm 02 track1-- 魏刚--osac-trusted-computing-pools-in-folsom-v2
Pm 02 track1-- 魏刚--osac-trusted-computing-pools-in-folsom-v2Pm 02 track1-- 魏刚--osac-trusted-computing-pools-in-folsom-v2
Pm 02 track1-- 魏刚--osac-trusted-computing-pools-in-folsom-v2
 
slope and one point
slope and one pointslope and one point
slope and one point
 
Creative teams the hats ok
Creative teams   the hats okCreative teams   the hats ok
Creative teams the hats ok
 
Open Stack Cheng Du Swift Alex Yang
Open Stack Cheng Du Swift Alex YangOpen Stack Cheng Du Swift Alex Yang
Open Stack Cheng Du Swift Alex Yang
 
3interview1 ima
3interview1 ima3interview1 ima
3interview1 ima
 
Understanding the Icarus Flight of Flappy Bird
Understanding the Icarus Flight of Flappy Bird Understanding the Icarus Flight of Flappy Bird
Understanding the Icarus Flight of Flappy Bird
 
RemiDeVos_Research_Contribution
RemiDeVos_Research_ContributionRemiDeVos_Research_Contribution
RemiDeVos_Research_Contribution
 
KVH Whitepaper: Financial Extranets
KVH Whitepaper: Financial ExtranetsKVH Whitepaper: Financial Extranets
KVH Whitepaper: Financial Extranets
 

Ähnlich wie How to write_language_compiler

Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainTowards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainAttila Szegedi
 
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...Novell
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen oneAlexandre Moneger
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR mattersAlexandre Moneger
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Svein Fidjestøl
 
Unicode and Collations in MySQL 8.0
Unicode and Collations in MySQL 8.0Unicode and Collations in MySQL 8.0
Unicode and Collations in MySQL 8.0Bernt Marius Johnsen
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersAlexandre Moneger
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolMashaelQ
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)Alexandre Moneger
 
02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stackAlexandre Moneger
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPSVaclav Pech
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W mattersAlexandre Moneger
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra Sencha
 
MySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howMySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howBernt Marius Johnsen
 

Ähnlich wie How to write_language_compiler (20)

Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainTowards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages Toolchain
 
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07
 
Unicode and Collations in MySQL 8.0
Unicode and Collations in MySQL 8.0Unicode and Collations in MySQL 8.0
Unicode and Collations in MySQL 8.0
 
55j7
55j755j7
55j7
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
FPGA DESIGN FLOW.pdf
FPGA DESIGN FLOW.pdfFPGA DESIGN FLOW.pdf
FPGA DESIGN FLOW.pdf
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)
 
02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
fg.workshop: Software vulnerability
fg.workshop: Software vulnerabilityfg.workshop: Software vulnerability
fg.workshop: Software vulnerability
 
David-FPGA
David-FPGADavid-FPGA
David-FPGA
 
David-FPGA
David-FPGADavid-FPGA
David-FPGA
 
MySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howMySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & how
 
SIP Tutorial/Workshop 3
SIP Tutorial/Workshop 3SIP Tutorial/Workshop 3
SIP Tutorial/Workshop 3
 

Mehr von Philip Zhong

How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store Philip Zhong
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge ShareingPhilip Zhong
 
Adapter Poxy Pattern
Adapter Poxy PatternAdapter Poxy Pattern
Adapter Poxy PatternPhilip Zhong
 
How to estimate_oracle_cost
How to estimate_oracle_costHow to estimate_oracle_cost
How to estimate_oracle_costPhilip Zhong
 
Mongo db program_installation_guide
Mongo db program_installation_guideMongo db program_installation_guide
Mongo db program_installation_guidePhilip Zhong
 
Mongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guideMongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guidePhilip Zhong
 
Vitess percona 2012
Vitess percona 2012Vitess percona 2012
Vitess percona 2012Philip Zhong
 
Distributed_Database_System
Distributed_Database_SystemDistributed_Database_System
Distributed_Database_SystemPhilip Zhong
 
Mysql5.1 character set testing
Mysql5.1 character set testingMysql5.1 character set testing
Mysql5.1 character set testingPhilip Zhong
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Philip Zhong
 
Mysql handle socket
Mysql handle socketMysql handle socket
Mysql handle socketPhilip Zhong
 

Mehr von Philip Zhong (11)

How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge Shareing
 
Adapter Poxy Pattern
Adapter Poxy PatternAdapter Poxy Pattern
Adapter Poxy Pattern
 
How to estimate_oracle_cost
How to estimate_oracle_costHow to estimate_oracle_cost
How to estimate_oracle_cost
 
Mongo db program_installation_guide
Mongo db program_installation_guideMongo db program_installation_guide
Mongo db program_installation_guide
 
Mongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guideMongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guide
 
Vitess percona 2012
Vitess percona 2012Vitess percona 2012
Vitess percona 2012
 
Distributed_Database_System
Distributed_Database_SystemDistributed_Database_System
Distributed_Database_System
 
Mysql5.1 character set testing
Mysql5.1 character set testingMysql5.1 character set testing
Mysql5.1 character set testing
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
Mysql handle socket
Mysql handle socketMysql handle socket
Mysql handle socket
 

Kürzlich hochgeladen

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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
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 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
"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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"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 ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

How to write_language_compiler

  • 1. How to Write Language “Compiler” Philip Zhong © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 1
  • 2. • Language Compilers • JAVACC • SQL Parser © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
  • 3. • ANTLR • YACC • JAVACC © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
  • 4. • Another Tool for Language Recognition • Java/C++/C/C#/Python/Ruby/object C • BSD © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
  • 5. • Yet Another Compiler Compile • C++/C for Unix • BSD © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
  • 6. • Java Compiler Compile • Java • BSD © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
  • 7. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
  • 8. "n" newline * zero or more copies of the preceding expression + one or more copies of the preceding expression ? zero or one copy of the preceding expression | or [] optional ˜[] matches any single character that is not in the empty set () must appear EOF end of line "a"-"z" any letter, from a to z "0" - "9" any numeric © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
  • 9. • Options • Program header • Tokens • Production © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
  • 10. options { JDK_VERSION = "1.6"; IGNORE_CASE=true ; JAVA_UNICODE_ESCAPE = true; UNICODE_INPUT=true; DEBUG_PARSER=false ; STATIC = false; } © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
  • 11. PARSER_BEGIN(SqlParser) package com.webex.wddl.engine.parser.sql; public class SqlParser implements Parser { final public void setStatement(String sqlStatement) { InputStream stream = new ByteArrayInputStream(sqlStatement.getBytes()); ... public SqlParser() { } } PARSER_END(SqlParser) © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
  • 12. • TOKEN: The regular expressions in this regular expression production describe tokens in the grammar. • SPECIAL_TOKEN: The regular expressions in this regular expression production describe special tokens. • SKIP: Matches to regular expressions in this regular expression production are simply skipped (ignored) by the token manager. • MORE: Sometimes it is useful to gradually build up a token to be passed on to the parser. Matches to this kind of regular expression are stored in a buffer until the next TOKEN or SPECIAL_TOKEN match. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
  • 13. TOKEN: { <X_AND:"AND"> | <X_FROM:"FROM"> | <X_IN:"IN"> | <X_LIKE:"LIKE"> | <X_SELECT:"SELECT"> | <X_WHERE:"WHERE"> ... } © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
  • 14. SPECIAL_TOKEN: { <LINE_COMMENT: "--"(~["r","n"])*> | <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> } © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
  • 15. SKIP: { "" | "t" | "r" | "n" } © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
  • 16. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
  • 17. Statement parse(String SQL): ... { ... ( statement = insert() | statement = merge() ... | statement = select() )(<EOF>|";") ... } © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
  • 18. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
  • 19. • Define tokens • Define parser tree classes • Write parser logic • Create parser classes © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
  • 20. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
  • 21. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
  • 22. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 22
  • 23. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
  • 24. Thank you. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 24

Hinweis der Redaktion

  1. http://javacc.java.net/doc/javaccgrm.html#prod2STATIC: This is a boolean option whose default value is true. If true, all methods and class variables are specified as static in the generated parser and token manager. This allows only one parser object to be present, but it improves the performance of the parser. To perform multiple parses during one run of your Java program, you will have to call the ReInit() method to reinitialize your parser if it is static. If the parser is non-static, you may use the &quot;new&quot; operator to construct as many parsers as you wish. These can all be used simultaneously from different threads. DEBUG_PARSER: This is a boolean option whose default value is false. This option is used to obtain debugging information from the generated parser. Setting this option to true causes the parser to generate a trace of its actions. Tracing may be disabled by calling the method disable_tracing() in the generated parser class. Tracing may be subsequently enabled by calling the method enable_tracing() in the generated parser class. JAVA_UNICODE_ESCAPE: This is a boolean option whose default value is false. When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\\u...) before sending characters to the token manager. By default, Java Unicode escapes are not processed. This option is ignored if either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true. UNICODE_INPUT: This is a boolean option whose default value is false. When set to true, the generated parser uses uses an input stream object that reads Unicode files. By default, ASCII files are assumed. This option is ignored if either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true. IGNORE_CASE: This is a boolean option whose default value is false. Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files. This is useful for writing grammars for languages such as HTML. It is also possible to localize the effect of IGNORE_CASE by using an alternate mechanism described later.
  2. The token manager starts initially in the state &quot;DEFAULT“In the default mode (start of the program)