From: David Blasby Date: Tue, 27 Apr 2004 17:46:46 +0000 (+0000) Subject: bison -vd -p lwg_parse_yy wktparse.y X-Git-Tag: pgis_0_8_2~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6e7341adee50c299cc9fb7aeccbc9ca782eb879;p=postgis bison -vd -p lwg_parse_yy wktparse.y flex -Plwg_parse_yy -if -o'lex.yy.c' wktparse.lex Initial versions (from Ralph Mason) git-svn-id: http://svn.osgeo.org/postgis/trunk@514 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/wktparse.lex b/lwgeom/wktparse.lex new file mode 100644 index 000000000..463214131 --- /dev/null +++ b/lwgeom/wktparse.lex @@ -0,0 +1,47 @@ +/* + * Written by Ralph Mason ralph.masontelogis.com + * + * Copyright Telogis 2004 + * www.telogis.com + * + */ + +%x vals_ok +%{ +#include "wktparse.tab.h" + +static YY_BUFFER_STATE buf_state; + void init_parser(char *src) { BEGIN(0);buf_state = lwg_parse_yy_scan_string(src); } + void close_parser() { lwg_parse_yy_delete_buffer(buf_state); } + int lwg_parse_yywrap(void){ return 1; } + +%} + +%% + + +(-)?([0-9]*)?(\.[0-9]+([Ee](\+|-)?[0-9]+)?)? { lwg_parse_yylval.value=atof(lwg_parse_yytext); return VALUE; } + +00[0-9A-F]* { lwg_parse_yylval.wkb=lwg_parse_yytext; return WKB;} +01[0-9A-F]* { lwg_parse_yylval.wkb=lwg_parse_yytext; return WKB;} + +<*>POINT { return POINT; } +<*>LINESTRING { return LINESTRING; } +<*>POLYGON { return POLYGON; } +<*>MULTIPOINT { return MULTIPOINT; } +<*>MULTILINESTRING { return MULTILINESTRING; } +<*>MULTIPOLYGON { return MULTIPOLYGON; } +<*>GEOMETRYCOLLECTION { return GEOMETRYCOLLECTION; } +<*>SRID { BEGIN(vals_ok); return SRID; } +<*>EMPTY { return EMPTY; } + +<*>\( { BEGIN(vals_ok); return LPAREN; } +<*>\) { return RPAREN; } +<*>, { return COMMA ; } +<*>= { return EQUALS ; } +<*>; { BEGIN(0); return SEMICOLON; } +<*>[ \t\n\r]+ /*eat whitespace*/ +<*>. { return lwg_parse_yytext[0]; } + +%% + diff --git a/lwgeom/wktparse.y b/lwgeom/wktparse.y new file mode 100644 index 000000000..0d6ba25fc --- /dev/null +++ b/lwgeom/wktparse.y @@ -0,0 +1,121 @@ +/* + * Written by Ralph Mason ralph.masontelogis.com + * + * Copyright Telogis 2004 + * www.telogis.com + * + */ + +%{ +#include "wktparse.h" + +%} + +%start geometry + +%union { + double value; + const char* wkb; +} + +%token POINT LINESTRING POLYGON MULTIPOINT MULTILINESTRING MULTIPOLYGON GEOMETRYCOLLECTION +%token SRID +%token EMPTY +%token VALUE +%token LPAREN RPAREN COMMA EQUALS SEMICOLON +%token WKB + +%% + +geometry : srid SEMICOLON { alloc_lwgeom(srid); } geometry_int + | { alloc_lwgeom(-1); } geometry_int ; + +geometry_int : geom_wkb | geom_point | geom_linestring | geom_polygon | geom_multipoint + | geom_multilinestring | geom_multipolygon| geom_geometrycollection; + +srid : SRID EQUALS VALUE { set_srid($3); } ; + +geom_wkb : WKB {alloc_wkb($1) ; } ; + + +/* POINT */ + +geom_point : POINT point ; + +point : { alloc_point(); } point_int { pop();} ; + +point_int : empty | LPAREN a_point RPAREN; + +/* MULTIPOINT */ + +geom_multipoint : MULTIPOINT { alloc_multipoint(); } multipoint { pop();}; + +multipoint : empty | { alloc_counter(); } LPAREN multipoint_int RPAREN {pop();} ; + +multipoint_int : mpoint | multipoint_int COMMA mpoint; + +mpoint : point | { alloc_point(); } a_point { pop();} ; + + +/* LINESTRING */ + +geom_linestring : LINESTRING linestring; + +linestring : { alloc_linestring(); } linestring_1 {pop();} ; + +linestring_1 : empty | { alloc_counter(); } LPAREN linestring_int RPAREN {popc(); }; + +linestring_int : a_point | linestring_int COMMA a_point; + +/* MULTILINESTRING */ + +geom_multilinestring : MULTILINESTRING { alloc_multilinestring(); } multilinestring { pop();} ; + +multilinestring : empty | { alloc_counter(); } LPAREN multilinestring_int RPAREN{ pop();} ; + +multilinestring_int : linestring | multilinestring_int COMMA linestring; + + +/* POLYGON */ + +geom_polygon : POLYGON polygon; + +polygon : { alloc_polygon(); } polygon_1 { pop();} ; + +polygon_1 : empty | { alloc_counter(); } LPAREN polygon_int RPAREN { pop();} ; + +polygon_int : linestring_1 | polygon_int COMMA linestring_1; + +/* MULTIPOLYGON */ + +geom_multipolygon : MULTIPOLYGON { alloc_multipolygon(); } multipolygon { pop();}; + +multipolygon : empty | { alloc_counter(); } LPAREN multipolygon_int RPAREN { pop();} ; + +multipolygon_int : polygon | multipolygon_int COMMA polygon; + + + +/* GEOMETRYCOLLECTION */ + +geom_geometrycollection : GEOMETRYCOLLECTION { alloc_geomertycollection(); } geometrycollection { pop();} ; + +geometrycollection : empty | { alloc_counter(); } LPAREN geometrycollection_int RPAREN { pop();} ; + +geometrycollection_int : geometry_int | geometrycollection_int COMMA geometry_int; + + +a_point : point_2d | point_3d | point_4d ; + +point_2d : VALUE VALUE {alloc_point_2d($1,$2) }; + +point_3d : VALUE VALUE VALUE {alloc_point_3d($1,$2,$3) }; + +point_4d : VALUE VALUE VALUE VALUE {alloc_point_4d($1,$2,$3,$4) }; + +empty : EMPTY {alloc_empty() } ; +%% + + + +