Compiling for Original language.
language statement.
if ( 10 == 1 + 9 ) {
10
}
Run.
require './lexer.rb'
require './parser.rb'
str = <<EOF
if ( 10 == 1 + 9 ) {
10
}
EOF
# lexer
lex = MyLexer.new(str).run
# parser
p MyParser.new(lex).run # => ["if", ["==", ["lit", 10], ["+", ["lit", 1], ["lit", 9]]], ["lit", 10]]
- Number literal
1
- String
"foo"
- Calculation
10 + 20 * 30 / 40
+, -, *, /, %
- if
if ( ... ) {
...
}
- multi line
10 + 20
if ( 100 = 100 ) {
"OK"
}
- else
- elseif
- for
- variable
- function
- and more... 😇
here ( Japanese ) -> 雰囲気でコンパイラを書いたら大変だった話 - Speaker Deck