[Python-checkins] CVS: python/nondist/sandbox/ast/tests README,NONE,1.1 asdl.asdl,NONE,1.1 errors.asdl,NONE,1.1 pattern.asdl,NONE,1.1 rcc.asdl,NONE,1.1 slp.asdl,NONE,1.1 slp3.asdl,NONE,1.1 test.asdl,NONE,1.1 toplevel.asdl,NONE,1.1 zsuif.asdl,NONE,1.1

Jeremy Hylton jhylton@users.sourceforge.net
Sat, 06 Apr 2002 16:05:01 -0800


Update of /cvsroot/python/python/nondist/sandbox/ast/tests
In directory usw-pr-cvs1:/tmp/cvs-serv25251

Added Files:
	README asdl.asdl errors.asdl pattern.asdl rcc.asdl slp.asdl 
	slp3.asdl test.asdl toplevel.asdl zsuif.asdl 
Log Message:
New ast definition and tools.

asdl.py: an ASDL parser based on spark
spark.py: John Aycock's little language toolkit
python.asdl: an in-progress AST for Python
tests/: a collector of .asdl files to test asdl.py


--- NEW FILE: README ---
Tests for the ast sandbox.

The .asdl files come from asdl.sourceforge.net.  They are used to test
the parser in asdl.py.  They are subject to the following license:

COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.

Copyright 1998 by Princeton University

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both the copyright notice and this permission notice and warranty
disclaimer appear in supporting documentation, and that the name of
Princeton University not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.

Princeton University disclaims all warranties with regard to this
software, including all implied warranties of merchantability and
fitness.  In no event shall Princeton University be liable for any
special, indirect or consequential damages or any damages whatsoever
resulting from loss of use, data or profits, whether in an action of
contract, negligence or other tortious action, arising out of or in
connection with the use or performance of this software.

--- NEW FILE: asdl.asdl ---

-- ASDL specicication in ASDL without use of labels
-- * = repetition ? = optional ala. grep
-- Think grep meets Cish prototypes
module Asdl {

asdl_module = (identifier name,identifier* imports,asdl_type* defs)

asdl_type = SumType(field*,constructor, constructor*)
     | ProductType(field,field*)
       attributes (identifier)

constructor = Con(identifier, field*)

field = Id | Option | Sequence 
    attributes (identifier*, identifier?) 

}

--- NEW FILE: errors.asdl ---
module Foo {

t = A | B (x)
y = (t,int)
x = (y,t)

}





--- NEW FILE: pattern.asdl ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: rcc.asdl ---
-- lcc IR
-- $Id: rcc.asdl,v 1.1 2002/04/07 00:04:58 jhylton Exp $
module rcc {

-- Pickles start with an int version number, followed by rcc.program

program = (int nuids,int nlabels,item* items,interface* interfaces,int argc,string *argv)

real	= (int msb,int lsb)

item	= Symbol(symbol symbol)
	| Type(type type)
	attributes(int uid)

symbol	= (identifier id,int type,int scope,int sclass,int ref,int flags)

field	= (identifier id,int type,int offset,int bitsize,int lsb)

enum	= (identifier id,int value)

type	= INT
	| UNSIGNED
	| FLOAT
	| VOID
	| POINTER(int type)
	| ENUM(identifier tag,enum* ids)
	| STRUCT(identifier tag,field* fields)
	| UNION(identifier tag,field* fields)
	| ARRAY(int type)
	| FUNCTION(int type,int* formals)
	| CONST(int type)
	| VOLATILE(int type)
	attributes(int size,int align)

interface	= Export(int p)
		| Import(int p)
		| Global(int p,int seg)
		| Local(int uid,symbol p)		-- includes formals
		| Address(int uid,symbol q,int p,int n)
		| Segment(int seg)
		| Defaddress(int p)
		| Deflabel(int label)
		| Defconst(int suffix,int size,int value)
		| Defconstf(int size,real value)
		| Defstring(string s)
		| Space(int n)
		| Function(int f,int* caller,int* callee,int ncalls,interface* codelist)
		| Blockbeg
		| Blockend
		| Forest(node* nodes)

node	= CNST(int value)
	| CNSTF(real value)
	| ARG(node left,int len,int align)
	| ASGN(node left,node right,int len,int align)
	| CVT(int op,node left,int fromsize)
	| CALL(node left,int type)
	| CALLB(node left,node right,int type)
	| RET
	| ADDRG(int uid)
	| ADDRL(int uid)
	| ADDRF(int uid)
	| Unary(int op,node left)				-- INDIR RET JUMP NEG BCOM
	| Binary(int op,node left,node right)			-- ADD SUB DIV MUL MOD BOR BAND BXOR RSH LSH
	| Compare(int op,node left,node right,int label)	-- EQ NE GT GE LE LT
	| LABEL(int label)
	| BRANCH(int label)
	| CSE(int uid,node node)
	attributes(int suffix,int size)
}

--- NEW FILE: slp.asdl ---
module Slp {

-- Straight Line Programs from MC

stm = Compound(stm,stm)
    | Assign(identifier,exp) 
    | Print(exp_list)

exp_list = ExpList(exp,exp_list) | Nil

exp = Id(identifier)
    | Num(int)
    | Op(exp,binop,exp)

binop = Plus | Minus | Times | Div

}



--- NEW FILE: slp3.asdl ---
module Slp3 {

-- Straight Line Programs from MC
-- With user defined field names
-- With sequence
-- With raw products, atributes and options

pos = (string? file,int line, int offset)

stm = Compound(stm head,stm next)
    | Assign(identifier id,exp exp) 
    | Print(exp*)
     attributes (pos p,int? value)

-- Values are optional so that a parser can ignore them
-- but an evaluator can use them to record the value of each
-- sub-expression

exp = Id(identifier id)
    | Num(int v)
    | Op(exp lexp,binop,exp rexp)
     attributes (pos p,int? value)	

binop = Plus | Minus | Times | Div

}

--- NEW FILE: test.asdl ---
-- ASDL specicication in ASDL without use of labels
-- * = repetition ? = optional ala. grep
-- Think grep meets Cish prototypes

module Asdl {

  asdl_type = SumType(identifier, field*,constructor, constructor*)
            | ProductType(identifier,field?,field*)

  constructor = Con(identifier, field*)

  field = Id | Option | Sequence 
  attributes (identifier,identifier?)

  op = Plus | Minus | Times | Div
  t = (op bar,op* baz,op?)
  foo = (bar)
  bar = (foo)
}







--- NEW FILE: toplevel.asdl ---
module Top {

pos = (string? file,int line, int offset)

stm = Compound(stm head,stm next)
    | Assign(identifier id,exp exp) 
    | Print(exp*)
     attributes (pos p,int? value)

-- Values are optional so that a parser can ignore them
-- but an evaluator can use them to record the value of each
-- sub-expression

exp = Id(identifier id)
    | Num(int v)
    | Op(exp lexp,binop,exp rexp)
     attributes (pos p,int? value)	

binop = Plus | Minus | Times | Div

}


--- NEW FILE: zsuif.asdl ---

module zsuif {
-- hacked
suif_int = (int)
lstring  = (identifier)


-- Zephyr SUIF a simplified interface for SUIF 2.0

constant = ConstInt(suif_int)
         | ConstString(string)
         | ConstBits(string)

source_op =
           SrcVar(variable_symbol var)
         | SrcReg(register_symbol reg, type type)
         | SrcDst(instruction instr, nat op_num)
          
destination_op = 
           DstTmp -- unnamed destination 
         | DstVar(variable_symbol var)
         | DstReg(register_symbol reg, type type)
         | DstSrc(instruction instr, nat op_num)

int_or_source_op = Int(suif_int)
                 | SrcOp(source_op)

symbol = (nat uid, identifier name)

-- reorganized type hierarchy 
type_id  = (nat)

type = Data(data_type)
     | Procedure(procedure_type)
     | Qualified(qualification* qualifications, type type)
     | Void 

procedure_type = 
    Basic_procedure_type(type result_type, type* args)

    attributes(int_or_source_op? bit_size,
               int_or_source_op? bit_alignment)

data_type =
     Boolean_type 
   | Integer_type  
   | UInteger_type 
   | Floating_point_type
   | Enumerated_type(string name, enumerate_case* cases)
   | Pointer_type(type_id reference_type)
   | Array_type 
     (type element_type, 
      int_or_source_op lower_bound,
      int_or_source_op upper_bound)
   | Group_type(string name, group_field* fields)
   | Lookup_type(type_id)

   attributes(int_or_source_op? bit_size, 
              int_or_source_op? bit_alignment)

group_field    = (field_symbol name, type type, int_or_source_op bit_offset)
enumerate_case = (string name, suif_int case_constant)
qualification  = (string qualifier)

type_table_entry = (type_id key, type)
type_table       = (type_table_entry* entries)

code_label_symbol = (symbol)
procedure_symbol  = (symbol)
register_symbol   = (symbol)
variable_symbol   = (symbol)
field_symbol      = (symbol)
parameter_symbol  = (symbol)

symbol_table_entry = 
       CodeLabelEntry
     | ProcedureEntry(procedure_definition def)
     | RegisterEntry(suif_int size)
     | VariableEntry(variable_definition def)
     | ParameterEntry(parameter_symbol name,
                      int_or_source_op bit_alignment,
                      type type, procedure_symbol proc)
     | FieldEntry(int_or_source_op bit_offset)
     | NestedVariable(variable_symbol start, int_or_source_op bit_offset)
     attributes (symbol key, bool address_taken)

symbol_table = (symbol_table_entry* entries)

procedure_definition =
  (procedure_symbol name,
   qualification* qualifications, 
   procedure_type procedure_type,
   parameter_symbol* params,
   statement body)

variable_definition = (variable_symbol name,
                       type type,
                       int_or_source_op bit_alignment,
                       value_block value_block)

value_block = 
    Constant_value_block(constant constnat)
  | Expression_value_block(source_op expression)
  | Multi_value_block(multi_value_block_init* inits)
  | Repeat_value_block(suif_int count, value_block block) 
  | Undefined_value_block
  attributes(data_type data_type)

definition_block = 
  (variable_symbol*  defined_variables,
   procedure_symbol* defined_procedures)

file_block = 
  (string source_file_name, definition_block definition_block)

file_set_block = 
  (file_block* file_blocks,
   type_table type_table,
   symbol_table symbol_table,
   symbol_table extern_symbol_table,
   global_information_block information_block)

statement =
  Eval_statement -- order of evaluation undefined 
     (instruction* instructions)

 | Sequence_statement -- sequential semantics
     (statement* statements)

 | If_statement
     (source_op condition, 
      statement then_part,
      statement else_part)

 | While_statement 
     (source_op condition, statement body,
      code_label_symbol? break_label,
      code_label_symbol? continue_label)

 | Do_while_statement 
     (source_op condition, statement body,
      code_label_symbol? break_label,
      code_label_symbol? continue_label)

 | For_statement 
     (variable_symbol index, 
      source_op lower_bound,
      source_op upper_bound, 
      source_op step,
      lstring init_comparison_opcode, 
      statement body,
      statement? pre_pad, 
      statement? post_pad,
      code_label_symbol? break_label,
      code_label_symbol? continue_label)

 | Scope_statement 
     (statement body, definition_block definition_block)

 | Mark_statement -- possibly redundant

 | Va_start_statement      
     (source_op ap_address, parameter_symbol parmn)

 | Va_start_old_statement  
     (source_op ap_address)

 | Va_end_statement        
     (source_op ap_address)

 | Store_statement         
     (source_op data_operand, 
      source_op destination_address)

 | Return_statement        
     (source_op* return_values)

 | Jump_statement          
     (code_label_symbol target)

 | Jump_indirect_statement 
     (source_op itarget)

 | Branch_statement        
     (lstring opcode, 
      source_op decision_operand,
      code_label_symbol target)

 | Multi_way_branch_statement 
     (source_op decision_operand,
      code_label_symbol default_target,
      multi_way_branch_case* cases)

 | Label_location_statement (code_label_symbol defined_label)
 | Assert_statement(source_op asserted_value) 

--  attributes(?? )


-- all instructions have at least one dest op listed in the attributes code

instruction =
   Binary_arithmetic_instruction
           (lstring opcode, 
            source_op source1,
            source_op source2,
            data_type result_type, 
	    destination_op destination_op)

 | Unary_arithmetic_instruction
	   (lstring opcode, 
            source_op source,            
            data_type result_type, 
	    destination_op destination_op)

 | Copy_instruction
           (source_op source,            
            data_type result_type, 
            destination_op destination_op,
	    destination_op* destination_ops)
 
 | Select_instruction 
           (source_op selector, 
            source_op selection1,
            source_op selection2,            
            data_type result_type, 
	    destination_op destination_op)

 | Array_reference_instruction
           (source_op base_array_address,
            source_op index,            
            data_type result_type, 
	    destination_op destination_op)

 | Field_access_instruction
           (source_op base_group_address,
            field_symbol field,            
            data_type result_type, 
	    destination_op destination_op)
 
 | Extract_fields_instruction 
           (source_op base_group_op,            
            field_dst  field_dst,
	    field_dst* field_dsts)

 | Set_fields_instruction 
	   (source_op base_group_op,
            field_src  field_src,
	    field_src* field_srcs,            
            data_type result_type, 
	    destination_op destination_op)

 | Extract_elements_instruction 
	   (source_op index,
            source_op base_array_op,           
            element_dst  element_dst,
            element_dst* element_dsts)

 | Set_elements_instruction 
           (source_op base_array_op,
	    element_src  element_src,
            element_src* element_srcs)

 | Bit_size_of_instruction
           (type_id ref_type,            
            data_type   result_type, 
	    destination_op destination_op)

 | Bit_alignment_of_instruction
           (type_id ref_type,            
            data_type result_type, 
	    destination_op destination_op)

 | Bit_offset_of_instruction
            (field_symbol field,            
             data_type result_type, 
	     destination_op destination_op)

-- add bit to byte coercions and avoid these 
 | Byte_size_of_instruction
            (type_id ref_type,            
             data_type result_type, 
	     destination_op destination_op)
 
 | Byte_alignment_of_instruction
            (type_id ref_type,            
             data_type result_type, 
	     destination_op destination_op)

 | Byte_offset_of_instruction
            (field_symbol field,            
             data_type result_type, 
	     destination_op destination_op)

 | Va_arg_instruction
            (source_op ap_address,
             data_type result_type, 
	     destination_op destination_op)

 | Sc_and_instruction 
            (source_op source1, 
             source_op source2,
             data_type result_type, 
	     destination_op destination_op)

 | Sc_or_instruction 
             (source_op source1, 
              source_op source2,
              data_type result_type, 
	      destination_op destination_op)

 | Sc_select_instruction 
             (source_op selector, 
              source_op selection1,
              source_op selection2,
              data_type result_type, 
	      destination_op destination_op)

 | Load_instruction 
             (source_op source_address,
              data_type result_type, 
	      destination_op destination_op)

 | Load_address_instruction 
             (symbol addressed_symbol,
              data_type result_type, 
	      destination_op destination_op)

 | Load_constant_instruction
             (constant constant,              
              data_type result_type, 
	      destination_op destination_op)

 | Load_value_block_instruction 
             (constant constant,
              data_type result_type, 
	      destination_op destination_op)

 | Call_instruction 
             (source_op callee_address,
              source_op* arguments, 	        
	      return_value return_value,
	      return_value* return_values)

 | Ssa_phi_instruction 
             (variable_symbol* variables,
              data_type result_type, 
	      destination_op destination_op)

 | Mark_instruction 

-- redundant use statement versions
-- | Va_start_instruction(source_op ap_address, parameter_symbol parmn)
-- | Va_start_old_instruction(source_op ap_address)
-- | Va_end_instruction(source_op ap_address)
-- | Store_instruction(source_op data_operand, source_op destination_address)
-- | Return_instruction(source_op* return_values)
-- | Jump_instruction(code_label_symbol target) 
-- | Jump_indirect_instruction(source_op target)
-- | Branch_instruction(lstring opcode, 
--              source_op decision_operand,
--              code_label_symbol target)
-- | Multi_way_branch_instruction(source_op decision_operand,
--              code_label_symbol default_target,
--              multi_way_branch_case* cases)
-- | Label_location_instruction(code_label_symbol defined_label)
-- | Assert_instruction(source_op asserted_value)
--

-- attributes( )

 element_dst = (data_type result_type,
                destination_op destination_op,
                source_op index)

 element_src = (source_op index, source_op element)

 field_dst = (data_type result_type,
              destination_op destination_op, 
              field_symbol field)

 field_src  = (field_symbol field,  source_op source_op)
 
 return_value  = (destination_op destination_op, 
                  data_type result_type)

 multi_way_branch_case = (constant case_constant,
                          code_label_symbol case_target)


multi_value_block_init = (suif_int bit_offset, value_block block)

-- just stubbed out for now 
global_information_block = C_information_block 


}