LangStudies/Notes.Lecture.1.txt

93 lines
1.2 KiB
Plaintext
Raw Normal View History

2022-07-06 03:03:11 -07:00
Following the first lecture of "Building a Parser from scratch"
By Dmitry Soshnikov.
Lecture 1:
Phases:
Data - Text Content
Processor - Tokenizer
Data - Tokens
Processor - Parser
Data - AST
Example of syntaxes :
S-Expression :
(class Point
(begin
(def constructor (self x y)
(begin
(set (prop self x) x)
(set (prop self y) y)
)
)
(def calc (self)
(+ (prop self x)
(prop self y)
)
)
)
)
(var p (new Point 10 20))
((prop p calc) p)
User Syntax :
class Point
{
def constructor( x, y )
{
this.x = x;
this.y = y;
}
def calc() {
return this.x + this.y;
}
}
let
p = new Point(10, 20);
p.calc();
Tokenizer - Lexial Analysis : Uses Regular Expressions (Optimal)
Parser - Syntactic Analysis : Uses Backus-Naur Form
Backus-Naur Example :
Program
: StatementList
;
StatementList
: BlockStatement
| IfStatement
| FunctionDeclaration
...
;
FunctionDeclaration
: def Identifier ( Arguments ) BlockStatement
;
Hand-written parsers :
Use recursive descent.
Automatically generated
All kinds of stuff...