Lecture 3 on compiler construction course on definition of lexical syntax and syntactic services that can be derived from syntax definitions such as formatting and syntactic completion
Declarative Syntax Definition - Grammars and TreesGuido Wachsmuth
Ā
This lecture lays the theoretic foundations for declarative syntax formalisms and syntax-based language processors, which we will discuss later in the course. We introduce the notions of formal languages, formal grammars, and syntax trees, starting from Chomsky's work on formal grammars as generative devices.
We start with a formal model of languages and investigate formal grammars and their derivation relations as finite models of infinite productivity. We further discuss several classes of formal grammars and their corresponding classes of formal languages. In a second step, we introduce the word problem, analyse its decidability and complexity for different classes of formal languages, and discuss consequences of this analysis on language processing. We conclude the lecture with a discussion about parse tree construction, abstract syntax trees, and ambiguities.
Slides for invited talk at Dynamic Languages Symposium (DLS'15) at SPLASH 2015 in Pittsburgh
http://2015.splashcon.org/event/dls2015-papers-declare-your-language
In the Language Designerās Workbench project we are extending the Spoofax Language Workbench with meta-languages to declaratively specify the syntax, name binding rules, type rules, and operational semantics of a programming language design such that a variety of artifacts including parsers, static analyzers, interpreters, and IDE editor services can be derived and properties can be verified automatically. In this presentation I will talk about declarative specification for two aspects of language design: syntax and name binding.
First, I discuss the idea of declarative syntax definition as supported by grammar formalisms based on generalized parsing using the SDF3 syntax definition formalism as example. With SDF3, the language designer defines syntax in terms of productions and declarative disambiguation rules. This requires understanding a language in term of (tree) structure instead of the operational implementation of parsers. As a result, syntax definitions can be used for a range of language processors including parsers, formatters, syntax coloring, outline view, syntactic completion.
Second, I discuss our recent work on the declarative specification of name binding rules, that takes inspiration from declarative syntax definition. The NaBL name binding language supports definition of name binding rules in terms of its fundamental concepts: declarations, references, scopes, and imports. I will present the theory of name resolution that we have recently developed to provide a semantics for name binding languages such as NaBL.
Declarative Syntax Definition - Grammars and TreesGuido Wachsmuth
Ā
This lecture lays the theoretic foundations for declarative syntax formalisms and syntax-based language processors, which we will discuss later in the course. We introduce the notions of formal languages, formal grammars, and syntax trees, starting from Chomsky's work on formal grammars as generative devices.
We start with a formal model of languages and investigate formal grammars and their derivation relations as finite models of infinite productivity. We further discuss several classes of formal grammars and their corresponding classes of formal languages. In a second step, we introduce the word problem, analyse its decidability and complexity for different classes of formal languages, and discuss consequences of this analysis on language processing. We conclude the lecture with a discussion about parse tree construction, abstract syntax trees, and ambiguities.
Slides for invited talk at Dynamic Languages Symposium (DLS'15) at SPLASH 2015 in Pittsburgh
http://2015.splashcon.org/event/dls2015-papers-declare-your-language
In the Language Designerās Workbench project we are extending the Spoofax Language Workbench with meta-languages to declaratively specify the syntax, name binding rules, type rules, and operational semantics of a programming language design such that a variety of artifacts including parsers, static analyzers, interpreters, and IDE editor services can be derived and properties can be verified automatically. In this presentation I will talk about declarative specification for two aspects of language design: syntax and name binding.
First, I discuss the idea of declarative syntax definition as supported by grammar formalisms based on generalized parsing using the SDF3 syntax definition formalism as example. With SDF3, the language designer defines syntax in terms of productions and declarative disambiguation rules. This requires understanding a language in term of (tree) structure instead of the operational implementation of parsers. As a result, syntax definitions can be used for a range of language processors including parsers, formatters, syntax coloring, outline view, syntactic completion.
Second, I discuss our recent work on the declarative specification of name binding rules, that takes inspiration from declarative syntax definition. The NaBL name binding language supports definition of name binding rules in terms of its fundamental concepts: declarations, references, scopes, and imports. I will present the theory of name resolution that we have recently developed to provide a semantics for name binding languages such as NaBL.
This talk covers a novel approach to "name binding" in syntax trees for programming languages that makes it much easier to write compilers and interpreters with a higher degree of assurance.
In this part of the course, meta languages for describing grammars are introduced. Bottom-up and top-down parsers are derivation steps are described. Finally, ambiguous grammars are defined.
Declarative Type System Specification with StatixEelco Visser
Ā
In this talk I present the design of Statix, a new constraint-based language for the executable specification of type systems. Statix specifications consist of predicates that define the well-formedness of language constructs in terms of built-in and user-defined constraints. Statix has a declarative semantics that defines whether a model satisfies a constraint. The operational semantics of Statix is defined as a sound constraint solving algorithm that searches for a solution for a constraint. The aim of the design is that Statix users can ignore the execution order of constraint solving and think in terms of the declarative semantics.
A distinctive feature of Statix is its use of scope graphs, a language parametric framework for the representation and querying of the name binding facts in programs. Since types depend on name resolution and name resolution may depend on types, it is typically not possible to construct the entire scope graph of a program before type constraint resolution. In (algorithmic) type system specifications this leads to explicit staging of the construction and querying of the type environment (class table, symbol table). Statix automatically stages the construction of the scope graph of a program such that queries are never executed when their answers may be affected by future scope graph extension. In the talk, I will explain the design of Statix by means of examples.
https://eelcovisser.org/post/309/declarative-type-system-specification-with-statix
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
Ā
Lecture introducing the need for static analysis in addition to parsing, the complications caused by names, and an introduction to name resolution with scope graphs
In the ever-evolving landscape of technology, enterprise software development is undergoing a significant transformation. Traditional coding methods are being challenged by innovative no-code solutions, which promise to streamline and democratize the software development process.
This shift is particularly impactful for enterprises, which require robust, scalable, and efficient software to manage their operations. In this article, we will explore the various facets of enterprise software development with no-code solutions, examining their benefits, challenges, and the future potential they hold.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Understanding Nidhi Software Pricing: A Quick Guide š
Choosing the right software is vital for Nidhi companies to streamline operations. Our latest presentation covers Nidhi software pricing, key factors, costs, and negotiation tips.
š What Youāll Learn:
Key factors influencing Nidhi software price
Understanding the true cost beyond the initial price
Tips for negotiating the best deal
Affordable and customizable pricing options with Vector Nidhi Software
š Learn more at: www.vectornidhisoftware.com/software-for-nidhi-company/
#NidhiSoftwarePrice #NidhiSoftware #VectorNidhi
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
Ā
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
šš Click Here To Get More Info šš
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
ā Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
ā Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
ā Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
ā Fully automated AI articles bulk generation!
ā Auto-post or schedule stunning AI content across all your accounts at onceāWordPress, Facebook, LinkedIn, Blogger, and more.
ā With one keyword or URL, generate complete websites, landing pages, and moreā¦
ā Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
ā Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
ā Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
ā Save over $5000 per year and kick out dependency on third parties completely!
ā Brand New App: Not available anywhere else!
ā Beginner-friendly!
ā ZERO upfront cost or any extra expenses
ā Risk-Free: 30-Day Money-Back Guarantee!
ā Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
Ā
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operateāor are planning to operateābroader deployments at their institution.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Ā
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. Itās here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
Ā
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Ā
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Ā
Looking for a reliable mobile app development company in Noida? Look no further than Drona Infotech. We specialize in creating customized apps for your business needs.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
AI Pilot Review: The Worldās First Virtual Assistant Marketing SuiteGoogle
Ā
AI Pilot Review: The Worldās First Virtual Assistant Marketing Suite
šš Click Here To Get More Info šš
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
ā Deploy AI expert bots in Any Niche With Just A Click
ā With one keyword, generate complete funnels, websites, landing pages, and more.
ā More than 85 AI features are included in the AI pilot.
ā No setup or configuration; use your voice (like Siri) to do whatever you want.
ā You Can Use AI Pilot To Create your version of AI Pilot And Charge People For Itā¦
ā ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
ā ZERO Limits On Features Or Usages
ā Use Our AI-powered Traffic To Get Hundreds Of Customers
ā No Complicated Setup: Get Up And Running In 2 Minutes
ā 99.99% Up-Time Guaranteed
ā 30 Days Money-Back Guarantee
ā ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Ā
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Ā
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Need for Speed: Removing speed bumps from your Symfony projects ā”ļøÅukasz ChruÅciel
Ā
No one wants their application to drag like a car stuck in the slow lane! Yet itās all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. Weāll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
3. Lexical syntax
- deļ¬ning the syntax of tokens / terminals including layout
- making lexical syntax explicit
Formatting speciļ¬cation
- how to map (abstract syntax) trees to text
Syntactic completion
- proposing valid syntactic completions in an editor
Grammar transformation
- disambiguation by transformation
Parsing
- interpreting a syntax deļ¬nition to map text to trees
This Lecture
3
5. 5
The SDF3 syntax definition
formalism is documented at
the metaborg.org website.
http://www.metaborg.org/en/latest/source/langdev/meta/lang/sdf3/index.html
6. 6
The inverse of parsing is unparsing or
pretty-printing or formatting, i.e.
mapping a tree representation of a
program to a textual representation. A
plain context-free grammar can be used
as specification of an unparser.
However, then it is unclear where the
whitespace should go.
This paper extends context-free
grammars with templates that provide
hints for layout of program text when
formatting.
https://doi.org/10.1145/2427048.2427056
7. 7
Syntax definitions cannot be used just
for parsing, but for many other
operations. This paper shows how
syntactic completion can be provided
generically given a syntax definition.
open access!
https://doi.org/10.1145/2427048.2427056
8. 8
Chapter 2: Lexical Analysis
Chapter 3: Parsing
Chapter 4: Abstract Syntax
Next week: LR Parsing
10. Context-Free Syntax vs Lexical Syntax
10
let function power(x: int, n: int): int =
if n <= 0 then 1
else x * power(x, n - 1)
in power(3, 10)
end
Mod(
Let(
[ FunDecs(
[ FunDec(
"power"
, [FArg("x", Tid("int")), FArg("n", Tid("int"))]
, Tid("int")
, If(
Leq(Var("n"), Int("0"))
, Int("1")
, Times(
Var("x")
, Call(
"power"
, [Var("x"), Minus(Var("n"), Int("1"))]
)
)
)
)
]
)
]
, [Call("power", [Int("3"), Int("10")])]
)
)
phrase structure
lexeme / token
separated by layout
structure not relevant
not separated by layout
11. Character Classes
11
lexical syntax // character codes
Character = [65]
Range = [65-90]
Union = [65-90] / [97-122]
Difference = [0-127] / [1013]
Union = [0-911-1214-255]
Character class represents choice from a set of characters
17. abc def ghi
Lexical Restriction => Longest Match
17
lexical syntax
Id = [a-zA-Z] [a-zA-Z0-9_]*
lexical restrictions
Id -/- [a-zA-Z0-9_] // longest match for identifiers
context-free syntax
Exp.Var = Id
Exp.Call = Exp Exp {left} // curried function call
Call(Call(Var("abc"), Var("def")), Var("ghi"))
Lexical restriction: phrase cannot be followed by character in character class
18. if def then ghi
Lexical Ambiguity: Keywords overlap with Identiļ¬ers
18
lexical syntax
Id = [a-zA-Z] [a-zA-Z0-9_]*
lexical restrictions
Id -/- [a-zA-Z0-9_] // longest match for identifiers
context-free syntax
Exp.Var = Id
Exp.Call = Exp Exp {left}
Exp.IfThen = "if" Exp "then" Exp
amb(
[ Mod(
Call(
Call(Call(Var("if"), Var("def")), Var("then"))
, Var("ghi")
)
)
, Mod(IfThen(Var("def"), Var("ghi")))
]
)
19. ifdef then ghi
Lexical Ambiguity: Keywords overlap with Identiļ¬ers
19
amb(
[ Mod(
Call(Call(Var("ifdef"), Var("then")), Var("ghi"))
)
, Mod(IfThen(Var("def"), Var("ghi")))
]
)
lexical syntax
Id = [a-zA-Z] [a-zA-Z0-9_]*
lexical restrictions
Id -/- [a-zA-Z0-9_] // longest match for identifiers
context-free syntax
Exp.Var = Id
Exp.Call = Exp Exp {left}
Exp.IfThen = "if" Exp "then" Exp
20. Reject Productions => Reserved Words
20
lexical syntax
Id = [a-zA-Z] [a-zA-Z0-9_]*
Id = āif" {reject}
Id = "then" {reject}
lexical restrictions
Id -/- [a-zA-Z0-9_] // longest match for identifiers
"if" "then" -/- [a-zA-Z0-9_]
context-free syntax
Exp.Var = Id
Exp.Call = Exp Exp {left}
Exp.IfThen = "if" Exp "then" Exp
if def then ghi IfThen(Var("def"), Var("ghi"))
21. ifdef then ghi
Reject Productions => Reserved Words
21
parse error
lexical syntax
Id = [a-zA-Z] [a-zA-Z0-9_]*
Id = āif" {reject}
Id = "then" {reject}
lexical restrictions
Id -/- [a-zA-Z0-9_] // longest match for identifiers
"if" "then" -/- [a-zA-Z0-9_]
context-free syntax
Exp.Var = Id
Exp.Call = Exp Exp {left}
Exp.IfThen = "if" Exp "then" Exp
30. Core language
- context-free grammar productions
- with constructors
- only character classes as terminals
- explicit deļ¬nition of layout
Desugaring
- express lexical syntax in terms of character classes
- explicate layout between context-free syntax symbols
- separate lexical and context-free syntax non-terminals
Explication of Lexical Syntax
30
34. Give an example syntax deļ¬nition that
demonstrates the need for separating lexical and
context-free syntax
Explain what goes wrong in the absence of that
separation
Exam Question
34
41. Generated Syntax Coloring
41
module libspoofax/color/default
imports
libspoofax/color/colors
colorer // Default, token-based highlighting
keyword : 127 0 85 bold
identifier : default
string : blue
number : darkgreen
var : 139 69 19 italic
operator : 0 0 128
layout : 63 127 95 italic
// compute the n-th fibonacci number
let function fib(n: int): int =
if n <= 1 then 1
else fib(n - 1) + fib(n - 2)
in fib(10)
end
42. Customized Syntax Coloring
42
module Tiger-Colorer
colorer
red = 255 0 0
green = 0 255 0
blue = 0 0 255
TUDlavender = 123 160 201
colorer token-based highlighting
keyword : red
Id : TUDlavender
StrConst : darkgreen
TypeId : blue
layout : green
// compute the n-th fibonacci number
let function fib(n: int): int =
if n <= 1 then 1
else fib(n - 1) + fib(n - 2)
in fib(10)
end
46. From ASTs to text
- insert keywords
- insert layout: spaces, line breaks, indentation
- insert parentheses to preserve tree structure
Unparser
- derive transformation rules from context-free grammar
- keywords, literals deļ¬ned in grammar productions
- parentheses determined by priority, associativity rules
- separate all symbols by a space => not pretty, or even readable
Pretty-printer
- introduce spaces, line breaks, and indentation to produce readable text
- doing that manually is tedious
Pretty-Printing
46
47. Specifying Formatting Layout with Templates
47
context-free syntax
Exp.Seq = <
(
<{Exp ";n"}*>
)
>
Exp.If = <
if <Exp> then
<Exp>
else
<Exp>
>
Exp.IfThen = <
if <Exp> then
<Exp>
>
Exp.While = <
while <Exp> do
<Exp>
>
Inverse quotation
- template quotes literal text with <>
- anti-quotations insert non-terminals with <>
Layout directives
- whitespace (linebreaks, indentation, spaces)
in template guides formatting
- is interpreted as LAYOUT? for parsing
Formatter generation
- generate rules for mapping AST to text (via
box expressions)
Applications
- code generation; pretty-printing generated
AST
- syntactic completions
- formatting
49. Templates for Tiger: Functions
49
context-free syntax
Dec.FunDecs = <<{FunDec "n"}+>> {longest-match}
FunDec.ProcDec = <
function <Id>(<{FArg ", "}*>) =
<Exp>
>
FunDec.FunDec = <
function <Id>(<{FArg ", "}*>) : <Type> =
<Exp>
>
FArg.FArg = <<Id> : <Type>>
Exp.Call = <<Id>(<{Exp ", "}*>)>
No space after function name in call
Space after comma!
Function declarations
separated by newline
Indent body
of function
50. Templates for Tiger: Bindings and Records
50
context-free syntax
Exp.Let = <
let
<{Dec "n"}*>
in
<{Exp ";n"}*>
end
>
context-free syntax // records
Type.RecordTy = <
{
<{Field ", n"}*>
}
>
Field.Field = <<Id> : <TypeId>>
Exp.NilExp = <nil>
Exp.Record = <<TypeId>{ <{InitField ", "}*> }>
InitField.InitField = <<Id> = <Exp>>
LValue.FieldVar = <<LValue>.<Id>>
Note spacing / layout in separators
59. Tiger Syntax: Comments
module Comments
lexical syntax // multiline comments
CommentChar = [*]
LAYOUT = "/*" InsideComment* "*/"
InsideComment = ~[*]
InsideComment = CommentChar
lexical restrictions
CommentChar -/- [/]
context-free restrictions
LAYOUT? -/- [/].[/]
lexical syntax // single line comments
LAYOUT = "//" ~[nr]* NewLineEOF
NewLineEOF = [nr]
NewLineEOF = EOF
EOF =
// end of file since it cannot be followed by any character
// avoids the need for a newline to close a single line comment
// at the last line of a file
lexical restrictions
EOF -/- ~[]
context-free restrictions
LAYOUT? -/- [/].[*]
63. Syntactic Completion
63
Amorim, Erdweg, Wachsmuth, Visser
Principled syntactic code completion using placeholders.
In ACM SIGPLAN International Conference on Software Language Engineering [SLE 2016].
64. 64
*S. Amann, S. Proksch, S. Nadi, and M. Mezini. A study
of visual studio usage in practice. In SANER, 2016.
109. Representation
- Standardized representation for <aspect> of programs
- Independent of speciļ¬c object language
Speciļ¬cation Formalism
- Language-speciļ¬c declarative rules
- Abstract from implementation concerns
Language-Independent Interpretation
- Formalism interpreted by language-independent algorithm
- Multiple interpretations for diļ¬erent purposes
- Reuse between implementations of diļ¬erent languages
Separation of Concerns in Declarative Language Deļ¬nition
109
110. Context-free grammars
- well-understood mathematical basis
- generation of valid sentences of language
- derivation corresponds to phrase structure
Character-level grammars
- terminals are characters
- lexical syntax deļ¬ned using same (CFG) formalism
Declarative disambiguation
- associativity and priority declarations for phrase structure ambiguities
- follow restrictions and reject productions for lexical disambiguation
- not discussed: layout constraints for modeling layout sensitive languages
Structure
- abstract syntax tree schema deļ¬ned in grammar using constructors
Formatting
- mapping from abstract syntax to text deļ¬ned using template production
Services
- automatically derived: coloring, formatting, completion
- to do: parsing
Declarative Syntax Deļ¬nition
110
111. Representation: (Abstract Syntax) Trees
- Standardized representation for structure of programs
- Basis for syntactic and semantic operations
Formalism: Syntax Deļ¬nition
- Productions + Constructors + Templates + Disambiguation
- Language-speciļ¬c rules: structure of each language construct
Language-Independent Interpretation
- Well-formedness of abstract syntax trees
ā£ provides declarative correctness criterion for parsing
- Parsing algorithm
ā£ No need to understand parsing algorithm
ā£ Debugging in terms of representation
- Formatting based on layout hints in grammar
- Syntactic completion
Declarative Syntax Deļ¬nition
111
A meta-
language for
talking about
syntax
}
112. Syntax of a Syntax
Deļ¬nition Formalism
112
Bootstrapping
115. Exam Question
115
Consider the following SDF3 syntax deļ¬nition and assume a standard deļ¬nition for identiļ¬ers ID:
context-free syntax
E.Var = ID
E.Add = E "+" E
E.App = E E
E.Fun = "" ID "." "{" E "}"
E = "(" E ")" {bracket}
(a) Demonstrate that this grammar is ambiguous by giving two diļ¬erent abstract syntax trees
using term notation based on the constructors in the grammar for the sentence f x + x and the
left-most derivations that give rise to these trees.
(b) Disambiguate the syntax deļ¬nition by means of priority and associativity declarations, i.e.
without (otherwise) changing the productions. Motivate your choice of disambiguation rules. Is
your disambiguation complete?
(c) Translate the disambiguated syntax deļ¬nition into an unambiguous one without separate
disambiguation rules. The syntax deļ¬nition should accept the same language and produce the
same abstract syntax trees.