common: libeval_compiler :virtual method support

This commit is contained in:
Tomasz Wlostowski 2020-06-16 21:48:47 +02:00
parent 085698d17c
commit 3005aab444
8 changed files with 908 additions and 562 deletions

View File

@ -4,7 +4,9 @@ if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_subdirectory( libeval libeval_compiler ) add_subdirectory( libeval )
add_subdirectory( libeval_compiler )
include_directories( BEFORE ${INC_BEFORE} ) include_directories( BEFORE ${INC_BEFORE} )
include_directories( include_directories(
@ -91,7 +93,7 @@ endif()
# a single_top link image. By not linking to common, we control what does # a single_top link image. By not linking to common, we control what does
# statically go into single_top link images. My current thinking is that only # statically go into single_top link images. My current thinking is that only
# wxWidgets should be a shared link from single top, everything else should be # wxWidgets should be a shared link from single top, everything else should be
# statically bound into it. Otherwise you will have DSO loading problems. After it # statically bound into it. Otherwise you will have DSO loading probs. After it
# sets the LIB PATHS however, we want the *.kiface modules to use shared linking. # sets the LIB PATHS however, we want the *.kiface modules to use shared linking.
add_library( singletop STATIC EXCLUDE_FROM_ALL add_library( singletop STATIC EXCLUDE_FROM_ALL
confirm.cpp confirm.cpp
@ -423,6 +425,8 @@ target_include_directories( common PRIVATE
add_dependencies( common libcontext ) add_dependencies( common libcontext )
add_dependencies( common version_header ) add_dependencies( common version_header )
add_dependencies( common libeval_grammar )
add_dependencies( common libeval_grammar2 )
target_link_libraries( common target_link_libraries( common
kimath kimath
@ -557,6 +561,7 @@ make_lexer(
DRCRULE_T DRCRULE_T
) )
# auto-generate pcbnew_sexpr.h and pcbnew_sexpr.cpp # auto-generate pcbnew_sexpr.h and pcbnew_sexpr.cpp
make_lexer( make_lexer(
pcbcommon pcbcommon

View File

@ -1,29 +1,17 @@
annulus_width
board_edge
buried_via
clearance
condition condition
constraint
disallow
footprint
graphic
hole
match_area
match_layer
match_netclass
match_type
max max
micro_via
min min
npth
opt opt
pad allow
pth
rule rule
selector
text
track
track_width
version version
via name
zone priority
expression
enable
severity
type
error
warning
info
ignore

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
#define VAR 1 #define VAR 1
#define ASSIGN 2 #define ASSIGN 2
#define SEMCOL 3 #define SEMCOL 3
#define PLUS 4 #define PLUS 4
#define MINUS 5 #define MINUS 5
#define UNIT 6 #define UNIT 6
#define DIVIDE 7 #define DIVIDE 7
#define MULT 8 #define MULT 8
#define ENDS 9 #define ENDS 9
#define VALUE 10 #define VALUE 10
#define PARENL 11 #define PARENL 11
#define PARENR 12 #define PARENR 12

View File

@ -25,7 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
/************ Begin %include sections from the grammar ************************/ /************ Begin %include sections from the grammar ************************/
#line 33 "grammar.lemon" #line 34 "grammar.lemon"
#include <assert.h> #include <assert.h>
#include <libeval_compiler/libeval_compiler.h> #include <libeval_compiler/libeval_compiler.h>
@ -190,57 +190,59 @@ typedef union {
** yy_default[] Default action for each state. ** yy_default[] Default action for each state.
** **
*********** Begin parsing tables **********************************************/ *********** Begin parsing tables **********************************************/
#define YY_ACTTAB_COUNT (118) #define YY_ACTTAB_COUNT (135)
static const YYACTIONTYPE yy_action[] = { static const YYACTIONTYPE yy_action[] = {
/* 0 */ 68, 1, 1, 19, 9, 10, 17, 16, 14, 13, /* 0 */ 68, 1, 1, 19, 10, 9, 17, 16, 14, 13,
/* 10 */ 12, 4, 11, 92, 19, 8, 7, 5, 6, 3, /* 10 */ 12, 4, 11, 87, 8, 7, 5, 6, 3, 5,
/* 20 */ 87, 26, 9, 10, 61, 16, 14, 13, 12, 4, /* 20 */ 6, 3, 10, 9, 61, 16, 14, 13, 12, 4,
/* 30 */ 11, 31, 32, 8, 7, 5, 6, 3, 28, 29, /* 30 */ 11, 67, 8, 7, 5, 6, 3, 92, 19, 22,
/* 40 */ 9, 10, 62, 16, 14, 13, 12, 4, 11, 20, /* 40 */ 10, 9, 62, 16, 14, 13, 12, 4, 11, 31,
/* 50 */ 21, 8, 7, 5, 6, 3, 43, 67, 67, 27, /* 50 */ 8, 7, 5, 6, 3, 32, 43, 9, 28, 16,
/* 60 */ 16, 14, 13, 12, 4, 11, 23, 24, 8, 7, /* 60 */ 14, 13, 12, 4, 11, 29, 8, 7, 5, 6,
/* 70 */ 5, 6, 3, 67, 67, 67, 67, 4, 11, 90, /* 70 */ 3, 67, 67, 67, 67, 67, 67, 23, 8, 7,
/* 80 */ 33, 8, 7, 5, 6, 3, 67, 67, 33, 25, /* 80 */ 5, 6, 3, 16, 14, 13, 12, 4, 11, 33,
/* 90 */ 8, 7, 5, 6, 3, 33, 18, 22, 45, 66, /* 90 */ 8, 7, 5, 6, 3, 90, 33, 20, 24, 25,
/* 100 */ 34, 46, 2, 5, 6, 3, 15, 66, 34, 46, /* 100 */ 26, 27, 18, 21, 3, 15, 45, 69, 66, 34,
/* 110 */ 2, 67, 3, 69, 69, 34, 46, 2, /* 110 */ 46, 2, 33, 69, 69, 66, 34, 46, 2, 69,
/* 120 */ 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
/* 130 */ 69, 69, 34, 46, 2,
}; };
static const YYCODETYPE yy_lookahead[] = { static const YYCODETYPE yy_lookahead[] = {
/* 0 */ 25, 26, 27, 28, 4, 5, 28, 7, 8, 9, /* 0 */ 25, 26, 27, 28, 4, 5, 28, 7, 8, 9,
/* 10 */ 10, 11, 12, 27, 28, 15, 16, 17, 18, 19, /* 10 */ 10, 11, 12, 28, 14, 15, 16, 17, 18, 16,
/* 20 */ 28, 28, 4, 5, 24, 7, 8, 9, 10, 11, /* 20 */ 17, 18, 4, 5, 24, 7, 8, 9, 10, 11,
/* 30 */ 12, 28, 28, 15, 16, 17, 18, 19, 28, 28, /* 30 */ 12, 18, 14, 15, 16, 17, 18, 27, 28, 28,
/* 40 */ 4, 5, 24, 7, 8, 9, 10, 11, 12, 28, /* 40 */ 4, 5, 24, 7, 8, 9, 10, 11, 12, 28,
/* 50 */ 28, 15, 16, 17, 18, 19, 20, 4, 5, 28, /* 50 */ 14, 15, 16, 17, 18, 28, 20, 5, 28, 7,
/* 60 */ 7, 8, 9, 10, 11, 12, 28, 28, 15, 16, /* 60 */ 8, 9, 10, 11, 12, 28, 14, 15, 16, 17,
/* 70 */ 17, 18, 19, 7, 8, 9, 10, 11, 12, 0, /* 70 */ 18, 7, 8, 9, 10, 11, 12, 28, 14, 15,
/* 80 */ 1, 15, 16, 17, 18, 19, 11, 12, 1, 28, /* 80 */ 16, 17, 18, 7, 8, 9, 10, 11, 12, 1,
/* 90 */ 15, 16, 17, 18, 19, 1, 28, 28, 13, 20, /* 90 */ 14, 15, 16, 17, 18, 0, 1, 28, 28, 28,
/* 100 */ 21, 22, 23, 17, 18, 19, 23, 20, 21, 22, /* 100 */ 28, 28, 28, 28, 18, 23, 19, 29, 20, 21,
/* 110 */ 23, 19, 19, 29, 29, 21, 22, 23, 29, 29, /* 110 */ 22, 23, 1, 29, 29, 20, 21, 22, 23, 29,
/* 120 */ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, /* 120 */ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
/* 130 */ 29, 29, 29, 29, 29, 29, 29, 29, /* 130 */ 29, 29, 21, 22, 23, 29, 29, 29,
}; };
#define YY_SHIFT_COUNT (34) #define YY_SHIFT_COUNT (34)
#define YY_SHIFT_MIN (0) #define YY_SHIFT_MIN (0)
#define YY_SHIFT_MAX (94) #define YY_SHIFT_MAX (111)
static const unsigned char yy_shift_ofst[] = { static const unsigned char yy_shift_ofst[] = {
/* 0 */ 87, 79, 94, 94, 94, 94, 94, 94, 94, 94, /* 0 */ 88, 95, 111, 111, 111, 111, 111, 111, 111, 111,
/* 10 */ 94, 94, 94, 94, 94, 94, 94, 0, 18, 36, /* 10 */ 111, 111, 111, 111, 111, 111, 111, 0, 18, 36,
/* 20 */ 53, 53, 66, 66, 66, 66, 75, 75, 86, 86, /* 20 */ 52, 64, 64, 76, 64, 64, 64, 64, 3, 3,
/* 30 */ 92, 93, 93, 83, 85, /* 30 */ 13, 86, 86, 82, 87,
}; };
#define YY_REDUCE_COUNT (16) #define YY_REDUCE_COUNT (16)
#define YY_REDUCE_MIN (-25) #define YY_REDUCE_MIN (-25)
#define YY_REDUCE_MAX (69) #define YY_REDUCE_MAX (75)
static const signed char yy_reduce_ofst[] = { static const signed char yy_reduce_ofst[] = {
/* 0 */ -25, -14, -22, -8, -7, 3, 4, 10, 11, 21, /* 0 */ -25, 10, -22, -15, 11, 21, 27, 30, 37, 49,
/* 10 */ 22, 31, 38, 39, 61, 68, 69, /* 10 */ 69, 70, 71, 72, 73, 74, 75,
}; };
static const YYACTIONTYPE yy_default[] = { static const YYACTIONTYPE yy_default[] = {
/* 0 */ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, /* 0 */ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
/* 10 */ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, /* 10 */ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
/* 20 */ 81, 80, 75, 78, 77, 76, 86, 79, 83, 82, /* 20 */ 80, 75, 86, 81, 79, 78, 77, 76, 83, 82,
/* 30 */ 87, 85, 84, 74, 71, /* 30 */ 87, 85, 84, 74, 71,
}; };
/********** End of lemon-generated parsing tables *****************************/ /********** End of lemon-generated parsing tables *****************************/
@ -352,8 +354,8 @@ static const char *const yyTokenName[] = {
/* 1 */ "G_IDENTIFIER", /* 1 */ "G_IDENTIFIER",
/* 2 */ "G_ASSIGN", /* 2 */ "G_ASSIGN",
/* 3 */ "G_SEMCOL", /* 3 */ "G_SEMCOL",
/* 4 */ "G_BOOL_OR", /* 4 */ "G_BOOL_AND",
/* 5 */ "G_BOOL_AND", /* 5 */ "G_BOOL_OR",
/* 6 */ "G_BOOL_XOR", /* 6 */ "G_BOOL_XOR",
/* 7 */ "G_LESS_THAN", /* 7 */ "G_LESS_THAN",
/* 8 */ "G_GREATER_THAN", /* 8 */ "G_GREATER_THAN",
@ -361,13 +363,13 @@ static const char *const yyTokenName[] = {
/* 10 */ "G_GREATER_EQUAL_THAN", /* 10 */ "G_GREATER_EQUAL_THAN",
/* 11 */ "G_EQUAL", /* 11 */ "G_EQUAL",
/* 12 */ "G_NOT_EQUAL", /* 12 */ "G_NOT_EQUAL",
/* 13 */ "G_UNIT", /* 13 */ "G_BOOL_NOT",
/* 14 */ "G_BOOL_NOT", /* 14 */ "G_PLUS",
/* 15 */ "G_PLUS", /* 15 */ "G_MINUS",
/* 16 */ "G_MINUS", /* 16 */ "G_DIVIDE",
/* 17 */ "G_DIVIDE", /* 17 */ "G_MULT",
/* 18 */ "G_MULT", /* 18 */ "G_STRUCT_REF",
/* 19 */ "G_STRUCT_REF", /* 19 */ "G_UNIT",
/* 20 */ "G_ENDS", /* 20 */ "G_ENDS",
/* 21 */ "G_VALUE", /* 21 */ "G_VALUE",
/* 22 */ "G_STRING", /* 22 */ "G_STRING",
@ -963,121 +965,121 @@ static YYACTIONTYPE yy_reduce(
/********** Begin reduce actions **********************************************/ /********** Begin reduce actions **********************************************/
YYMINORTYPE yylhsminor; YYMINORTYPE yylhsminor;
case 0: /* stmt ::= expr G_ENDS */ case 0: /* stmt ::= expr G_ENDS */
#line 54 "grammar.lemon" #line 55 "grammar.lemon"
{ pEval->setRoot(yymsp[-1].minor.yy0); } { pEval->setRoot(yymsp[-1].minor.yy0); }
#line 969 "grammar.c" #line 971 "grammar.c"
break; break;
case 1: /* expr ::= G_VALUE */ case 1: /* expr ::= G_VALUE */
#line 57 "grammar.lemon" #line 58 "grammar.lemon"
{ yylhsminor.yy0.op = TR_NUMBER; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; } { yylhsminor.yy0.op = TR_NUMBER; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; }
#line 974 "grammar.c" #line 976 "grammar.c"
yymsp[0].minor.yy0 = yylhsminor.yy0; yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 2: /* expr ::= G_VALUE G_UNIT */ case 2: /* expr ::= G_VALUE G_UNIT */
#line 58 "grammar.lemon" #line 59 "grammar.lemon"
{ yylhsminor.yy0.op = TR_NUMBER; yylhsminor.yy0.value = yymsp[-1].minor.yy0.value; yylhsminor.yy0.leaf[0] = newNode( TR_UNIT, yymsp[0].minor.yy0.value.type, ""); yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; } { yylhsminor.yy0.op = TR_NUMBER; yylhsminor.yy0.value = yymsp[-1].minor.yy0.value; yylhsminor.yy0.leaf[0] = newNode( TR_UNIT, yymsp[0].minor.yy0.value.type, ""); yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; }
#line 980 "grammar.c" #line 982 "grammar.c"
yymsp[-1].minor.yy0 = yylhsminor.yy0; yymsp[-1].minor.yy0 = yylhsminor.yy0;
break; break;
case 3: /* expr ::= G_STRING */ case 3: /* expr ::= G_STRING */
#line 59 "grammar.lemon" #line 60 "grammar.lemon"
{ yylhsminor.yy0.op = TR_STRING; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; } { yylhsminor.yy0.op = TR_STRING; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; }
#line 986 "grammar.c" #line 988 "grammar.c"
yymsp[0].minor.yy0 = yylhsminor.yy0; yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 4: /* expr ::= G_IDENTIFIER */ case 4: /* expr ::= G_IDENTIFIER */
#line 60 "grammar.lemon" #line 61 "grammar.lemon"
{ yylhsminor.yy0.op = TR_IDENTIFIER; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; } { yylhsminor.yy0.op = TR_IDENTIFIER; yylhsminor.yy0.value = yymsp[0].minor.yy0.value; yylhsminor.yy0.leaf[0] = yylhsminor.yy0.leaf[1] = NULL; yylhsminor.yy0.valid = true; }
#line 992 "grammar.c" #line 994 "grammar.c"
yymsp[0].minor.yy0 = yylhsminor.yy0; yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 5: /* expr ::= expr G_LESS_THAN expr */ case 5: /* expr ::= expr G_LESS_THAN expr */
#line 61 "grammar.lemon" #line 62 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_LESS; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_LESS; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 998 "grammar.c" #line 1000 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 6: /* expr ::= expr G_GREATER_THAN expr */ case 6: /* expr ::= expr G_GREATER_THAN expr */
#line 62 "grammar.lemon" #line 63 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_GREATER; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_GREATER; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1004 "grammar.c" #line 1006 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 7: /* expr ::= expr G_LESS_EQUAL_THAN expr */ case 7: /* expr ::= expr G_LESS_EQUAL_THAN expr */
#line 63 "grammar.lemon" #line 64 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_LESS_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_LESS_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1010 "grammar.c" #line 1012 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 8: /* expr ::= expr G_GREATER_EQUAL_THAN expr */ case 8: /* expr ::= expr G_GREATER_EQUAL_THAN expr */
#line 64 "grammar.lemon" #line 65 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_GREATER_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_GREATER_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1016 "grammar.c" #line 1018 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 9: /* expr ::= expr G_NOT_EQUAL expr */ case 9: /* expr ::= expr G_NOT_EQUAL expr */
#line 65 "grammar.lemon" #line 66 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_NOT_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_NOT_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1022 "grammar.c" #line 1024 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 10: /* expr ::= expr G_BOOL_AND expr */ case 10: /* expr ::= expr G_BOOL_AND expr */
#line 66 "grammar.lemon" #line 67 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_BOOL_AND; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_BOOL_AND; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1028 "grammar.c" #line 1030 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 11: /* expr ::= expr G_BOOL_OR expr */ case 11: /* expr ::= expr G_BOOL_OR expr */
#line 67 "grammar.lemon" #line 68 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_BOOL_OR; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_BOOL_OR; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1034 "grammar.c" #line 1036 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 12: /* expr ::= expr G_PLUS expr */ case 12: /* expr ::= expr G_PLUS expr */
#line 68 "grammar.lemon" #line 69 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_ADD; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_ADD; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1040 "grammar.c" #line 1042 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 13: /* expr ::= expr G_MINUS expr */ case 13: /* expr ::= expr G_MINUS expr */
#line 69 "grammar.lemon" #line 70 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_SUB; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_SUB; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1046 "grammar.c" #line 1048 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 14: /* expr ::= expr G_MULT expr */ case 14: /* expr ::= expr G_MULT expr */
#line 70 "grammar.lemon" #line 71 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_MUL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_MUL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1052 "grammar.c" #line 1054 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 15: /* expr ::= expr G_DIVIDE expr */ case 15: /* expr ::= expr G_DIVIDE expr */
#line 71 "grammar.lemon" #line 72 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_DIV; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_DIV; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1058 "grammar.c" #line 1060 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 16: /* expr ::= expr G_EQUAL expr */ case 16: /* expr ::= expr G_EQUAL expr */
#line 72 "grammar.lemon" #line 73 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_OP_EQUAL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1064 "grammar.c" #line 1066 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 17: /* expr ::= expr G_STRUCT_REF expr */ case 17: /* expr ::= expr G_STRUCT_REF expr */
#line 74 "grammar.lemon" #line 75 "grammar.lemon"
{ yylhsminor.yy0.op = TR_STRUCT_REF; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; } { yylhsminor.yy0.op = TR_STRUCT_REF; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-2].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[0].minor.yy0); yylhsminor.yy0.valid=yymsp[-2].minor.yy0.valid && yymsp[0].minor.yy0.valid; }
#line 1070 "grammar.c" #line 1072 "grammar.c"
yymsp[-2].minor.yy0 = yylhsminor.yy0; yymsp[-2].minor.yy0 = yylhsminor.yy0;
break; break;
case 18: /* expr ::= G_PARENL expr G_PARENR */ case 18: /* expr ::= G_PARENL expr G_PARENR */
#line 76 "grammar.lemon" #line 77 "grammar.lemon"
{ yymsp[-2].minor.yy0.op = yymsp[-1].minor.yy0.op; yymsp[-2].minor.yy0.value = yymsp[-1].minor.yy0.value; yymsp[-2].minor.yy0.valid=yymsp[-1].minor.yy0.valid; yymsp[-2].minor.yy0.leaf[0] = yymsp[-1].minor.yy0.leaf[0]; yymsp[-2].minor.yy0.leaf[1] = yymsp[-1].minor.yy0.leaf[1]; } { yymsp[-2].minor.yy0.op = yymsp[-1].minor.yy0.op; yymsp[-2].minor.yy0.value = yymsp[-1].minor.yy0.value; yymsp[-2].minor.yy0.valid=yymsp[-1].minor.yy0.valid; yymsp[-2].minor.yy0.leaf[0] = yymsp[-1].minor.yy0.leaf[0]; yymsp[-2].minor.yy0.leaf[1] = yymsp[-1].minor.yy0.leaf[1]; }
#line 1076 "grammar.c" #line 1078 "grammar.c"
break; break;
case 19: /* expr ::= G_IDENTIFIER G_PARENL expr G_PARENR */ case 19: /* expr ::= G_IDENTIFIER G_PARENL expr G_PARENR */
#line 77 "grammar.lemon" #line 78 "grammar.lemon"
{ yylhsminor.yy0.op = TR_OP_FUNC_CALL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-3].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[-1].minor.yy0); yylhsminor.yy0.valid=1; } { yylhsminor.yy0.op = TR_OP_FUNC_CALL; yylhsminor.yy0.leaf[0] = copyNode(yymsp[-3].minor.yy0); yylhsminor.yy0.leaf[1] = copyNode(yymsp[-1].minor.yy0); yylhsminor.yy0.valid=1; }
#line 1081 "grammar.c" #line 1083 "grammar.c"
yymsp[-3].minor.yy0 = yylhsminor.yy0; yymsp[-3].minor.yy0 = yylhsminor.yy0;
break; break;
default: default:
@ -1144,10 +1146,10 @@ static void yy_syntax_error(
ParseCTX_FETCH ParseCTX_FETCH
#define TOKEN yyminor #define TOKEN yyminor
/************ Begin %syntax_error code ****************************************/ /************ Begin %syntax_error code ****************************************/
#line 38 "grammar.lemon" #line 39 "grammar.lemon"
pEval->parseError("Syntax error"); pEval->parseError("Syntax error");
#line 1151 "grammar.c" #line 1153 "grammar.c"
/************ End %syntax_error code ******************************************/ /************ End %syntax_error code ******************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
ParseCTX_STORE ParseCTX_STORE
@ -1173,10 +1175,10 @@ static void yy_accept(
/* Here code is inserted which will be executed whenever the /* Here code is inserted which will be executed whenever the
** parser accepts */ ** parser accepts */
/*********** Begin %parse_accept code *****************************************/ /*********** Begin %parse_accept code *****************************************/
#line 42 "grammar.lemon" #line 43 "grammar.lemon"
pEval->parseOk(); pEval->parseOk();
#line 1180 "grammar.c" #line 1182 "grammar.c"
/*********** End %parse_accept code *******************************************/ /*********** End %parse_accept code *******************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
ParseCTX_STORE ParseCTX_STORE

View File

@ -1,8 +1,8 @@
#define G_IDENTIFIER 1 #define G_IDENTIFIER 1
#define G_ASSIGN 2 #define G_ASSIGN 2
#define G_SEMCOL 3 #define G_SEMCOL 3
#define G_BOOL_OR 4 #define G_BOOL_AND 4
#define G_BOOL_AND 5 #define G_BOOL_OR 5
#define G_BOOL_XOR 6 #define G_BOOL_XOR 6
#define G_LESS_THAN 7 #define G_LESS_THAN 7
#define G_GREATER_THAN 8 #define G_GREATER_THAN 8
@ -10,13 +10,13 @@
#define G_GREATER_EQUAL_THAN 10 #define G_GREATER_EQUAL_THAN 10
#define G_EQUAL 11 #define G_EQUAL 11
#define G_NOT_EQUAL 12 #define G_NOT_EQUAL 12
#define G_UNIT 13 #define G_BOOL_NOT 13
#define G_BOOL_NOT 14 #define G_PLUS 14
#define G_PLUS 15 #define G_MINUS 15
#define G_MINUS 16 #define G_DIVIDE 16
#define G_DIVIDE 17 #define G_MULT 17
#define G_MULT 18 #define G_STRUCT_REF 18
#define G_STRUCT_REF 19 #define G_UNIT 19
#define G_ENDS 20 #define G_ENDS 20
#define G_VALUE 21 #define G_VALUE 21
#define G_STRING 22 #define G_STRING 22

View File

@ -21,14 +21,15 @@
%extra_argument { LIBEVAL::COMPILER* pEval } %extra_argument { LIBEVAL::COMPILER* pEval }
%nonassoc G_IDENTIFIER G_ASSIGN G_SEMCOL. %nonassoc G_IDENTIFIER G_ASSIGN G_SEMCOL.
%nonassoc G_BOOL_OR G_BOOL_AND G_BOOL_XOR. %left G_BOOL_AND.
%nonassoc G_LESS_THAN G_GREATER_THAN G_LESS_EQUAL_THAN G_GREATER_EQUAL_THAN. %left G_BOOL_OR.
%nonassoc G_EQUAL G_NOT_EQUAL. %left G_BOOL_XOR.
%right G_UNIT. %nonassoc G_LESS_THAN G_GREATER_THAN G_LESS_EQUAL_THAN G_GREATER_EQUAL_THAN G_EQUAL G_NOT_EQUAL.
%left G_BOOL_NOT. %right G_BOOL_NOT.
%left G_PLUS G_MINUS. %left G_PLUS G_MINUS.
%left G_DIVIDE G_MULT. %left G_DIVIDE G_MULT.
%nonassoc G_STRUCT_REF. %nonassoc G_STRUCT_REF.
%nonassoc G_UNIT.
%include { %include {
#include <assert.h> #include <assert.h>

View File

@ -49,7 +49,7 @@ namespace LIBEVAL
static void libeval_dbg( int level, const char* fmt, ... ) static void libeval_dbg( int level, const char* fmt, ... )
{ {
#ifdef DEBUG #ifdef DEBUG
if(level <= 10) // fixme: tom's debugging. if(level < 10) // fixme: tom's debugging.
{ {
va_list ap; va_list ap;
va_start( ap, fmt ); va_start( ap, fmt );
@ -409,8 +409,12 @@ bool COMPILER::lexDefault( COMPILER::T_TOKEN& aToken )
else if( m_tokenizer.MatchAhead( "==", []( int c ) -> bool { return c != '='; } ) ) else if( m_tokenizer.MatchAhead( "==", []( int c ) -> bool { return c != '='; } ) )
{ {
retval.token = G_EQUAL; retval.token = G_EQUAL;
m_tokenizer.NextChar( 2 );
}
else if( m_tokenizer.MatchAhead( "!=", []( int c ) -> bool { return c != '='; } ) )
{
retval.token = G_NOT_EQUAL;
m_tokenizer.NextChar( 2 ); m_tokenizer.NextChar( 2 );
//printf( "nc pos %d\n", m_tokenizer.GetPos() );
} }
else if( m_tokenizer.MatchAhead( "<=", []( int c ) -> bool { return c != '='; } ) ) else if( m_tokenizer.MatchAhead( "<=", []( int c ) -> bool { return c != '='; } ) )
{ {
@ -541,6 +545,11 @@ void dumpNode( std::string& buf, TREE_NODE* tok, int depth = 0 )
dumpNode( buf, tok->leaf[0], depth + 1 ); dumpNode( buf, tok->leaf[0], depth + 1 );
dumpNode( buf, tok->leaf[1], depth + 1 ); dumpNode( buf, tok->leaf[1], depth + 1 );
break; break;
case TR_OP_FUNC_CALL:
sprintf( str, "CALL '%s': ", tok->leaf[0]->value.str );
buf += str;
dumpNode( buf, tok->leaf[1], depth + 1 );
break;
case TR_UNIT: case TR_UNIT:
sprintf( str, "UNIT: %d ", tok->value.type ); sprintf( str, "UNIT: %d ", tok->value.type );
buf += str; buf += str;
@ -554,6 +563,12 @@ ERROR_STATUS COMPILER::GetErrorStatus()
return dummy; return dummy;
} }
void COMPILER::ReportError( const std::string aErrorMsg )
{
m_errorStatus.pendingError = true;
m_errorStatus.message = aErrorMsg;
}
void COMPILER::setRoot( TREE_NODE root ) void COMPILER::setRoot( TREE_NODE root )
{ {
m_tree = copyNode( root ); m_tree = copyNode( root );
@ -575,14 +590,21 @@ bool COMPILER::generateUCode( UCODE* aCode )
stack.push_back( m_tree ); stack.push_back( m_tree );
//printf("compile: tree %p\n", m_tree); std::string dump;
dumpNode( dump, m_tree, 0 );
libeval_dbg(3,"Tree: %s", dump.c_str() );
while( !stack.empty() ) while( !stack.empty() )
{ {
auto node = stack.back(); auto node = stack.back();
bool isTerminalNode = true; bool isTerminalNode = true;
// printf( "process node %p [op %d] [stack %d]\n", node, node->op, stack.size() );
libeval_dbg( 4, "process node %p [op %d] [stack %d]\n", node, node->op, stack.size() );
// process terminal nodes first // process terminal nodes first
switch( node->op ) switch( node->op )
@ -590,10 +612,54 @@ bool COMPILER::generateUCode( UCODE* aCode )
case TR_STRUCT_REF: case TR_STRUCT_REF:
{ {
assert( node->leaf[0]->op == TR_IDENTIFIER ); assert( node->leaf[0]->op == TR_IDENTIFIER );
assert( node->leaf[1]->op == TR_IDENTIFIER ); //assert( node->leaf[1]->op == TR_IDENTIFIER );
switch( node->leaf[1]->op )
{
case TR_IDENTIFIER:
{
auto vref = aCode->createVarRef( this, node->leaf[0]->value.str, node->leaf[1]->value.str );
if( m_errorStatus.pendingError )
{
printf("varref fail\n");
return false;
}
aCode->AddOp( TR_UOP_PUSH_VAR, vref );
break;
}
case TR_OP_FUNC_CALL:
{
//printf("got a method call... [%s], this = %s\n", node->leaf[1]->leaf[0]->value.str, node->leaf[0]->value.str);
auto vref = aCode->createVarRef( this, node->leaf[0]->value.str, "");
auto func = aCode->createFuncCall( this, node->leaf[1]->leaf[0]->value.str );
if(!func)
{
m_errorStatus.pendingError = true;
m_errorStatus.stage = ERROR_STATUS::CST_CODEGEN;
return false;
// fixme: generate a message
}
// printf("cfc4 test\n");
// func(nullptr, nullptr, nullptr);
aCode->AddOp( TR_OP_METHOD_CALL, func, vref );
isTerminalNode = false;
visitedNodes.insert( node );
visitedNodes.insert( node->leaf[0] );
//visitedNodes.insert( node->leaf[1]->leaf[1] );
break;
}
}
auto vref = aCode->createVarRef( this, node->leaf[0]->value.str, node->leaf[1]->value.str );
aCode->AddOp( TR_UOP_PUSH_VAR, vref );
break; break;
} }
@ -665,9 +731,15 @@ void UCODE::UOP::Exec( CONTEXT* ctx, UCODE* ucode )
ctx->Push( value ); ctx->Push( value );
break; break;
} }
case TR_UOP_PUSH_VALUE: case TR_UOP_PUSH_VALUE:
ctx->Push( reinterpret_cast<VALUE*>( m_arg ) ); ctx->Push( reinterpret_cast<VALUE*>( m_arg ) );
return; return;
case TR_OP_METHOD_CALL:
//printf("CALL METHOD %s\n" );
m_func( ucode, ctx, m_arg );
return;
default: default:
break; break;
} }