summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/promela/parser/promela.ypp
blob: 8b4426b6cfe1f5706cd2153bc50811777a5f7b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/** Subset extracted from spin.y by Stefan Radomski 2014                  */

/***** spin: spin.y *****/

/* Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories.     */
/* All Rights Reserved.  This software is for educational purposes only.  */
/* No guarantee whatsoever is expressed or implied by the distribution of */
/* this code.  Permission is given to distribute this code provided that  */
/* this introductory message is not removed and no monies are exchanged.  */
/* Software written by Gerard J. Holzmann.  For tool documentation see:   */
/*             http://spinroot.com/                                       */
/* Send all bug-reports and/or questions to: bugs@spinroot.com            */

%{
#include "../PromelaParser.h"
#include "promela.tab.hpp"
#include <sys/types.h>
#include <stdarg.h>

#define YYMAXDEPTH	20000	// default is 10000
#define YYDEBUG		1
#define YYERROR_VERBOSE 1

extern int promela_lex (PROMELA_STYPE* yylval_param, void* yyscanner);

using namespace uscxml;
%}

%pure-parser
%file-prefix "promela"
%parse-param { uscxml::PromelaParser* ctx }
%lex-param {void * scanner}
%parse-param {void * scanner}
%define api.prefix promela_
%defines

%union {
  uscxml::PromelaParserNode* node;
	char* value;
}

%error-verbose


%type <node> expr pfld varref decl_lst vardcl ivar var_list one_decl

%token  LBRACKET RBRACKET
%token  <value> LEN
%token  TYPEDEF MTYPE INLINE RETURN LABEL OF
%token  GOTO BREAK ELSE SEMI ARROW
%token  IF FI DO OD FOR SELECT IN SEP DOTDOT
%token  HIDDEN SHOW ISLOCAL
%token  <value> CONST TYPE XU			/* val */
%token  <value> NAME UNAME PNAME INAME		/* sym */
%token  STRING CLAIM TRACE INIT	LTL	/* sym */

%right	ASGN
%left OR AND
%left	BITOR BITXOR BITAND
%left	EQ NE
%left	GT LT GE LE
%left	LSHIFT RSHIFT
%left	PLUS MINUS 
%left TIMES DIVIDE MODULO
%left COMPL
%right NEG
%left	DOT

%%


/** PROMELA Grammar Rules **/

program	: 
  decl_lst { 
    ctx->ast = $1; 
    ctx->type = PromelaParser::PROMELA_DECL; 
  }
  | expr { 
    ctx->ast = $1; 
    ctx->type = PromelaParser::PROMELA_EXPR;
  }

varref	: cmpnd			{}
	;

pfld	: NAME			{ $$ = ctx->value(yylval.value); }
	| NAME '[' expr ']' {}
	;

cmpnd	: pfld			{}
				sfld			{}
	;

sfld	: /* empty */		{}
	| '.' cmpnd %prec DOT	{}
	;

expr    : LBRACKET expr RBRACKET		{ $$ = $2; }
	| expr PLUS expr		{ $$ = ctx->binOp(PLUS, $1, $3); }
	| expr MINUS expr		{ $$ = ctx->binOp(MINUS, $1, $3); }
	| expr TIMES expr		{ $$ = ctx->binOp(TIMES, $1, $3); }
	| expr DIVIDE expr		{ $$ = ctx->binOp(DIVIDE, $1, $3); }
	| expr MODULO expr		{ $$ = ctx->binOp(MODULO, $1, $3); }
	| expr BITAND expr		{ $$ = ctx->binOp(BITAND, $1, $3); }
	| expr BITXOR expr		{ $$ = ctx->binOp(BITXOR, $1, $3); }
	| expr BITOR expr		{ $$ = ctx->binOp(BITOR, $1, $3); }
	| expr GT expr		{ $$ = ctx->binOp(GT, $1, $3); }
	| expr LT expr		{ $$ = ctx->binOp(LT, $1, $3); }
	| expr GE expr		{ $$ = ctx->binOp(GE, $1, $3); }
	| expr LE expr		{ $$ = ctx->binOp(LE, $1, $3); }
	| expr EQ expr		{ $$ = ctx->binOp(EQ, $1, $3); }
	| expr NE expr		{ $$ = ctx->binOp(NE, $1, $3); }
	| expr AND expr		{ $$ = ctx->binOp(AND, $1, $3); }
	| expr OR  expr		{ $$ = ctx->binOp(OR, $1, $3); }
	| expr LSHIFT expr	{ $$ = ctx->binOp(LSHIFT, $1, $3); }
	| expr RSHIFT expr	{ $$ = ctx->binOp(RSHIFT, $1, $3); }
	| NEG expr		      { $$ = ctx->uniOp(NEG, $2); }
	| MINUS expr %prec MINUS	{ $$ = ctx->uniOp(MINUS, $2); }

	| LEN '(' varref ')'	{ $$ = ctx->uniOp(LEN, $3);  }
	| varref		{  }
	| CONST 		{ $$ = ctx->value(yylval.value); }
	;


vis	: /* empty */		{ }
	| HIDDEN		{  }
	| SHOW			{  }
	| ISLOCAL		{  }
	;

one_decl: vis TYPE var_list	{ $$ = ctx->uniOp(ASGN, $3); }
	| vis UNAME var_list	{ }
	| vis TYPE ASGN '{' nlst '}' { }
	;

decl_lst: one_decl       	{ }
	| one_decl SEMI
	  decl_lst		{  }
	;

var_list: ivar           	{ $$ = ctx->uniOp(ASGN, $1); }
	| ivar ',' var_list	{ $$ = ctx->binOp(ASGN, $1, $3); }
	;

ivar    : vardcl           	{ $$ = ctx->uniOp(ASGN, $1); }
	| vardcl ASGN expr   	{ $$ = ctx->binOp(ASGN, $1, $3); }
	;

vardcl  : NAME  		{ $$ = ctx->value(yylval.value); }
	| NAME ':' CONST	{ }
	| NAME '[' const_expr ']'	{ }
	;

const_expr:	CONST			{ }
	| '-' const_expr %prec MINUS	{  }
	| '(' const_expr ')'		{  }
	| const_expr '+' const_expr	{  }
	| const_expr '-' const_expr	{  }
	| const_expr '*' const_expr	{  }
	| const_expr '/' const_expr	{  }
	| const_expr '%' const_expr	{  }
	;

nlst	: NAME			{  }
	| nlst NAME 		{  }
	| nlst ','		{  }
	;

%%