BGBCC BAON - cr88192/bgbtech_shxemu GitHub Wiki

New AST Node serialization to replace use of XML.

Node:

  • { tag attr* }
  • { tag attr* child* }
Attr:
  • var=int
  • var=real
  • var='shortstring'
    • Shortstring is a string which may be interned.
  • var="longstring"
    • Longstring is a string which may be heap-allocated.
  • var=node
  • var= [node*]
Example:
  • x+y
    • {binary op='+' left={ref name='x'} right={ref name='y'}}
  • x*2
    • {binary op='*' left={ref name='x'} right={int value=2}}
Notes:
  • For binary nodes and similar, the left/right attributes are required to be nodes.
  • Possibly could allow literal values in some cases, TBD.
  • Many nodes may be expressed either as an attribute or as a node.
    • {binary op='*' left={ref name='x'} right={int value=2}}
    • {binary op='*' {left {ref name='x'}} {right {int value=2}}}
Expression or Statement Node Types:
  • { assign left right }
    • left=right;
  • { assign op left right }
    • left=(left op right);
  • { unary op value}
    • (op value)
  • { binary op left right }
    • (left op right)
  • { funcall name args }
    • name(args)
  • { defun name args body }
    • Define function.
  • { preinc name } | { postinc name } | { predec name } | { postdec name }
Statement Node:
  • { vars var* }
    • { var name type }
    • { var name type init }
    • { proto name type args }
  • { begin body* }
    • Block of statements.
Expression Node:
  • { ref name }
    • Variable referenced by name.
  • { int value }
    • Integer literal (32 or 64 bit).
  • { real value }
    • Floating point literal (float or double).
  • { string value }
    • String literal.
Init Expression Node:
  • { list expr* }
    • List of expressions (array or struct literal).
Structs Node:
  • { struct name body }
    • Struct definition (exists in structs list).
  • { union name body }
    • Struct definition (exists in structs list).
  • { enum name body }
    • Struct definition (exists in structs list).
Topelevel:
  • { module structs types body }
⚠️ **GitHub.com Fallback** ⚠️