Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/dpas/dpas-parser.y  view on Meta::CPAN

%token K_GE					"`>='"
%token K_ASSIGN				"`:='"
%token K_DOT_DOT			"`..'"

/*
 * Define the yylval types of the various non-terminals.
 */
%type <name>				IDENTIFIER STRING_CONSTANT Identifier Directive
%type <int_const>			INTEGER_CONSTANT
%type <real_const>			REAL_CONSTANT
%type <const_value>			Constant ConstantValue BasicConstant
%type <id_list>				IdentifierList
%type <type_list>			ArrayBoundsList VariantCaseList

%type <type>				Type TypeIdentifier SimpleType StructuredType
%type <type>				BoundType Variant VariantList

%type <param_type>			ParameterType ConformantArray

%type <parameters>			FormalParameterList FormalParameterSection
%type <parameters>			FormalParameterSections FieldList FixedPart
%type <parameters>			RecordSection VariantPart BoundSpecificationList
%type <parameters>			BoundSpecification

%type <procedure>			ProcedureHeading FunctionHeading
%type <procedure>			ProcedureOrFunctionHeading

%type <semvalue>			Variable Expression SimpleExpression
%type <semvalue>			AdditionExpression Term Factor Power
%type <semvalue>			BooleanExpression AssignmentStatement

%type <expr_list>			ExpressionList ActualParameters

%type <direction>			Direction

%type <abi>					OptAbi

%expect 3

%start Program
%%

/*
 * Programs.
 */

Program
	: ProgramHeading ImportDeclarationPart ProgramBlock '.'
	;

ProgramHeading
	: K_PROGRAM Identifier '(' IdentifierList ')' ';'	{
				jit_free($2);
				identifier_list_free($4.list, $4.len);
			}
	| K_PROGRAM Identifier ';'	{
				jit_free($2);
			}
	| K_MODULE Identifier '(' IdentifierList ')' ';'	{
				/* The "module" keyword is provided as an alternative
				   to "program" because it looks odd to put "program"
				   on code included via an "import" clause */
				jit_free($2);
				identifier_list_free($4.list, $4.len);
			}
	| K_MODULE Identifier ';'	{
				jit_free($2);
			}
	;

ImportDeclarationPart
	: /* empty */
	| K_IMPORT ImportDeclarations ';'
	;

ImportDeclarations
	: Identifier		{
				dpas_import($1);
				jit_free($1);
			}
	| ImportDeclarations ',' Identifier	{
				dpas_import($3);
				jit_free($3);
			}
	;

ProgramBlock
	: Block		{
				/* Get the "main" function for this module */
				jit_function_t func = dpas_current_function();

				/* Make sure that the function is properly terminated */
				if(!jit_insn_default_return(func))
				{
					dpas_out_of_memory();
				}

				/* Dump the before-compile state of the function */
				if(dpas_dump_functions)
				{
					jit_dump_function(stdout, func, "main");
				}

				/* Compile the procedure/function */
				if(!jit_function_compile(func))
				{
					dpas_out_of_memory();
				}

				/* Dump the after-compile state of the function */
				if(dpas_dump_functions > 1)
				{
					jit_dump_function(stdout, func, "main");
				}

				/* Add the function to the "main" list, for later execution */
				dpas_add_main_function(func);

				/* Pop the "main" function */
				dpas_pop_function();
			}



( run in 1.118 second using v1.01-cache-2.11-cpan-d7f47b0818f )