2.1.3) Formal syntax

This is the formal syntax using YACC, where:


program		:	r_PROGRAM
			command_syntax
		;

command_syntax	:	string
			case_line
			comment_line
			const_def
			type_def
			proc_body
		;

proc_body	:	select_body
		|	data_body
		|	unixdata_body
		;

select_body	:	r_SELECT
			select_stats
			r_END
		;

select_stats	:	command_stat
		|	select_stats command_stat
		;

command_stat	:	r_COMMAND 
			command_syntax
		;

data_body	:	r_DATA l_IDENTIFIER
			data_stats
			r_CALL l_IDENTIFIER ':' out_type
		;

unixdata_body	:	r_UNIXDATA l_IDENTIFIER
			unixdata_stats
			r_CALL l_IDENTIFIER ':' out_type
		;

data_stats	:	/* epsilon */
		|	data_stats data_stat
		;

data_stat	:	param_stat
		|	optparam_stat
		|	option_stat
		;

unixdata_stats	:	/* epsilon */
		|	unixdata_stats unixdata_stat
		;

unixdata_stat	:	option_stat
		|	short_option_stat
		;

param_stat	:	r_PARAM l_IDENTIFIER ':' in_type
			comment_line
		;

optparam_stat	:	r_OPTPARAM l_IDENTIFIER ':' in_type
			comment_line
		;

option_stat	:	r_OPTION string l_IDENTIFIER ':' in_type
			case_line
			comment_line
		;

short_option_stat	:	r_OPTION string l_IDENTIFIER
				case_line
				comment_line
			;

case_line	:	r_CASE r_SENSITIVE
		|	r_CASE r_INSENSITIVE
		|	/* epsilon */
		;

comment_line	:	comment_lines
		|	/* epsilon */
		;

comment_lines	:	comment_lines comment_el
		|	comment_el
		;


comment_el	:	r_COMMENT string
		;

simple_comment_line	:	simple_comment_lines
			|	/* epsilon */
			;

simple_comment_lines	:	simple_comment_lines simple_comment_el
			|	simple_comment_el
			;


simple_comment_el	:	r_COMMENT string_el
			;

/* const definition */

const_def	:	const_def const_decl
		|	/* epsilon */
		;

const_decl	:	r_CONST const_dicks
		;

const_dicks	:	const_dicks const_dick
		|	const_dick
		;

const_dick	:	l_IDENTIFIER '=' const_int
		|	l_IDENTIFIER
		|	l_IDENTIFIER '=' const_real
		|	l_IDENTIFIER '=' const_string
		|	l_IDENTIFIER '=' l_IDENTIFIER
		|	l_IDENTIFIER '=' '-' l_IDENTIFIER
		|	l_IDENTIFIER '=' '+' l_IDENTIFIER
		;

const_int	:	l_nat
		|	'+' l_nat
		|	'-' l_nat
		;

const_real	:	l_ureal
		|	'+' l_ureal
		|	'-' l_ureal
		;

const_string	:	const_string '+' l_STRING
		|	l_STRING
		;

/* type definitions */
type_def	:	type_def in_type_def
		|	type_def out_type_def
		|	/* epsilon */
		;

/* input type definitions */
in_type_def	:	r_INTYPE in_type_dicks
		;

in_type_dicks	:	in_type_dick
		|	in_type_dicks in_type_dick
		;

in_type_dick	:	l_IDENTIFIER '=' in_type_ext
			comment_line
		;

in_type_ext	:	in_type
		|	in_type_user
		|	in_type_record
		|	in_type_list
		|	in_type_array
		|	in_type_case
		;

/* output type definitions */
out_type_def	:	r_OUTTYPE out_type_dicks
		;

out_type_dicks	:	out_type_dick
		|	out_type_dicks out_type_dick
		;

out_type_dick	:	l_IDENTIFIER '=' out_type_ext
			comment_line
		;

out_type_ext	:	out_type
		|	out_type_user
		|	out_type_record
		|	out_type_list
		|	out_type_array
		|	out_type_case
		;

/* input types */
in_type		:	l_IDENTIFIER	/* must be in_type */
		|	r_INT
		|	r_NAT
		|	r_COMPACT
		|	r_HEX
		|	r_OCTAL
		|	r_BINARY
		|	r_IRANGE '(' irange_list ')'
		|	r_REAL
		|	r_RRANGE '(' rrange_list ')'
		|	r_INTREAL
		|	r_IRRANGE '(' irrange_list ')'
		|	r_POINTER
		|	r_CHAR
		|	r_CRANGE '(' crange_list ')'
		|	in_type_string
		|	r_SET '(' set_list ')'
		|	r_ISET '(' set_list ')'
		|	r_BOOL
		;

in_type_string	:	r_STRING '(' nat ',' nat ')'
		|	r_STRING '(' nat ')'
		|	r_STRING
		;

irange_list	:	irange_list ',' irange_el
		|	irange_el
		;

irange_el	:	integer l_DPOINT integer
		|	integer
		|	integer l_DPOINT integer r_STEP nat
		;
		
rrange_list	:	rrange_list ',' rrange_el
		|	rrange_el
		;

rrange_el	:	real l_DPOINT real
		|	real ':' ureal
		|	real l_DPOINT real r_STEP ureal ':' ureal
		;

irrange_list	:	irrange_list ',' irrange_el
		|	irrange_el
		;

irrange_el	:	real l_DPOINT real
		|	real
		|	real l_DPOINT real r_STEP ureal
		;


crange_list	:	crange_list ',' crange_el
		|	crange_el
		;

crange_el	:	string l_DPOINT string
		|	string
		;

set_list	:	set_list ',' set_el
		|	set_el
		;

set_el		:	string ':' integer
			comment_line
		|	string
			comment_line
		;

in_type_user	:	r_USER l_IDENTIFIER l_IDENTIFIER
		;

in_type_record	:	r_RECORD
			in_record_dicks
			r_END
		;

in_record_dicks	:	in_record_dicks in_record_dick
		|	in_record_dick
		;

in_record_dick	:	l_IDENTIFIER ':' in_type
			simple_comment_line 
		;

in_type_list	:	r_LIST r_OF in_type
		;

in_type_array	:	r_ARRAY '(' nat ')' r_OF in_type
		;

in_type_case	:	r_CASE l_IDENTIFIER r_OF 
			in_case_dicks
			r_END
		;

in_case_dicks	:	in_case1_dicks in_case_dick
		|	in_case1_dicks in_case_else
		;

	/* in_case1_dicks is in_case_dicks without else +- */
in_case1_dicks	:	in_case1_dicks in_case_dick
		|	/* Empty */
		;

in_case_dick	:	nat l_IDENTIFIER ':' in_type
			simple_comment_line
		;

in_case_else	:	r_ELSE l_IDENTIFIER ':' in_type
			simple_comment_line
		;

/* output types */
out_type	:	l_IDENTIFIER	/* must be out_type */
		|	r_INT
		|	r_NAT
		|	r_COMPACT
		|	r_HEX
		|	r_OCTAL
		|	r_BINARY
		|	out_type_real
		|	out_type_freal
		|	r_BREAL
		|	out_type_intreal
		|	r_POINTER
		|	r_CHAR
		|	r_STRING
		|	r_BOOL
		|	r_CBOOL
		|	r_NBOOL
		;

out_type_real	:	r_REAL '(' l_nat ')'
		|	r_REAL
		;

out_type_freal	:	r_FREAL '(' l_nat ',' l_nat ')'
		|	r_FREAL '(' l_nat ')'
		|	r_FREAL
		;

out_type_intreal:	r_INTREAL '(' l_nat ')'
		|	r_INTREAL
		;

out_type_user	:	r_USER l_IDENTIFIER l_IDENTIFIER
		;

out_type_record	:	r_RECORD
			out_record_dicks
			r_END
		;

out_record_dicks:	out_record_dicks out_record_dick
		|	out_record_dick
		;

out_record_dick	:	l_IDENTIFIER ':' out_type
			simple_comment_line 
		;

out_type_list	:	r_LIST r_OF out_type
		;

out_type_array	:	r_ARRAY '(' nat ')' r_OF out_type
		;

out_type_case	:	r_CASE l_IDENTIFIER r_OF 
			out_case_dicks
			r_END
		;

out_case_dicks	:	out_case1_dicks out_case_dick
		|	out_case1_dicks out_case_else
		;

	/* out_case1_dicks is out_case_dicks without else +- */
out_case1_dicks	:	out_case1_dicks out_case_dick
		|	/*epsilon*/
		;

out_case_dick	:	nat l_IDENTIFIER ':' out_type
			simple_comment_line
		;

out_case_else	:	r_ELSE l_IDENTIFIER ':' out_type
			simple_comment_line 
		;

/* basic types */
int_el		:	l_nat
		|	l_IDENTIFIER	/* must be int */
		;

integer		:	int_el
		|	'+' int_el
		|	'-' int_el
		;

nat 		:	integer		/* must be non negative */
		;

real_el		:	l_ureal
		|	l_nat
		|	l_IDENTIFIER	/* must be real or int */
		;

real		:	real_el
		|	'+' real_el
		|	'-' real_el
		;

ureal		:	real	/* must be non negative*/
		;

string_el	:	l_STRING
		|	l_IDENTIFIER	/* must be string */
		;

string		:	string '+' string_el
		|	string_el
		;


Back to main page.
Send comments to: Igor Sfiligoi