Chapter 1 Introduction
How long have you been programming? Have you ever wondered what a programming language is?
There are many ways to answer this question, here I will try to answer this question from some different perspectives.
From formal language
A programming language is a formal language, so it is equipped with
1、alphabet
2、words and lexical grammar to defining the syntax of tokens.
3、Syntax and formal grammar to describe its syntax
From the perspectives of a compiler
How dose compiler understand what the program mean? The table is a summary of the implementation of compiler.
language | phase | grammar | technique | generator |
---|---|---|---|---|
alphabet | ||||
Lexical grammar | Lexical analysis | Regular expressions | Finite-state machine | Scanner generators, for example Lex (software) |
Syntax (programming languages) | Syntax analysis | Context-free grammar | Parse tree, Abstract syntax tree | Parser generators, for example Yacc |
Semantics (computer science) | Semantic analysis (compilers) |
Lexical grammar, syntax and semantics define a programming language,.Only when specifying lexical grammar, syntax and semantics can the compiler understand what programmer have written and translate the language correctly.
This book is about how to design and implement compilers. We shall discover that a few basic ideas can be used to construct translators for a wide variety of languages and machines. Besides compilers, the principles and techniques for compiler design are applicable to so many other domains that they are likely to be reused many times in the career of a computer scientist. The study of compiler writing touches up on programming languages, machine architecture, language theory, algorithms, and software engineering.