SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
??
BETTER UP FRONT
Generating Parsers in ANSI C
Peter T. Breuer
Depto. de Ingenier´ıa de Sistemas Telem´aticos
Universidad Polit´ecnica de Madrid
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 1
INTRODUCTON ??
PRECCX
Class: Compiler Compiler
alias Parser Generator
Friends:
yacc
bison
PCC
yacc++
Automate the production of front-ends by converting a language
specification to a parser/interpreter/compiler.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 2
INTRODUCTON Definition of Terms ??
A parser synthesises an attribute from a parse.
E.g. parse of “1 + 2” might synthesise the value 3.
A parser can inherit an attribute (from an earlier parse).
E.g. If the parser inherits the binding f := (+), then the parse of
“f(1,2)” might be expected to yield 3.
If the parser inherits the binding f := (∗), one might expect it to yield
2.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 3
INTRODUCTION PRECC History ??
1988-91 PRECC 1.* no inherited attributes, project REDO, boot-
strap term-rewrite engine/a Brief Editor macro.
1992 May PRECCX 2.01 first quiet public release with inherited at-
tributes as well as synthesised attributes.
1992 Jul PRECCX 2.23 language additions, lex compatibility, internal
improvements, released to MSDOS achive sites.
1993 Aug PRECCX 2.30 forward changes generate incompatibilities,
re-released to archive sites.
1994 Sep PRECCX 2.42 internal “monad model”, integrated treat-
ment of inherited and synthetic attributes. Re-released.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 4
INTRODUCTION PRECC Current ??
1995 PRECCX 2.43
Multi-platform support for compound data as synthetic attributes.
Type-safe.
Minor bug-fixes.
Re-entrant.
Free code, contracted maintenance.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 5
CONTENTS ??
1. Introduction
2. Middle
3. Conclusion
@ talk = Introduction
@ Middle
@ Conclusion
I like to recurse
@ Middle = {Introduction Middle Conclusion | Stuff}+
I like to backtrack
@ Stuff = Bit* EVERYBODY HAPPY | Default Stuff
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 6
MIDDLE Pros and cons v. yacc ??
pro: yacc implements a variety of BNF.
pro: yacc compiles to portable C. No support required.
pro: yacc implements well-understood theory. Reliable.
con: yacc BNF is very impoverished. PRECCX’s is full and extensible.
con: yacc is restricted to 1TLA. PRECCX is unbounded.
con: yacc handles ambiguity/context poorly. PRECCX does it well.
con: yacc 1TLA means approximate spex. PRECCX can be exact.
con: yacc output is a monolithic automaton. PRECCX’s is modular.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 7
MIDDLE Licensing ??
Code is free, but copyright.
Contract for maintenance (bug fixes, advice etc.).
About 100 commercial licences issued to corporations, but most don’t
bother (1% of downloads).
Distribution restrictions are that the package must be re-distributed
complete and for free.
Library code and generated code is excluded from distribution restric-
tions.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 8
MIDDLE Example - Fibonacci ??
My favorite example - a little parser that only accepts the Fibonacci
sequence 1,1,3,5,8,13,. . . as input.
MAIN(fibber)
@ fibber = { fibs $! }*
@ fibs = fib(1,1)k
@ {: printf("%d terms OKn",$k); :}
@ fib(a,b) = number(a) <’,’> fib(b,a+b)k
@ {@ k+1 @}
@ | <’.’> <’.’>
@ {: printf("Next terms are %d,%d,..n",a,b); :}
@ {@ 0 @}
@ number(n) = digit(n) | digit(HEAD(n)) number(TAIL(n))
@ digit(n) = <n+’0’>
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 9
MIDDLE Example - Fibonnaci input ??
1,1,2,3,5,..
Next terms are 8,13,..
5 terms OK
1,1,2,3,5,8,13,21,34,51,85,..
(line 2 error) failed parse:
probable error at <>1,85,..
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 10
MIDDLE Example - ideal palindromes ??
Palindromes are a classic example of a grammar that is difficult/impossible
to define with bounded lookahead.
“dabale arroz a la zorra el abad”
@ pallies = { palindrome $! }*
@ palindrome = ?x palindrome <$x>
@ | ?
@ | /* empty */
In practice, we will have to parse twice – once to count the letters and
again to see if it is a palindrome (PRECCX does not store enough
branch points to resolve the exact definition above).
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 11
MIDDLE Example - practical palindromes ??
I have to use a “macro” that parses the same input twice.
both(p, q) parses once using parser p, synthesizing attribute x, then
backtracks and parses once using parser q(x). q inherits x.
@ palindrome = both(getlen,pal)
@ pal(nc) = )nc==0( /* empty */
@ | )nc==1( ?x {: printf(”%c”,$x); :}
@ | )nc>=2( ?x {: printf(”%c”,$x); :}
@ pal(nc-2) <$x> {: printf(”%c”,$x); :}
@ getlen = line(0)
@ line(nc) = ? line(nc+1) | {@ nc @}
Got that?
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 12
MIDDLE Example - palindromes: Dirty Detail ??
@ both(p,q) = tmp {@ &tmp @}ptmp
@ ] px {@ *$ptmp=$x @} [
@ q(*$ptmp)
Don’t ask!
> dabale arroz a la zorra el abad
yow! !woy
> dabalearrozalazorraelabad
dabalearrozalazorraelabad is OK
>
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 13
MIDDLE Applications ??
The following is the list of languages known to me to have been
handled via PRECCX. There are many other existing applications.
• Cobol
• Uniform
• Oberon 2
• Occam
• RatFor
• Z
• PRECCX
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 14
CONCLUSION ??
This is the end. If you are not happy, we will have to backtrack and
start again in another way.
Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 15

Más contenido relacionado

Destacado (7)

Yacc
YaccYacc
Yacc
 
Lex
LexLex
Lex
 
Programming in Ansi C
Programming in Ansi CProgramming in Ansi C
Programming in Ansi C
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
 
Parsing example
Parsing exampleParsing example
Parsing example
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
 

Más de Peter Breuer

Avoiding Hardware Aliasing
Avoiding Hardware AliasingAvoiding Hardware Aliasing
Avoiding Hardware AliasingPeter Breuer
 
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)Peter Breuer
 
Certifying (RISC) Machine Code Safe from Aliasing (OpenCert 2013)
Certifying (RISC) Machine Code Safe from Aliasing  (OpenCert 2013)Certifying (RISC) Machine Code Safe from Aliasing  (OpenCert 2013)
Certifying (RISC) Machine Code Safe from Aliasing (OpenCert 2013)Peter Breuer
 
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Peter Breuer
 
A Semantic Model for VHDL-AMS (CHARME '97)
A Semantic Model for VHDL-AMS (CHARME '97)A Semantic Model for VHDL-AMS (CHARME '97)
A Semantic Model for VHDL-AMS (CHARME '97)Peter Breuer
 
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)Peter Breuer
 
Higher Order Applicative XML (Monterey 2002)
Higher Order Applicative XML (Monterey 2002)Higher Order Applicative XML (Monterey 2002)
Higher Order Applicative XML (Monterey 2002)Peter Breuer
 
Raiding the Noosphere
Raiding the NoosphereRaiding the Noosphere
Raiding the NoospherePeter Breuer
 
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...Peter Breuer
 
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...Peter Breuer
 
Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)Peter Breuer
 

Más de Peter Breuer (11)

Avoiding Hardware Aliasing
Avoiding Hardware AliasingAvoiding Hardware Aliasing
Avoiding Hardware Aliasing
 
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)
Empirical Patterns in Google Scholar Citation Counts (CyberPatterns 2014)
 
Certifying (RISC) Machine Code Safe from Aliasing (OpenCert 2013)
Certifying (RISC) Machine Code Safe from Aliasing  (OpenCert 2013)Certifying (RISC) Machine Code Safe from Aliasing  (OpenCert 2013)
Certifying (RISC) Machine Code Safe from Aliasing (OpenCert 2013)
 
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
 
A Semantic Model for VHDL-AMS (CHARME '97)
A Semantic Model for VHDL-AMS (CHARME '97)A Semantic Model for VHDL-AMS (CHARME '97)
A Semantic Model for VHDL-AMS (CHARME '97)
 
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)
The mixed-signal modelling language VHDL-AMS and its semantics (ICNACSA 1999)
 
Higher Order Applicative XML (Monterey 2002)
Higher Order Applicative XML (Monterey 2002)Higher Order Applicative XML (Monterey 2002)
Higher Order Applicative XML (Monterey 2002)
 
Raiding the Noosphere
Raiding the NoosphereRaiding the Noosphere
Raiding the Noosphere
 
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...
Abstract Interpretation meets model checking near the 1000000 LOC mark: Findi...
 
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...
Detecting Deadlock, Double-Free and Other Abuses in a Million Lines of Linux ...
 
Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)
 

Último

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Better up front: Generating parsers in ANSI C (FreeSoft '95)

  • 1. ?? BETTER UP FRONT Generating Parsers in ANSI C Peter T. Breuer Depto. de Ingenier´ıa de Sistemas Telem´aticos Universidad Polit´ecnica de Madrid Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 1
  • 2. INTRODUCTON ?? PRECCX Class: Compiler Compiler alias Parser Generator Friends: yacc bison PCC yacc++ Automate the production of front-ends by converting a language specification to a parser/interpreter/compiler. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 2
  • 3. INTRODUCTON Definition of Terms ?? A parser synthesises an attribute from a parse. E.g. parse of “1 + 2” might synthesise the value 3. A parser can inherit an attribute (from an earlier parse). E.g. If the parser inherits the binding f := (+), then the parse of “f(1,2)” might be expected to yield 3. If the parser inherits the binding f := (∗), one might expect it to yield 2. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 3
  • 4. INTRODUCTION PRECC History ?? 1988-91 PRECC 1.* no inherited attributes, project REDO, boot- strap term-rewrite engine/a Brief Editor macro. 1992 May PRECCX 2.01 first quiet public release with inherited at- tributes as well as synthesised attributes. 1992 Jul PRECCX 2.23 language additions, lex compatibility, internal improvements, released to MSDOS achive sites. 1993 Aug PRECCX 2.30 forward changes generate incompatibilities, re-released to archive sites. 1994 Sep PRECCX 2.42 internal “monad model”, integrated treat- ment of inherited and synthetic attributes. Re-released. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 4
  • 5. INTRODUCTION PRECC Current ?? 1995 PRECCX 2.43 Multi-platform support for compound data as synthetic attributes. Type-safe. Minor bug-fixes. Re-entrant. Free code, contracted maintenance. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 5
  • 6. CONTENTS ?? 1. Introduction 2. Middle 3. Conclusion @ talk = Introduction @ Middle @ Conclusion I like to recurse @ Middle = {Introduction Middle Conclusion | Stuff}+ I like to backtrack @ Stuff = Bit* EVERYBODY HAPPY | Default Stuff Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 6
  • 7. MIDDLE Pros and cons v. yacc ?? pro: yacc implements a variety of BNF. pro: yacc compiles to portable C. No support required. pro: yacc implements well-understood theory. Reliable. con: yacc BNF is very impoverished. PRECCX’s is full and extensible. con: yacc is restricted to 1TLA. PRECCX is unbounded. con: yacc handles ambiguity/context poorly. PRECCX does it well. con: yacc 1TLA means approximate spex. PRECCX can be exact. con: yacc output is a monolithic automaton. PRECCX’s is modular. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 7
  • 8. MIDDLE Licensing ?? Code is free, but copyright. Contract for maintenance (bug fixes, advice etc.). About 100 commercial licences issued to corporations, but most don’t bother (1% of downloads). Distribution restrictions are that the package must be re-distributed complete and for free. Library code and generated code is excluded from distribution restric- tions. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 8
  • 9. MIDDLE Example - Fibonacci ?? My favorite example - a little parser that only accepts the Fibonacci sequence 1,1,3,5,8,13,. . . as input. MAIN(fibber) @ fibber = { fibs $! }* @ fibs = fib(1,1)k @ {: printf("%d terms OKn",$k); :} @ fib(a,b) = number(a) <’,’> fib(b,a+b)k @ {@ k+1 @} @ | <’.’> <’.’> @ {: printf("Next terms are %d,%d,..n",a,b); :} @ {@ 0 @} @ number(n) = digit(n) | digit(HEAD(n)) number(TAIL(n)) @ digit(n) = <n+’0’> Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 9
  • 10. MIDDLE Example - Fibonnaci input ?? 1,1,2,3,5,.. Next terms are 8,13,.. 5 terms OK 1,1,2,3,5,8,13,21,34,51,85,.. (line 2 error) failed parse: probable error at <>1,85,.. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 10
  • 11. MIDDLE Example - ideal palindromes ?? Palindromes are a classic example of a grammar that is difficult/impossible to define with bounded lookahead. “dabale arroz a la zorra el abad” @ pallies = { palindrome $! }* @ palindrome = ?x palindrome <$x> @ | ? @ | /* empty */ In practice, we will have to parse twice – once to count the letters and again to see if it is a palindrome (PRECCX does not store enough branch points to resolve the exact definition above). Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 11
  • 12. MIDDLE Example - practical palindromes ?? I have to use a “macro” that parses the same input twice. both(p, q) parses once using parser p, synthesizing attribute x, then backtracks and parses once using parser q(x). q inherits x. @ palindrome = both(getlen,pal) @ pal(nc) = )nc==0( /* empty */ @ | )nc==1( ?x {: printf(”%c”,$x); :} @ | )nc>=2( ?x {: printf(”%c”,$x); :} @ pal(nc-2) <$x> {: printf(”%c”,$x); :} @ getlen = line(0) @ line(nc) = ? line(nc+1) | {@ nc @} Got that? Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 12
  • 13. MIDDLE Example - palindromes: Dirty Detail ?? @ both(p,q) = tmp {@ &tmp @}ptmp @ ] px {@ *$ptmp=$x @} [ @ q(*$ptmp) Don’t ask! > dabale arroz a la zorra el abad yow! !woy > dabalearrozalazorraelabad dabalearrozalazorraelabad is OK > Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 13
  • 14. MIDDLE Applications ?? The following is the list of languages known to me to have been handled via PRECCX. There are many other existing applications. • Cobol • Uniform • Oberon 2 • Occam • RatFor • Z • PRECCX Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 14
  • 15. CONCLUSION ?? This is the end. If you are not happy, we will have to backtrack and start again in another way. Univ. Carlos III, Madrid Free Software Workshop – 14-15 September 1995 15