Professional Documents
Culture Documents
Dušan Kolář
Lexical Analysis
Using flex and bison Possibilities
Token Description
flex/lex
Adding Functions
Read a Number
Build a Tree
Summary
References
Dušan Kolář
Faculty of Information Technology
Brno University of Technology
Small Interpreter.1
Small Interpreter
Aim of the Lecture
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
2 bison yacc/bison
Build a Tree
Summary
References
Small Interpreter.2
Small Interpreter
Contents
Dušan Kolář
1 Introduction
Possibilities Introduction
Lexical Analysis
Token Description Possibilities
Syntax Analysis
3 Syntax Analysis Syntax Constructs
Build a Tree
5 Adding Functions Add While Statement
Summary
6 Read a Number References
7 Build a Tree
9 Summary
Small Interpreter.3
Small Interpreter
Interpreter Structure
Dušan Kolář
Overview
Introduction
Analyses Lexical Analysis
Possibilities
• Semantic yacc/bison
Adding Functions
Read a Number
References
value, etc.
Small Interpreter.4
Small Interpreter
Our Language
Dušan Kolář
Introduction
• Ternary operator Lexical Analysis
• Variables Possibilities
Token Description
flex/lex
• Printing
Syntax Analysis
• Case insensitive Syntax Constructs
yacc/bison
Adding Functions
Read a Number
Build a Tree
Example
Add While Statement
Summary
LET a = 23*(5.6 + 256.8) References
Print a*2+6.1
LET b = a>5 ? 4.3 * a - 8.7 : a + 7.5
Small Interpreter.5
Small Interpreter
Possible Extensions
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Build a Tree
5 While statement addition
Add While Statement
Summary
References
Small Interpreter.6
Small Interpreter
Lexical Analyzer
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
How to implement: flex/lex
Syntax Analysis
• Direct implementation Syntax Constructs
yacc/bison
Adding Functions
• Lexer constructor
Read a Number
• Possibly other ways. . . Build a Tree
Summary
References
Small Interpreter.7
Small Interpreter
Lexical Elements
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
What to recognize? Token Description
flex/lex
Build a Tree
• Anything else is error, e.g. # Add While Statement
Summary
References
Small Interpreter.8
Small Interpreter
Lexical Element Description
Dušan Kolář
Identifier
Overview
It is a non-empty sequence of letters, numbers, and underscore
Introduction
symbol starting either with a letter or an underscore.
Lexical Analysis
Possibilities
Token Description
Regular expression flex/lex
Syntax Analysis
single occurrence of single one such a symbol Adding String for Print
Read a Number
set, e.g. a, bb, abc, . . .
Build a Tree
• Then [abc]* is possibly empty sequence of symbols Add While Statement
Small Interpreter.9
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Definition of a floating point number Token Description
flex/lex
Read a Number
• DIGITS plus exponent, e.g. 1e10, 2E-4 Build a Tree
• DIGITS dot DIGITS plus exponent, e.g. 1.2E+6, 7.1e-2 Add While Statement
Summary
References
Small Interpreter.10
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Integer Token Description
flex/lex
Syntax Analysis
• We can define a single DIGIT as [0-9] Syntax Constructs
yacc/bison
• Then an integer called DIGITS is {DIGIT}+ Adding String for Print
Adding Functions
Read a Number
Note: if we give a name to a regular expression, we should
Build a Tree
enclose it in curly braces for further use. Add While Statement
Summary
References
Small Interpreter.11
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Syntax Analysis
• Exact match of a string is a string, e.g. ”AM” Syntax Constructs
yacc/bison
• Let FLOAT1 is {DIGITS}"."{DIGITS} Adding String for Print
Adding Functions
Read a Number
Note: dot as such will represent any symbol except end of Build a Tree
line. Add While Statement
Summary
References
Small Interpreter.12
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Floating point number format 2 and 3 Possibilities
Token Description
Syntax Analysis
symbol in the set Syntax Constructs
yacc/bison
• Let EXP is [eE][-+]?{DIGITS} Adding String for Print
Build a Tree
References
Small Interpreter.13
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
White spaces and line end
Syntax Analysis
Syntax Constructs
Build a Tree
Summary
References
Small Interpreter.14
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Operators Token Description
flex/lex
• Single letter operators are simply a set [-+*/=<>?:()!] Adding String for Print
Adding Functions
• Two letter operators can be represented as a choice Read a Number
Summary
References
Small Interpreter.15
Small Interpreter
Lexical Element Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
• We will use dot for such a representation (as noted above) Adding Functions
Read a Number
Build a Tree
Summary
References
Small Interpreter.16
Small Interpreter
About generators
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
Syntax Analysis
• Regular expressions to define tokens/symbols Syntax Constructs
yacc/bison
• Always parse the longest/first definition (if several overlap) Adding String for Print
Adding Functions
Read a Number
• Manual should be studied for deep understanding. Build a Tree
Summary
References
Small Interpreter.17
Small Interpreter
Structure
Dušan Kolář
Overview
Introduction
Input text Lexical Analysis
Possibilities
Definitions of regular expressions Token Description
flex/lex
%%
Syntax Analysis
Definitions of tokens and actions Syntax Constructs
yacc/bison
%%
Adding String for Print
C code Adding Functions
Read a Number
Note Build a Tree
Using %{ and %} pair brackets we can insert C code into Add While Statement
Summary
regular expressions too, typically at the beginning, symbols
References
must be at the beginning of the line.
Small Interpreter.18
Small Interpreter
Demo
Dušan Kolář
Overview
Introduction
Lexical Analysis
Example of reg. exp. definitions Possibilities
Token Description
flex/lex
LETTER ([ a-zA-Z])
Syntax Analysis
DIGIT ([0-9]) Syntax Constructs
yacc/bison
DIGITS ({DIGIT}+)
Adding String for Print
EXP ([eE][-+]?{DIGITS})
Adding Functions
FLOAT1 ({DIGITS}"."{DIGITS}) Read a Number
FLOAT2 ({DIGITS}{EXP}) Build a Tree
FLOAT3 ({DIGITS}"."{DIGITS}{EXP}) Add While Statement
References
Small Interpreter.19
Small Interpreter
Demo
Dušan Kolář
Overview
Introduction
Lexical Analysis
Example of tokens and actions Possibilities
Token Description
Syntax Analysis
Syntax Constructs
{FLOAT} { yacc/bison
} Summary
References
Small Interpreter.20
Small Interpreter
Demo
Dušan Kolář
Overview
Introduction
Example of insert code
Lexical Analysis
Possibilities
%{ Token Description
Syntax Analysis
#include <string.h> Syntax Constructs
yacc/bison
%} References
Small Interpreter.21
Small Interpreter
Statements
Dušan Kolář
Overview
Introduction
Lexical Analysis
LET Possibilities
Token Description
It enables to assign a value of expression to the given variable. flex/lex
Syntax Analysis
Syntax Constructs
Sequence of yacc/bison
Adding Functions
2 Variable (variable name as an attribute) Read a Number
Small Interpreter.22
Small Interpreter
Statements
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
PRINT flex/lex
It prints to the standard output a value of the given expression. Syntax Analysis
Syntax Constructs
yacc/bison
Read a Number
2 expression Build a Tree
Summary
References
Small Interpreter.23
Small Interpreter
Statements
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
It seems like it is quite easy to recognize, as white spaces will Syntax Analysis
be skipped by lexical analyzer. Syntax Constructs
yacc/bison
Build a Tree
Summary
References
Small Interpreter.24
Small Interpreter
Expression Representation
Dušan Kolář
Overview
Introduction
There are many possible representations, some of them are Lexical Analysis
feasible. Possibilities
Token Description
Syntax Analysis
not simple to interpret Syntax Constructs
yacc/bison
• Stack code — e.g. Java Virtual Machine, similar to post-fix Adding String for Print
notation Adding Functions
Build a Tree
simple to create
Add While Statement
• Tree representation — no brackets, priorities solved, Summary
simple to traverse References
Small Interpreter.25
Small Interpreter
Tree Example 1 — 2*a
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
*
Syntax Analysis
Syntax Constructs
yacc/bison
Adding Functions
2 a Read a Number
Build a Tree
Summary
References
Small Interpreter.26
Small Interpreter
Tree Example 2 — b*(c+4)
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
* Syntax Analysis
Syntax Constructs
yacc/bison
Adding Functions
c 4
Read a Number
Build a Tree
Summary
References
Small Interpreter.27
Small Interpreter
Expression Description
Dušan Kolář
Overview
Introduction
Lexical Analysis
From such a representation a description of the expression can Possibilities
Token Description
be derived. flex/lex
Syntax Analysis
Definition Syntax Constructs
yacc/bison
A quadruple G = (N, T , P, S) is called context free grammar if Adding String for Print
N is a finite set of non-terminals, S is a starting non-terminal, Adding Functions
Summary
References
Small Interpreter.28
Small Interpreter
Generalization of Tree
Dušan Kolář
Overview
If we have an expression a ∗ (3 + b) and appropriate tree Introduction
representation: Lexical Analysis
Possibilities
Token Description
flex/lex
Syntax Analysis
Syntax Constructs
yacc/bison
Adding Functions
b + e + Read a Number
Build a Tree
c 4 e e Summary
References
Small Interpreter.29
Small Interpreter
Generalization of Tree
Dušan Kolář
Overview
Introduction
We can see that leaves are variables, constants, operators are Lexical Analysis
inner nodes. Tree structure denotes priority and associativity. Possibilities
Token Description
So we say flex/lex
a ∗ (3 + b) Syntax Analysis
Syntax Constructs
yacc/bison
is Adding String for Print
e ∗ (e + e) Adding Functions
Read a Number
where e is an expression.
Build a Tree
More general, there are two expressions:
Add While Statement
Summary
e∗e e+e References
Small Interpreter.30
Small Interpreter
Generalization of Tree
Dušan Kolář
Overview
Introduction
Lexical Analysis
Thus, the additive and multiplicative operations can be Possibilities
Summary
We can easily extend to other operations.
References
Small Interpreter.31
Small Interpreter
Priority and Associativity
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
On the grammar level, two clumsy to solve. flex/lex
Adding Functions
• Right — e.g. unary minus
Read a Number
• No associativity — e.g comparison greater than Build a Tree
Summary
References
Small Interpreter.32
Small Interpreter
Priority and Associativity
Dušan Kolář
Overview
Introduction
Lexical Analysis
Rules for associativity: Possibilities
Token Description
Syntax Analysis
• %right token name(s) Syntax Constructs
yacc/bison
Read a Number
Build a Tree
Priority is given by the order, the higher is the line number, the Add While Statement
higher is the priority. Summary
References
Small Interpreter.33
Small Interpreter
Our Language
Dušan Kolář
Overview
Introduction
Lexical Analysis
Operator priority and associativity Possibilities
Token Description
flex/lex
%left OR
Syntax Analysis
%left AND Syntax Constructs
yacc/bison
%nonassoc EQ NE
Adding String for Print
%nonassoc LE GE ’<’ ’>’ Adding Functions
%left ’+’ ’-’ Read a Number
%left ’*’ ’/’ Build a Tree
%right ’!’ Add While Statement
References
Small Interpreter.34
Small Interpreter
Priority Change
Dušan Kolář
Overview
Introduction
Lexical Analysis
Override priority and associativity like in bison Possibilities
Token Description
e →e+e flex/lex
Read a Number
e → +e %prec UNOP
Build a Tree
e → (e)
Add While Statement
e → VARIABLE Summary
e → CONSTANT References
Small Interpreter.35
Small Interpreter
Expression in yacc/bison Notation
Dušan Kolář
expr
: expr OR expr
Overview
| expr AND expr Introduction
| expr EQ expr Lexical Analysis
| expr NE expr Possibilities
Token Description
| expr LE expr flex/lex
Adding Functions
| expr ’+’ expr
Read a Number
| expr ’-’ expr
Build a Tree
| expr ’*’ expr Add While Statement
| expr ’/’ expr Summary
| ’!’ expr References
| ’+’ expr %prec UNOP
| ’-’ expr %prec UNOP
| ’(’ ternary ’)’
| FLOAT
| IDENT
Small Interpreter.36
Small Interpreter
Ternary Operator
Dušan Kolář
Overview
Introduction
Adding Functions
Grammar part: Read a Number
ternary Build a Tree
| expr Summary
References
;
Small Interpreter.37
Small Interpreter
Structure — Similar to lex/flex
Dušan Kolář
Overview
Introduction
Input text Lexical Analysis
Possibilities
Definitions of tokens and attributes Token Description
flex/lex
%%
Syntax Analysis
Definition of grammar Syntax Constructs
yacc/bison
%%
Adding String for Print
C code Adding Functions
Read a Number
Note Build a Tree
Using %{ and %} pair brackets we can insert C code into Add While Statement
Summary
regular expressions too, typically at the beginning, symbols
References
must be at the beginning of the line.
Small Interpreter.38
Small Interpreter
Tokens
Dušan Kolář
Overview
Introduction
%left OR Lexical Analysis
%left AND Possibilities
Token Description
%nonassoc EQ NE flex/lex
Build a Tree
Small Interpreter.39
Small Interpreter
Data Structure
Dušan Kolář
Overview
} u; Summary
} s; References
Small Interpreter.40
Small Interpreter
Remaining Part of the Grammar
Dušan Kolář
Overview
prog Introduction
: progelem Lexical Analysis
; flex/lex
Syntax Analysis
Syntax Constructs
progelem yacc/bison
Adding Functions
| ’\n’
Read a Number
;
Build a Tree
| PRINT ternary
;
Small Interpreter.41
Small Interpreter
Computation
Dušan Kolář
Overview
Introduction
Semantic action is the C code, which is performed when part of Token Description
flex/lex
Build a Tree
• Statement is parsed
Add While Statement
• Constant/Variable is recognized Summary
• Etc. References
Small Interpreter.42
Small Interpreter
Expression
Dušan Kolář
Introduction
| expr ’>’ expr
Lexical Analysis
{ Possibilities
} Read a Number
} Build a Tree
{ Summary
References
$1.u.vFloat += $3.u.vFloat;
$$ = $1;
}
Small Interpreter.43
Small Interpreter
Expression
Dušan Kolář
Overview
xfree($1.u.vStr); References
Small Interpreter.44
Small Interpreter
Statement
Dušan Kolář
Overview
Introduction
We add action to each statement: Lexical Analysis
statement Possibilities
Token Description
: LET IDENT ’=’ ternary flex/lex
{ Syntax Analysis
Syntax Constructs
insertModify($2.u.vStr,$4.u.vFloat); yacc/bison
} Adding Functions
Build a Tree
{
Add While Statement
printf("%g\n",$2.u.vFloat);
Summary
} References
;
Small Interpreter.45
Small Interpreter
Our Language
Dušan Kolář
Introduction
#include <stdio.h>
Lexical Analysis
#include <stdlib.h> Possibilities
Adding Functions
Summary
int yylex(void);
References
extern int yylineno;
FILE *fIn;
int yyerror(char *str);
%}
Small Interpreter.46
Small Interpreter
Our Language
Dušan Kolář
C code
int yyerror(char *str) {
Overview
prError(yylineno,"%s\n",str,NULL);
Introduction
return 1; Lexical Analysis
} Possibilities
Token Description
extern FILE *yyin; flex/lex
...... test arguments, open file ...... Adding String for Print
Build a Tree
fclose(fIn);
return 0;
} Small Interpreter.47
Small Interpreter
Building the Stuff
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Command line commands: Token Description
flex/lex
Read a Number
Build a Tree
Note: It is for Linux/BSD machines, for Windows, use proper Add While Statement
name of executable, e.g. x inter01.exe . Summary
References
Small Interpreter.48
Small Interpreter
Adding String for Print
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
Build a Tree
Summary
References
Small Interpreter.49
Small Interpreter
flex
Dušan Kolář
Overview
Regular expression
Introduction
Syntax Analysis
Definition of token and action Syntax Constructs
yacc/bison
{STRSTART} { Adding String for Print
yyStr(yylval) = readStr(); Adding Functions
yyFlag(yylval) = fSTR; Read a Number
Summary
References
Note: function reads the characters using input() until end of
string is reached od error occurs. It stores the string
dynamically (re)allocated buffer. It can be at the end of the file.
Small Interpreter.50
Small Interpreter
bison
Dušan Kolář
Token
Overview
%token <s> STR
Introduction
Lexical Analysis
Possibilities
Token Description
Statement extension by flex/lex
Syntax Analysis
| PRINT STR Syntax Constructs
{ yacc/bison
{ Summary
printf("%s%g\n",$2.u.vStr,$3.u.vFloat); References
xfree($2.u.vStr);
}
Small Interpreter.51
Small Interpreter
Build the Stuff
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Syntax Analysis
Syntax Constructs
Use commands from previous version, missing C code is in yacc/bison
Adding Functions
Read a Number
Build a Tree
Summary
References
Small Interpreter.52
Small Interpreter
Adding Functions and Operators
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
Build a Tree
Summary
References
Small Interpreter.53
Small Interpreter
flex
Dušan Kolář
LET, Summary
References
PRINT,
SIN,
TAN,
};
Small Interpreter.54
Small Interpreter
flex
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
Regular expression flex/lex
Syntax Analysis
OP1 ([-+*/=<>?:()!ˆ]) Syntax Constructs
yacc/bison
Adding Functions
Definition of token and action Read a Number
Summary
References
Small Interpreter.55
Small Interpreter
bison
Dušan Kolář
Overview
Token
Introduction
%term SIN COS TAN Lexical Analysis
Syntax Analysis
Syntax Constructs
yacc/bison
{ Build a Tree
Small Interpreter.56
Small Interpreter
bison
Dušan Kolář
{ Lexical Analysis
Possibilities
$$.flag = fFLOAT; Token Description
Syntax Analysis
} Syntax Constructs
{ References
$$.flag = fFLOAT;
$$.u.vFloat = tan($3.u.vFloat);
}
Small Interpreter.57
Small Interpreter
Building the Stuff
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
-o x inter03 -lm
Build a Tree
Summary
References
Small Interpreter.58
Small Interpreter
Adding Statement to Read a Number
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
Build a Tree
Summary
References
Small Interpreter.59
Small Interpreter
flex
Dušan Kolář
}; Read a Number
Introduction
{ Syntax Analysis
Syntax Constructs
double rval; yacc/bison
} Build a Tree
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Syntax Analysis
Syntax Constructs
Adding Functions
Read a Number
Build a Tree
Summary
References
Small Interpreter.62
Small Interpreter
Change from Direct to Indirect Interpretation
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
What to add? Token Description
flex/lex
Adding Functions
Build a Tree
Summary
References
Small Interpreter.63
Small Interpreter
A Type for Tree Structure
Dušan Kolář
Overview
Introduction
Statement extension by
Lexical Analysis
Syntax Analysis
unsigned lineno; Syntax Constructs
union { yacc/bison
Adding Functions
struct ast s *lft, *rgt;
Read a Number
} ptr;
Build a Tree
char *sVal; Add While Statement
double dVal; Summary
} u; References
} ast t;
Small Interpreter.64
Small Interpreter
Operations with the Tree
Dušan Kolář
Introduction
• ast t *mkSlf(unsigned tag, char *str); Lexical Analysis
creates leaf with string value and the given tag. Possibilities
Token Description
Syntax Analysis
creates leaf with double value and the given tag. Syntax Constructs
yacc/bison
• ast t*
Adding String for Print
mkNd(unsigned tag, ast t *l, ast t *r); Adding Functions
creates inner node with left and right sub-tree and the Read a Number
Summary
appR(unsigned tag, ast t *lst, ast t *nd);
References
appends node to the right (end) of the list of nodes.
• void evaluate(ast t *root);
evaluates the program.
Small Interpreter.65
Small Interpreter
Expression Evaluation Fragment
Dušan Kolář
Overview
Lexical Analysis
switch (tag(root)) { Possibilities
Token Description
case ’?’: flex/lex
} Read a Number
Small Interpreter.66
Small Interpreter
Statement Evaluation Fragment
Dušan Kolář
Lexical Analysis
case ’=’: Possibilities
} else { Summary
References
printf("%s%g\n", sv(left(root)),
expr(right(root)) );
}
break;
Small Interpreter.67
Small Interpreter
bison
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
Token flex/lex
Syntax Analysis
No need to modify. Syntax Constructs
yacc/bison
Adding Functions
Grammar Read a Number
Summary
References
Small Interpreter.68
Small Interpreter
bison
Dušan Kolář
Overview
Actions should be reworked Introduction
Build a Tree
double vFloat;
Add While Statement
char *vStr; Summary
struct ast s *ast; References
} u;
} s; }
Small Interpreter.69
Small Interpreter
bison
Dušan Kolář
{ Lexical Analysis
Possibilities
{ References
$$.flag = fAST;
$$.u.ast = mkNd(SIN,$3.u.ast,NULL);
}
Small Interpreter.70
Small Interpreter
bison
Dušan Kolář
Overview
Lexical Analysis
: LET IDENT ’=’ ternary Possibilities
{ Token Description
flex/lex
} Adding Functions
{ Build a Tree
Small Interpreter.71
Small Interpreter
Building the Stuff
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
astree.c -o x inter05 -lm
Build a Tree
Summary
References
Small Interpreter.72
Small Interpreter
Adding Statement for While Lopp
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Read a Number
Build a Tree
Summary
References
Small Interpreter.73
Small Interpreter
flex
Dušan Kolář
}; Read a Number
Overview
Introduction
Token Lexical Analysis
Possibilities
%term END WHILE Token Description
Syntax Analysis
Syntax Constructs
yacc/bison
{ Build a Tree
Small Interpreter.75
Small Interpreter
bison
Dušan Kolář
Overview
Introduction
Grammar change — add body 1
Lexical Analysis
Possibilities
body Token Description
{ Syntax Analysis
Syntax Constructs
Small Interpreter.76
Small Interpreter
bison
Dušan Kolář
Overview
Introduction
Grammar change — add body 2 Lexical Analysis
Possibilities
{ Build a Tree
} Summary
References
;
Small Interpreter.77
Small Interpreter
astree.c
Dušan Kolář
Overview
Introduction
static void proc(ast t *root) Lexical Analysis
Possibilities
} Summary
References
break;
Small Interpreter.78
Small Interpreter
Build the Stuff
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Syntax Analysis
Syntax Constructs
Adding Functions
Read a Number
Build a Tree
Summary
References
Small Interpreter.79
Small Interpreter
What We’ve Learned
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
1 Basic structure of interpreter flex/lex
Build a Tree
6 Hot to make not so simple interpreter Add While Statement
Summary
References
Small Interpreter.80
Small Interpreter
References
Dušan Kolář
Overview
Introduction
Lexical Analysis
Possibilities
Token Description
flex/lex
Syntax Analysis
Manual pages of bison, flex Syntax Constructs
yacc/bison
Aho, Sethi, Ullman: Compilers: Principles, Techniques, Adding String for Print
Read a Number
Build a Tree
Summary
References
Small Interpreter.81