GIRL语法


文件girl.y按照yacc的规则给出了GIRL的语法。下面给出其内容及相应的解释(斜体字):
%{
%}

%token  _MODULE_ , _VERSION_ , _IMPORT_
%token  _TYPE_ , _INTEGER_ , _FLOAT_ , _STRING_
%token  _COLOR_ , _CURSOR_ , _FONT_ , _PIXMAP_
%token	_BMP_ , _JPEG_ , _PNG_ , _PPM_ , _PS_ , _TIFF_ , _XPM_
%token	_WIDGET_ , _SIGNAL_ , _DATASLOT_ , _RECEIVER_ , _TABLE_

%token	NULL

%token	TABLEITEM
%token	FLOAT , INTEGER , STRING , IDENTIFIER

%token	EQUAL , DOT , COMMA , COLON , SEMICOLON , SENDSLOT
%token	LINKSLOT , LPAREN , RPAREN , LBRACKET , RBRACKET
%token	LBRACE , RBRACE

%%

girlfile	:	statementlist
		;

statementlist	:	statementlist statement
		|
		;

statement	:	modulestatement
		|       versionstatement
		|	importstatement
		|	typedefinition
		|	signaldefinition
		|	identifierassign
		|	integerassign
		|	floatassign
		|	stringassign
		|	colorassign
		|	cursorassign
		|	fontassign
		|	pixmapassign
		|	widgetdefinition
		;
modulestatement	:	_MODULE_ IDENTIFIER SEMICOLON
		;
versionstatement	:	_VERSION_ INTEGER DOT INTEGER DOT INTEGER SEMICOLON
                        |       _VERSION_ INTEGER DOT INTEGER SEMICOLON
                        |       _VERSION_ INTEGER SEMICOLON
                        ;

importstatement	:	_IMPORT_ IDENTIFIER LBRACE describelist RBRACE
		;

describelist	:	describelist describe
		|
		;

describe	:	integerdescribe
		|	floatdescribe
		|	stringdescribe
		|	colordescribe
		|	cursordescribe
		|	fontdescribe
		|	pixmapdescribe
		|	widgetdescribe
		;

typedefinition	:	IDENTIFIER EQUAL typevalue
		;

typevalue	:	_TYPE_ LPAREN compoundtypelist RPAREN
		;

compoundtypelist	:	compoundtypelist COMMA compoundtype
			|	compoundtype
			;

compoundtype	:	IDENTIFIER
		|	LPAREN compoundtypelist RPAREN
		;

signaldefinition	:	IDENTIFIER EQUAL signalvalue SEMICOLON
		;

signalvalue		:	_SIGNAL_
			|	_SIGNAL_ LPAREN typevalue RPAREN
			;

integerdescribe	:	_INTEGER_ identifierlist SEMICOLON
		;

floatdescribe	:	_FLOAT_ identifierlist SEMICOLON
		;

stringdescribe	:	_STRING_ identifierlist SEMICOLON
		;

colordescribe	:	_COLOR_ identifierlist SEMICOLON
		;

cursordescribe	:	_CURSOR_ identifierlist SEMICOLON
		;

fontdescribe	:	_FONT_ identifierlist SEMICOLON
		;

pixmapdescribe	:	_PIXMAP_ identifierlist SEMICOLON
		;

identifierlist	:	identifierlist COMMA IDENTIFIER
		|	IDENTIFIER
		;

widgetdescribe	:	_WIDGET_ IDENTIFIER COLON IDENTIFIER LBRACE slotdescribelist RBRACE
		;

slotdescribelist	:	slotdescribelist slotdescribe
			|	slotdescribe
			;

slotdescribe	:	dataslotdescribe
		|	receiverdescribe
		|	signalslotdescribe
		;

dataslotdescribe	:	_DATASLOT_ dataslotdescribelist SEMICOLON
			;

dataslotdescribelist	:	dataslotdescribelist COMMA dataslotitemdescribe
			|	dataslotitemdescribe
			;

dataslotitemdescribe	:	IDENTIFIER LPAREN typevalue RPAREN
			|	IDENTIFIER LPAREN typevalue RPAREN LINKSLOT INTEGER
			;

receiverdescribe	:	_RECEIVER_ receiverdescribelist SEMICOLON
			;

receiverdescribelist	:	receiverdescribelist COMMA receiveritemdescribe
			|	receiveritemdescribe
			;

receiveritemdescribe	:	IDENTIFIER LPAREN typevalue RPAREN
			|	IDENTIFIER LPAREN typevalue RPAREN LINKSLOT INTEGER
			;

signalslotdescribe	:	_SIGNAL_ signalslotdescribelist SEMICOLON
			;

signalslotdescribelist	:	signalslotdescribelist COMMA signalslotitemdescribe
			|	signalslotitemdescribe
			;

signalslotitemdescribe	:	IDENTIFIER LPAREN identifierlist RPAREN
			;

identifierassign	:	IDENTIFIER EQUAL IDENTIFIER SEMICOLON
			;

integerassign	:	IDENTIFIER EQUAL INTEGER SEMICOLON
		;

floatassign	:	IDENTIFIER EQUAL FLOAT SEMICOLON
		;

stringassign	:	IDENTIFIER EQUAL STRING SEMICOLON
		;

colorassign	:	IDENTIFIER EQUAL colorvalue SEMICOLON
		;

colorvalue	:	_COLOR_ LPAREN STRING RPAREN
		|	_COLOR_ LPAREN integervalue COMMA integervalue COMMA integervalue RPAREN
		;
integervalue	:	IDENTIFIER
		|	INTEGER
		;

cursorassign	:	IDENTIFIER EQUAL cursorvalue SEMICOLON
		;

cursorvalue	:	_CURSOR_ LPAREN STRING RPAREN
		;

fontassign	:	IDENTIFIER EQUAL fontvalue SEMICOLON
		;

fontvalue	:	_FONT_ LPAREN STRING RPAREN
		;

pixmapassign	:	IDENTIFIER EQUAL pixmapvalue SEMICOLON
		;

pixmapvalue	:	_BMP_ LPAREN STRING RPAREN
		|	_JPEG_ LPAREN STRING RPAREN
		|	_PNG_ LPAREN STRING RPAREN
		|	_PPM_ LPAREN STRING RPAREN
		|	_PS_ LPAREN STRING RPAREN
		|	_TIFF_ LPAREN STRING RPAREN
		|	_XPM_ LPAREN STRING RPAREN
		;

widgetdefinition	:	IDENTIFIER COLON IDENTIFIER LBRACE widgetdefstatelist RBRACE
			;

widgetdefstatelist	:	widgetdefstatelist widgetdefstateitem
			|	widgetdefstateitem
			;

widgetdefstateitem	:	dataslotdefinition
			|	receiverdefinition
			|	slotassign
			|	slotlink
			|	signalslotdefinition
			|	signalslotredefinition
			;

dataslotdefinition	:	_DATASLOT_ LPAREN identifierlist RPAREN EQUAL typevalue
			|	_DATASLOT_ LPAREN identifierlist RPAREN EQUAL typevalue LINKSLOT INTEGER
			;

receiverdefinition	:	_RECEIVER_ LPAREN IDENTIFIER RPAREN EQUAL LPAREN typevalue COLON receiverfunc COMMA receiverfunc RPAREN
			|	_RECEIVER_ LPAREN IDENTIFIER RPAREN EQUAL LPAREN typevalue COLON receiverfunc COMMA receiverfunc RPAREN LINKSLOT INTEGER
			;
receiverfunc		:	IDENTIFIER
			|	NULL
			;

slotassign		:	IDENTIFIER slotassignlist
			;
slotassignlist		:	slotassignlist SENDSLOT slotvalue
			|	SENDSLOT slotvalue
			;

slotvalue		:	IDENTIFIER
			|	INTEGER
			|	FLOAT
			|	STRING
			|	colorvalue
			|	cursorvalue
			|	fontvalue
			|	pixmapvalue
			|	widgetvalue
			|	tablestatement
			|	TABLEITEM
			|	NULL
			;

widgetvalue		:	IDENTIFIER LBRACE widgetvaluesublist RBRACE
			;

widgetvaluesublist	:	widgetvaluesublist widgetvaluesub
			|
			;

widgetvaluesub		:	slotassign
			|	slotlink
			;

slotlink		:	identifierlist LINKSLOT INTEGER
			;

signalslotdefinition	:	_SIGNAL_ LPAREN IDENTIFIER RPAREN EQUAL IDENTIFIER LPAREN identifierlist RPAREN
			;

signalslotredefinition	:	_SIGNAL_ LPAREN IDENTIFIER RPAREN EQUAL IDENTIFIER
			;

tablestatement		:	_TABLE_ LBRACKET slotvalue RBRACKET LBRACE tablerowlist RBRACE
			;

tablerowlist		:	tablerowlist tablerow SEMICOLON
			|	tablerow SEMICOLON
			;

tablerow		:	tablerow slotvalue
			|	slotvalue
			;

返回首页
GIRL词法
与我联系