DIGIT [0-9]
HEX [0-9A-F]
ID [A-Za-z][A-Za-z0-9]*
%%
":=" { return (ASSIGN); }
"<=" { return (LE); }
"!=" { return (NE); }
char { return (CHAR); }
byte { return (BYTE); }
word { return (WORD); }
is { return (IS); }
begin { return (BLOCK); }
if { return (IF); }
then { return (THEN); }
while { return (WHILE); }
do { return (DO); }
inline { return (INLINE); }
return { return (RETURN); }
end { return (END); }
{ID} { return (IDENTIFIER); }
{DIGIT}+ { return (NUMBER); }
"$"{HEX}+ { return (NUMBER); }
"'"."'" { return (CHARACTER); }
[ 	
]+
. { return (yytext[0]); }
%%
%start program
%token CHARACTER
%token NUMBER
%token IDENTIFIER
%token CHAR BYTE WORD
%token IS BLOCK IF THEN WHILE DO INLINE
%token LE NE
%%
program : declarations
BLOCK
operators
END
;
declarations : /* Пусто */
| declaration
| declarations declaration
;
declaration : type IDENTIFIER ';'
| type IDENTIFIER '[' NUMBER ']' ';'
| type IDENTIFIER '(' ')' IS
operators
END
;
type : CHAR
| BYTE
| WORD
;
operator : IF cond THEN operators END
| WHILE cond DO operators END
| INLINE opcodes ';'
| RETURN expr ';'
| IDENTIFIER ASSIGN expr ';'
| IDENTIFIER '[' expr ']' ASSIGN expr ';'
| IDENTIFIER '(' ')' ';'
;
cond : expr '<' expr
| expr LE expr
| expr '=' expr
| expr NE expr
;
expr : NUMBER
| CHARACTER
| IDENTIFIER
| IDENTIFIER '[' expr ']'
| IDENTIFIER '(' ')'
| type '(' expr ')'
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr '%' expr
;
opcodes : NUMBER
| opcodes ',' NUMBER
;
%%
operators : operator | operators operator ;