PreviousUpNext

15.3.73  src/lib/c-kit/src/parser/parse-tree.api

## parse-tree.api

# Compiled by:
#     src/lib/c-kit/src/parser/c-parser.sublib

#  C parse trees, produced by the parser 



###                    "The single thing that I'm happiest about is that the notion
###                     of making the Unix system portable was mostly mine."
###
###                                                       -- Dennis Ritchie



api Parsetree {

    Qualifier = CONST | VOLATILE;

   #  storage ilk attributes 
    Storage
     = TYPEDEF
     | STATIC
     | EXTERN 
     | REGISTER
     | AUTO;

   #  Built in unary and binary operators 
    Operator
     = PLUS | MINUS | TIMES | DIVIDE | MOD
     | GT | LT | GTE | LTE | EQ | NEQ | AND | OR
     | BIT_OR | BIT_AND | BIT_XOR | LSHIFT | RSHIFT
     | STAR | ADDR_OF | DOT | ARROW | SUB | SIZEOF
     | PRE_INC | POST_INC | PRE_DEC | POST_DEC | COMMA
     | NOT | NEGATE | BIT_NOT | ASSIGN
     | PLUS_ASSIGN | MINUS_ASSIGN | TIMES_ASSIGN | DIV_ASSIGN
     | MOD_ASSIGN | XOR_ASSIGN | OR_ASSIGN | AND_ASSIGN
     | LSHIFT_ASSIGN | RSHIFT_ASSIGN 
     | UPLUS 
     | SIZEOF_TYPE  Ctype
     | OPERATOR_EXT  Operator_Ext

   also Expression
     = EMPTY_EXPR
     | INT_CONST  large_int::Int
     | REAL_CONST  Float
     | STRING  String
     | ID  String
     | UNOP  (Operator, Expression)
     | BINOP  (Operator, Expression, Expression)
     | QUESTION_COLON  (Expression, Expression, Expression)
     | CALL  (Expression, List( Expression ))
     | CAST  (Ctype, Expression)
     | INIT_LIST  List( Expression )
     | MARKEXPRESSION  ((line_number_db::Location, Expression))
     | EXPR_EXT  Expression_Ext

   also Specifier
     = VOID
     | ELLIPSES
     | SIGNED
     | UNSIGNED
     | CHAR
     | SHORT
     | INT
     | LONG
     | FLOAT 
     | DOUBLE
     | FRACTIONAL
     | WHOLENUM
     | SATURATE
     | NONSATURATE
     | ARRAY  (Expression, Ctype)
     | POINTER  Ctype
     | FUNCTION 
         { ret_type:  Ctype,  
          parameters:   List( (Decltype, Declarator) ) }
     | ENUM 
         { tag_opt:  Null_Or( String ),
          enumerators:   List( (String, Expression) ),
          trailing_comma:  Bool }  #  TRUE if there was there a trailing comma in the declaration 
     | STRUCT 
         { is_struct:  Bool,   #  struct or union; TRUE => struct 
          tag_opt:  Null_Or( String ),  #  optional tag 
          members:  List ((Ctype, List( (Declarator, Expression) )) ) } #  member specs 
     | TYPEDEF_NAME  String
     | STRUCT_TAG 
         { is_struct:  Bool,   #  ??? 
          name:  String }
     | ENUM_TAG  String 
     | SPEC_EXT  Specifier_Ext

   also Declarator  #  Constructor suffix: "Decr" 
     = EMPTY_DECR
     | ELLIPSES_DECR
     | VAR_DECR  String
     | ARRAY_DECR  (Declarator, Expression)
     | POINTER_DECR  Declarator
     | QUAL_DECR  (Qualifier, Declarator)
     | FUNC_DECR  (Declarator, List ((Decltype, Declarator)))
     | MARKDECLARATOR  (line_number_db::Location, Declarator)
     | DECR_EXT  Declarator_Ext

   #  supports extensions of C in which expressions contain statements 
   also Statement
     = DECL  Declaration
     | EXPR  Expression 
     | COMPOUND  List( Statement )
     | WHILE  (Expression, Statement)
     | DO  (Expression, Statement)
     | FOR  (Expression, Expression, Expression, Statement)
     | LABELED  (String, Statement)
     | CASE_LABEL  (Expression, Statement)
     | DEFAULT_LABEL  Statement
     | GOTO  String
     | BREAK
     | CONTINUE
     | RETURN  Expression
     | IF_THEN  (Expression, Statement)
     | IF_THEN_ELSE  (Expression, Statement, Statement)
     | SWITCH  (Expression, Statement)
     | MARKSTATEMENT  (line_number_db::Location, Statement)
     | STAT_EXT  Statement_Ext

   also Declaration
     = DECLARATION  (Decltype, List ((Declarator, Expression)))
     | MARKDECLARATION  (line_number_db::Location, Declaration)
     | DECLARATION_EXT  Declaration_Ext

   #  the top-level constructs in a translation unit (i.e. source file) 
   also External_Decl
     = EXTERNAL_DECL  Declaration
     | FUN 
        { ret_type:  Decltype,      #  return type 
         fun_decr:  Declarator,   #  function name declarator 
         kr_params:  List( Declaration ), #  K&R-style parameter declarations 
         body:  Statement }        #  function body 
     | MARKEXTERNAL_DECL  (line_number_db::Location, External_Decl)
     | EXTERNAL_DECL_EXT  External_Decl_Ext

   withtype Ctype =
       { qualifiers:  List( Qualifier ),
        specifiers:  List( Specifier ) }
   also Decltype =
       { qualifiers:  List( Qualifier ),
        specifiers:  List( Specifier ),
        storage:  List( Storage ) }

   #  extension types for basic constructs 
   also External_Decl_Ext =    parse_tree_ext::External_Decl_Ext (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)
   also Declaration_Ext =     parse_tree_ext::Declaration_Ext  (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)
   also Statement_Ext =       parse_tree_ext::Statement_Ext    (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)
   also Declarator_Ext =      parse_tree_ext::Declarator_Ext   (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)
   also Specifier_Ext =       parse_tree_ext::Specifier_Ext    (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)
   also Expression_Ext =      parse_tree_ext::Expression_Ext   (Specifier, Declarator, Ctype, Decltype, Operator, Expression, Statement)

   also Operator_Ext = parse_tree_ext::Operator_Ext;

}; #  Api PARSETREE 

# Note: in package declarations, the bool is IsStruct/IsUnion, and the expression
# after the declarator is the bit field.


# Location Marking:
# The expression, declarator, statement, declaration, and externalDecl
# types have a MARK variant for annotating the corresponding constructs
# with source file locations.


# Syntax Extensions:
# The operator, expression, specification, declarator, statement, declaration,
# and externalDecl types have an ...Ext variant for supporting syntax
# extensions.  The types of these variants, operatorExt, expressionExt, etc.
# are defined by instantiating corresponding type operators defined in
# the ParseTreeExt package (see src/parser/extensions/c/parse-tree-ext*.sml
# for the dummy definitions for ansi C).  In general, extensions for 
# a construct may need to build on other constructs, which is why
# the ParseTreeExt type constructors are parameterized by the collection
# of syntax tree types.

# A user-defined extension (call it x) would need it's own version of
# ParseTreeExt defined in files parse-tree-ext.api and parse-tree-ext.pkg
# in a new directory src/parser/extensions/x/.



## Copyright (c) 1998 by Lucent Technologies 
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext