aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_yaccer.y
blob: 7f873c24ad5758fbcbf3e4a5eb7ce85f933ba1b7 (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
%{

#include "LuaSL_LSL_tree.h"

//extern char *yytext;
//#define YYDEBUG_LEXER_TEXT yytext

%}

%define api.pure


%type <spaceValue> ignorable
%token <spaceValue> LSL_SPACE

%type <expressionValue> expr
%left LSL_BOOL_AND
%left LSL_BOOL_OR
%left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR
%left LSL_EQUAL LSL_NOT_EQUAL
%left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL
%left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT
%left LSL_SUBTRACT LSL_ADD
%left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY
%right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION
%token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION
%token <integerValue> LSL_INTEGER

%type <statementValue> statement
%nonassoc LSL_STATEMENT

%%

input :
    ignorable { ((LuaSL_yyparseParam*)data)->ast = addSpace($1, ((LuaSL_yyparseParam*)data)->ast); }
    | expr { ((LuaSL_yyparseParam*)data)->ast = addOperation(LSL_EXPRESSION, $1, $1); }
    | statement { ((LuaSL_yyparseParam*)data)->ast = addStatement($1, ((LuaSL_yyparseParam*)data)->ast); }
;

ignorable :
    LSL_SPACE { $$ = strdup($1); }
;

expr :
    expr LSL_BOOL_AND expr { $$ = addOperation( LSL_BOOL_AND, $1, $3 ); }
    | expr LSL_BOOL_OR expr { $$ = addOperation( LSL_BOOL_OR, $1, $3 ); }
    | expr LSL_BIT_OR expr { $$ = addOperation( LSL_BIT_OR, $1, $3 ); }
    | expr LSL_BIT_XOR expr { $$ = addOperation( LSL_BIT_XOR, $1, $3 ); }
    | expr LSL_BIT_AND expr { $$ = addOperation( LSL_BIT_AND, $1, $3 ); }
    | expr LSL_NOT_EQUAL expr { $$ = addOperation( LSL_NOT_EQUAL, $1, $3 ); }
    | expr LSL_EQUAL expr { $$ = addOperation( LSL_EQUAL, $1, $3 ); }
    | expr LSL_GREATER_EQUAL expr { $$ = addOperation( LSL_GREATER_EQUAL, $1, $3 ); }
    | expr LSL_LESS_EQUAL expr { $$ = addOperation( LSL_LESS_EQUAL, $1, $3 ); }
    | expr LSL_GREATER_THAN expr { $$ = addOperation( LSL_GREATER_THAN, $1, $3 ); }
    | expr LSL_LESS_THAN expr { $$ = addOperation( LSL_LESS_THAN, $1, $3 ); }
    | expr LSL_RIGHT_SHIFT expr { $$ = addOperation( LSL_RIGHT_SHIFT, $1, $3 ); }
    | expr LSL_LEFT_SHIFT expr { $$ = addOperation( LSL_LEFT_SHIFT, $1, $3 ); }
    | expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); }
    | expr LSL_SUBTRACT expr { $$ = addOperation( LSL_SUBTRACT, $1, $3 ); }
    | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); }
    | expr LSL_MODULO expr { $$ = addOperation( LSL_MODULO, $1, $3 ); }
    | expr LSL_DIVIDE expr { $$ = addOperation( LSL_DIVIDE, $1, $3 ); }
    | LSL_BIT_NOT expr { $$ = addOperation( LSL_BIT_NOT, NULL, $2 ); }
    | LSL_BOOL_NOT expr { $$ = addOperation( LSL_BOOL_NOT, NULL, $2 ); }
    | LSL_SUBTRACT expr { $$ = addOperation( LSL_NEGATION, NULL, $2 ); }  %prec LSL_NEGATION
    | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = addParenthesis($2); }
    | LSL_INTEGER { $$ = addInteger($1); }
;

statement :
    expr LSL_STATEMENT { $$ = createStatement(LSL_EXPRESSION, $1); }
;

%%