Highlighted text? Practice this concept. Highlighted passages and figures open related questions.
Practice related questions (3)Progress & bookmarks
Current section
3-2 Language Processor
p. 217
Practice this section 3 linked exam questions with default filters
Progress
Not marked complete
Related questions in this lesson 3
Compiler optimization1Original BNF rules and derivation1Finite automata: input and internal state1Finite automaton transition diagram1p. 217
3 - 2 Language Processor
A language processor is software that translates programs that are written in a programming language (other than machine language) into a machine language or an intermediate language (a language between a machine language and a high-level language). Even though the program before translation and the program after translation can process the same work, their content differs and they are distinguished as described below.
p. 218
3-2-1 Types of Language Processors
(1) Assembler
An assembler is a language processor that translates a source program written in an assembly language into an object program. Translating with an assembler is called “assembling.”
(2) Compiler
A compiler is a language processor that translates a source program written in a high-level language into an object program. Translating with a compiler is called “compiling.” A high-level language that is translated by a compiler is called a compiler language. Typical examples include COBOL and C. Since instructions of high-level languages are translated into multiple machine languages, a dedicated compiler for each language is required.
(1) Lexical analysis A general programming language is defined with formal language based on context-free grammar. Therefore, the program is divided into units of character strings (i.e., tokens) with finite automaton or other method which is used to interpret regular expressions. In general programming languages, identifiers, constants, keywords,
p. 219
operators, and such other elements are divided as tokens.
p. 220
(2) Syntax analysis This interprets the token structure according to the grammar of the programming language, and generates a syntax tree. In context-free grammar, syntax is often defined with BNF notation or a syntax diagram, so this can be called an activity to confirm that the tokens in the program constitute the correct meaning.
p. 221
(3) Semantic analysis This analyzes a tree structure generated in syntax analysis for meaning in terms of a programming language, and generates an intermediate code. Semantic analysis includes interpretation of sections that cannot be analyzed with the grammar of the programming language alone (e.g., validity of variable names, calling of external functions). In the intermediate code, the quadruple format or reverse Polish notation is sometimes used to represent formulas.
p. 222
(5) Code generation This converts the optimized intermediate code into the target object code. Basically, the intermediate code is converted into machine language. However these days, it is temporarily converted to an intermediate code (e.g., byte code using Java byte code or CIL (Common Intermediate Language)), and then, upon execution, converted into an environment-dependent machine language.
Furthermore, depending on the intended use, the types of compilers below are available.
p. 223
(3) Interpreter
An interpreter is a language processor that translates and executes a source program written in a high-level language one instruction on an instruction-by-instruction basis. The differences between a compiler and an interpreter are as below.
(4) Generator
A generator is a language processor that generates object programs by providing parameters, such as input data/output data specifications and process conditions. Since it can generate an object program without the need to be aware of the processing procedure, it is sometimes referred to as a non-procedural language.
(5) Translator
In the case of a language processor, a translator is software that converts a program into a
p. 224
different programming language. A compiler or an assembler can be called a translator that converts (i.e., translates) a source program into an object program. This does not apply to interpreters.
Section progress
Original chapter exercises
Original chapter exercises →New FE Textbook Vol.1 · IT Fundamentals · First Edition, April 2015

![Original textbook callout or table. Source text: [Translation procedure of a compiler] (1) Lexical analysis This divides a source program which is a sequence of character strings in units of tokens. (2) Syntax analysis This analyzes the character strings according to the grammar of the programming language, and generates a syntax tree. (3) Semantic analysis This analyzes the meaning of a syntax tree and generates an intermediate code. (4) Optimization In order to increase processing efficiency upon execution and reduce execution time, this simplifies expressions in the intermediate code and modifies the structure. (5) Code generation This converts the intermediate code into an object code of the machine language (or an intermediate language).](/private-assets/fe-v1/ch03/language-processors/original-box-228-1-f972f8205697.webp)
![Original formal-language and regular-expression definitions, including [A-Z]*[0-9]+ and its literal explanation. State-transition table columns S0, S1, S2: alphabetic A-Z goes to S0,S2,S2; number 0-9 goes to S1,S1,S2. S0 is initial, S1 accepting. Diagram continues on the next page. Source text: • Context-free grammar This is a grammar that enables symbols to be replaced without relying on the preceding or subsequent context. For example, with context-free grammar, if “A” is defined as “xy” or “yz”, “xyz” can be replaced by either “Az” or “xA”. • Formal languages These are languages, such as programming languages, for which a strict grammar is defined. In contrast, the language that is used in everyday conversation is sometimes called natural language. • Regular expression This is a notation method that is used in the definition of a string format (i.e., pattern). [Example of notation in regular expression] [A-Z]*[0-9]+ [A-Z]: Represents a single alphabetical character [0-9]: Represents a single number *: Represents the repetition of zero or more times of the immediately preceding regular expression +: Represents the repetition of one or more times of the immediately preceding regular expression Note: In the strings defined in this example, after an alphabetical character is repeated zero or more times, a number is repeated one or more time. In other words, “AB1” and “123” are applicable, but “ABC” and “12A” are not applicable. • Finite automaton An automaton is a notation method that models the difference in processing of input depending on the internal state. A finite automaton is composed of a finite number of states and transitions, and is represented with a state transition table, a state transition diagram, or such other method. [Representation with a state transition table] S0 S1 S2 Alphabetical character (A - Z) S0 S2 S2 S0: Initial state Number (0 - 9) S1 S1 S2 S1: Accepting state [Representation with a state transition diagram]](/private-assets/fe-v1/ch03/language-processors/original-box-229-1-f405af4b3e3b.webp)

![Original BNF grammar, complete aligned derivation of +4-12*6, and syntax-diagram definition. All original operators, production symbols, underlines, alternatives, colors and derivation steps are preserved in the crop. Source text: • BNF (Backus Naur Form) notation This is a metalanguage (i.e., a language to define a language) that defines the grammar of a programming language or such other aspects. It is also used for the definition of XML, and so on. [Example of BNF notation] <expression> ::= <numeric value>|<expression><operator><numeric value> <numeric value> ::= <number>|<sign><number>|<numeric value><number> <operator> ::= <sign> | * | / <sign> ::= + | − <number> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Note: In this example, “+4−12*6” is interpreted as below. +4−12*6 → <code><number><sign><number><number><operator><number> → <numeric value><sign><numeric value><number><operator> <numeric value> → <numeric value><sign><numeric value><operator><numeric value> → <numeric value><operator><numeric value><operator><numeric value> → <expression><operator><numeric value><operator><numeric value> → <expression><operator><numeric value> → <expression> … interpreted as correct <expression> • Syntax diagram This is a diagram of a definition in BNF notation that is visually easy to understand.](/private-assets/fe-v1/ch03/language-processors/original-box-230-2-e4460b060638.webp)






