Skip to content

AST2MIPS interface

Ben Shen edited this page Jun 19, 2019 · 20 revisions

guideline for the result field

  1. C Statement should only use mp() without argument.

  2. C expression should only use mp(Result& result).

  3. In expression, both id and freeable are always used

  4. When handling type, only type field is used

  5. Type is only passed in AST during delcartion, it should stay within the Mp class

  6. In general result field is used as return field from leaf nodes.

  7. mp(Result& result) hint is used as output, mp(Result& para) hint is used as intput

Below are classes with sepcial case:

  • whenever mention id, it also implies id AND bool freeable field are used.
class name input output remark
declaration type not sure why return type (declaration_specifiers ';')
init_declarator type
declarator basic_type type, identifier, (size vector if is array)
direct_declarator basic_type type, identifier, (size vector if is array) return VOID to indicate is function declaration
primary_expression type id, type, str May receive TYPE_VOID, in such case return str for IDENTIFIER (func name), reutrn constant through id for conditional_expression
conditional_expression use id field for compile time constant passdown TYPE_VOID to conditional_expression to indicate it's run time expression

remark

parameter_type_list is treaded as statement, i.e. use mp()

Benefit

Because of 1,2 statement like below will produce node in AST, but will not be evaluated nor produce any output (expect warnings). Because the statement uses mp() method, will not invoke mp(Result& result) method.

{
   1+5<<2;
}
Clone this wiki locally