This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =begin | |
| %%{ | |
| machine simple_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| float = ('+'|'-')?[0-9]+'.'[0-9]+; | |
| assignment = '='; | |
| identifier = [a-zA-Z][a-zA-Z_]+; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine simple_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| float = ('+'|'-')?[0-9]+'.'[0-9]+; | |
| assignment = '='; | |
| identifier = [a-zA-Z][a-zA-Z_]+; | |
| main := |* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [{:name => :integer_literal, :value => "-101" }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| main := |* | |
| integer => { | |
| emit(:integer_literal, data, token_array, ts, te) | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def emit(token_name, data, target_array, ts, te) | |
| target_array << {:name => token_name.to_sym, :value => data[ts...te].pack("c*") } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| main := |* | |
| integer => { puts "Integer: " + data[ts..te].pack("c*") }; | |
| *|; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| main := |* | |
| integer => { puts "Integer" }; | |
| *|; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| main := |* | |
| integer; | |
| *|; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = ('+'|'-')?[0-9]+; | |
| }%% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def run_lexer(data) | |
| data = data.unpack("c*") if(data.is_a?(String)) | |
| eof = data.length | |
| token_array = [] | |
| %% write init; | |
| %% write exec; | |
| puts token_array.inspect | |
| end |