The document discusses various techniques for syntax-directed translation including:
1. Using marker nonterminals to handle backpatching for if-then statements.
2. Replacing inherited attributes with synthesized lists to pass type information for declarations.
3. Generating abstract syntax trees from concrete syntax trees during translation to provide a more convenient intermediate representation.
Gentle Introduction to Functional ProgrammingSaurabh Singh
This slide is basically aimed at professionals and students to introduce them with functional programming.
I haven't used much functional programming terminologies because I personally feel they could be overwhelming to people getting introduced to FP for the first time. For similar reasons I have deliberately avoided using any functional programming language and kept the discussions programming language agnostic as far as possible.
Gentle Introduction to Functional ProgrammingSaurabh Singh
This slide is basically aimed at professionals and students to introduce them with functional programming.
I haven't used much functional programming terminologies because I personally feel they could be overwhelming to people getting introduced to FP for the first time. For similar reasons I have deliberately avoided using any functional programming language and kept the discussions programming language agnostic as far as possible.
First part of this presentation explains basics and advantages of using functional programming approaches with lambda calculus.
Second part of this presentation explains how can we use lambda calculus in C# 3.0
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
Explicit Formula for Riemann Prime Counting FunctionKannan Nambiar
Corresponding to every zeta function there is a delta series. We make use of this fact to derive an explicit formula for Riemann Prime Counting Function.
Monadic Comprehensions and Functional Composition with Query ExpressionsChris Eargle
Build monads using the C# language with a C# style, then use the appropriate methods to ensure the LINQ query syntax works with this functional design pattern. After describing monads, we will cut the middleman and apply the same techniques directly to objects and functions to achieve better results with a declarative syntax.
First part of this presentation explains basics and advantages of using functional programming approaches with lambda calculus.
Second part of this presentation explains how can we use lambda calculus in C# 3.0
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
Explicit Formula for Riemann Prime Counting FunctionKannan Nambiar
Corresponding to every zeta function there is a delta series. We make use of this fact to derive an explicit formula for Riemann Prime Counting Function.
Monadic Comprehensions and Functional Composition with Query ExpressionsChris Eargle
Build monads using the C# language with a C# style, then use the appropriate methods to ensure the LINQ query syntax works with this functional design pattern. After describing monads, we will cut the middleman and apply the same techniques directly to objects and functions to achieve better results with a declarative syntax.
This 7-second Brain Wave Ritual Attracts Money To You.!nirahealhty
Discover the power of a simple 7-second brain wave ritual that can attract wealth and abundance into your life. By tapping into specific brain frequencies, this technique helps you manifest financial success effortlessly. Ready to transform your financial future? Try this powerful ritual and start attracting money today!
1.Wireless Communication System_Wireless communication is a broad term that i...JeyaPerumal1
Wireless communication involves the transmission of information over a distance without the help of wires, cables or any other forms of electrical conductors.
Wireless communication is a broad term that incorporates all procedures and forms of connecting and communicating between two or more devices using a wireless signal through wireless communication technologies and devices.
Features of Wireless Communication
The evolution of wireless technology has brought many advancements with its effective features.
The transmitted distance can be anywhere between a few meters (for example, a television's remote control) and thousands of kilometers (for example, radio communication).
Wireless communication can be used for cellular telephony, wireless access to the internet, wireless home networking, and so on.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
Talk presented at Kubernetes Community Day, New York, May 2024.
Technical summary of Multi-Cluster Kubernetes Networking architectures with focus on 4 key topics.
1) Key patterns for Multi-cluster architectures
2) Architectural comparison of several OSS/ CNCF projects to address these patterns
3) Evolution trends for the APIs of these projects
4) Some design recommendations & guidelines for adopting/ deploying these solutions.
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
2. 2
Translation Schemes using
Marker Nonterminals
S if E M then S { backpatch(M.loc, pc-M.loc) }
M { emit(iconst_0); M.loc := pc; emit(if_icmpeq, 0) }
S if E { emit(iconst_0); push(pc); emit(if_icmpeq, 0) }
then S { backpatch(top(), pc-top()); pop() }
Need a stack!
(for nested if-then)
Synthesized attribute
(automatically stacked)
Insert marker nonterminal
3. 3
Translation Schemes using
Marker Nonterminals in Yacc
S : IF E M THEN S { backpatch($3, pc-$3); }
;
M : /* empty */ { emit(iconst_0);
$$ = pc;
emit3(if_icmpeq, 0);
}
;
…
4. 4
Replacing Inherited Attributes
with Synthesized Lists
D T L { for all id L.list : addtype(id.entry, T.type) }
T int { T.type := ‘integer’ }
T real { T.type := ‘real’ }
L L1 , id { L.list := L1.list + [id] }
L id { L.list := [id] }
D
T.type = ‘real’ L.list = [id1,id2,id3]
L.list = [id1,id2]
L.list = [id1] id2.entry
id1.entry
id3.entry
real
,
,
5. 5
Replacing Inherited Attributes
with Synthesized Lists in Yacc
%{
typedef struct List
{ Symbol *entry;
struct List *next;
} List;
%}
%union
{ int type;
List *list;
Symbol *sym;
}
%token <sym> ID
%type <list> L
%type <type> T
%%
D : T L { List *p;
for (p = $2; p; p = p->next)
addtype(p->entry, $1);
}
;
T : INT { $$ = TYPE_INT; }
| REAL { $$ = TYPE_REAL; }
;
L : L ‘,’ ID
{ $$ = malloc(sizeof(List));
$$->entry = $3;
$$->next = $1;
}
| ID { $$ = malloc(sizeof(List));
$$->entry = $1;
$$->next = NULL;
}
;
6. 6
Concrete and Abstract Syntax
Trees
• A parse tree is called a concrete syntax tree
• An abstract syntax tree (AST) is defined by
the compiler writer as a more convenient
intermediate representation
E
+
E T
id
id
id
*
Concrete syntax tree
+
*
id
id id
Abstract syntax tree
T T
8. 8
S-Attributed Definitions for
Generating Abstract Syntax Trees
Production
E E1 + T
E E1 - T
E T
T T1 * id
T T1 / id
T id
Semantic Rule
E.nptr := mknode(‘+’, E1.nptr, T.nptr)
E.nptr := mknode(‘-’, E1.nptr, T.nptr)
E.nptr := T.nptr
T.nptr := mknode(‘*’, T1.nptr, mkleaf(id, id.entry))
T.nptr := mknode(‘/’, T1.nptr, mkleaf(id, id.entry))
T.nptr := mkleaf(id, id.entry)
9. 9
Generating Abstract Syntax Trees
with Yacc
%{
typedef struct Node
{ int op; /* node op */
Symbol *entry; /* leaf */
struct Node *left, *right;
} Node;
%}
%union
{ Node *node;
Symbol *sym;
}
%token <sym> ID
%type <node> E T F
%%
E : E ‘+’ T { $$ = mknode(‘+’, $1, $3); }
| E ‘-’ T { $$ = mknode(‘-’, $1, $3); }
| T { $$ = $1; }
;
T : T ‘*’ F { $$ = mknode(‘*’, $1, $3); }
| T ‘/’ F { $$ = mknode(‘/’, $1, $3); }
| F { $$ = $1; }
;
F : ‘(’ E ‘)’ { $$ = $2; }
| ID { $$ = mkleaf($1); }
;
%%
10. 10
Eliminating Left Recursion from
a Translation Scheme
A A1 Y { A.a := g(A1.a, Y.y) }
A X { A.a := f(X.x) }
A X { R.i := f(X.x) } R { A.a := R.s }
R Y { R1.i := g(R.i, Y.y) } R1 { R.s := R1.s }
R { R.s := R.i }
11. 11
Eliminating Left Recursion from
a Translation Scheme (cont’d)
A.a = g(g(f(X.x), Y1.y), Y2.y)
Y2
Y1
X
A.a = g(f(X.x), Y1.y)
A.a = f(X.x)
12. 12
Eliminating Left Recursion from
a Translation Scheme (cont’d)
R3.i = g(g(f(X.x), Y1.y), Y2.y)
Y2
Y1
X
R2.i = g(f(X.x), Y1.y)
R1.i = f(X.x)
A
1. Flow of inherited
attribute values
13. 13
Eliminating Left Recursion from
a Translation Scheme (cont’d)
R3.s = R3.i = g(g(f(X.x), Y1.y), Y2.y)
Y2
Y1
X
R2.s = R3.s = g(g(f(X.x), Y1.y), Y2.y)
R1.s = R2.s = g(g(f(X.x), Y1.y), Y2.y)
A.s = R1.s = g(g(f(X.x), Y1.y), Y2.y)
2. Flow of synthesized
attribute values
14. 14
Generating Abstract Syntax Trees
with Predictive Parsers
E T { R.i := T.nptr } R { E.nptr := R.s }
R + T {R1.i := mknode(‘+’, R.i, T.nptr) } R1 { R.s := R1.s }
R - T {R1.i := mknode(‘-’, R.i, T.nptr) } R1 { R.s := R1.s }
R { R.s := R.i }
T id { T.nptr := mkleaf(id, id.entry) }
E E1 + T { E.nptr := mknode(‘+’, E1.nptr, T.nptr) }
E E1 - T { E.nptr := mknode(‘-’, E1.nptr, T.nptr) }
E T { E.nptr := T.nptr }
T id { T.nptr := mkleaf(id, id.entry) }
15. 15
Generating Abstract Syntax Trees
with Predictive Parsers (cont’d)
Node *R(Node *i)
{ Node *s, *i1;
if (lookahead == ‘+’)
{ match(‘+’);
s = T();
i1 = mknode(‘+’, i, s);
s = R(i1);
} else if (lookahead == ‘-’)
{ …
} else
s = i;
return s;
}