Re: Writing a language in Euphoria
- Posted by xecronix 1 week ago
- 170 views
A decent debugger and editor are top level goals for this project. But, like I said, I've not done this before so, I'm sort of winging it. This enum is how I visualize the main data container called TAstToken. (aka indexes in a sequence) I'm hoping it's enough info to build a proper debugger and reference original code. By making an AST tree, I hope I can walk the tree one node or leaf at a time and show the results of each command in a textbox or simulated console. stepping should be a matter moving to the next node or next leaf in the tree. I have 2 hopes at this point, 1 - I hope my plan works. And 2 - I hope that I came close to answering you question. :)
public enum __TYPE__, -- must be first value in enum _kind, -- this is a constant that represents resolvable, -- literal, or action. This turned out to be less -- valuable than I hoped. Targeted for deprecation. _name, -- the name of the data or symbol @x, [, -- or __BZ_STRING__ for example is a literal string. _line_num, -- line number of the original source code _col_num, -- column number of the original source code _value, -- for variables.. this is the value. for not -- variables I may or may not use the field for -- meta data about the token. _factory_request_str, -- the interpreter dispatchers actions to something I call -- Ants. This is data about which Ant to dispatch. _child_stream_location, -- Metadata about where children are located if the tokens were -- arraigned left to right in a row. For example consider 5 + 6 -- + will have _child_stream_location of "left_and_right" because -- both 5 and 6 are needed to give + meaning. _child_count, -- every token can have children. This is how many they have. _ast_tokens, -- the token's children __MYSIZE__ -- must be last value in enum
Here is what the tree looks like. (as flat as I can make it. most of the data is represented)
Input:
fun do_stuff(#x, $r, @t via TAstToken(@_arg[3])){ #x = #x*5; print($r); printf(`%s`, @t[#_factory_request_str]); } let @token; do_stuff(6, `me`, @token);
AST Output:
name: __ast_token_root__ line: 0 col: 0 value: factory_request_str: child_count: 4 name: fun line: 1 col: 1 value: __KEYWORD__ factory_request_str: fun child_count: 1 name: do_stuff line: 1 col: 5 value: __FUN_DEF__ factory_request_str: fun_def child_count: 1 name: ( line: 1 col: 13 value: __FUN_DEF_GROUP__ factory_request_str: node_open child_count: 3 name: #x line: 1 col: 14 value: factory_request_str: var_number child_count: 0 name: $r line: 1 col: 18 value: factory_request_str: var_string child_count: 0 name: via line: 1 col: 25 value: __KEYWORD__ factory_request_str: via child_count: 2 name: @t line: 1 col: 22 value: factory_request_str: var_sequence child_count: 0 name: TAstToken line: 1 col: 29 value: __FUN_CALL__ factory_request_str: fun_call child_count: 1 name: ( line: 1 col: 38 value: __FUN_CALL_GROUP__ factory_request_str: node_open child_count: 1 name: @_arg line: 1 col: 39 value: factory_request_str: var_sequence child_count: 1 name: [ line: 1 col: 44 value: factory_request_str: node_open child_count: 1 name: __BZ__NUMBER__ line: 1 col: 45 value: 3 factory_request_str: literal_num child_count: 0 name: { line: 1 col: 49 value: factory_request_str: block_open child_count: 3 name: = line: 2 col: 4 value: factory_request_str: assignment child_count: 2 name: #x line: 2 col: 1 value: factory_request_str: var_number child_count: 0 name: * line: 2 col: 8 value: factory_request_str: multiply child_count: 2 name: #x line: 2 col: 6 value: factory_request_str: var_number child_count: 0 name: __BZ__NUMBER__ line: 2 col: 9 value: 5 factory_request_str: literal_num child_count: 0 name: print line: 3 col: 1 value: __FUN_CALL__ factory_request_str: fun_call child_count: 1 name: ( line: 3 col: 6 value: __FUN_CALL_GROUP__ factory_request_str: node_open child_count: 1 name: $r line: 3 col: 7 value: factory_request_str: var_string child_count: 0 name: printf line: 4 col: 1 value: __FUN_CALL__ factory_request_str: fun_call child_count: 1 name: ( line: 4 col: 7 value: __FUN_CALL_GROUP__ factory_request_str: node_open child_count: 2 name: __BZ__STRING__ line: 4 col: 9 value: %s factory_request_str: literal_str child_count: 0 name: @t line: 4 col: 14 value: factory_request_str: var_sequence child_count: 1 name: [ line: 4 col: 16 value: factory_request_str: node_open child_count: 1 name: #_factory_request_str line: 4 col: 17 value: factory_request_str: var_number child_count: 0 name: let line: 6 col: 1 value: __KEYWORD__ factory_request_str: let child_count: 1 name: @token line: 6 col: 5 value: factory_request_str: var_sequence child_count: 0 name: do_stuff line: 7 col: 1 value: __FUN_CALL__ factory_request_str: fun_call child_count: 1 name: ( line: 7 col: 9 value: __FUN_CALL_GROUP__ factory_request_str: node_open child_count: 3 name: __BZ__NUMBER__ line: 7 col: 10 value: 6 factory_request_str: literal_num child_count: 0 name: __BZ__STRING__ line: 7 col: 14 value: me factory_request_str: literal_str child_count: 0 name: @token line: 7 col: 19 value: factory_request_str: var_sequence child_count: 0 Program finished Successfully. (Or at least it didn't crash. :) )