Working through the https://interpreterbook.com/
- Lexer identifies tokens from text and categorizes them.
- We don't care if a number is 5, 10, 20 etc. we care that is it a nmber and identifies them as such.
- Token Type is a string so we can take advantage and classify anything as a stirng Identifiers, Ints, Commas (,)
- String is not the most peformant but it's the easiest to work with in the case of this book.
- We formally write out lexer here. We are takeing source input and --> outputting tokens that reperesen tthe source code.
- let x = 5 --> "LET", "IDENT", "EQUAL", "INT"
- We have a testing framework to test the final format of our langauge we are building to test it.
- Parsers take in input data (text) and create a data strucutre like a abstract syntax tree.
Javascript Example:
“> var input = '{"name": "Thorsten", "age": 28}';
> var output = JSON.parse(input);
> output
{ name: 'Thorsten', age: 28 }
> output.name
'Thorsten'
> output.age
28
>
Our”
Excerpt From
Writing An Interpreter In Go
Thorsten Ball
https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=0
This material may be protected by copyright.