// %expect 3 %{ // // tikzparser.y // TikZiT // // Copyright 2010 Chris Heunen. All rights reserved. // // // This file is part of TikZiT. // // TikZiT is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // TikZiT is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with TikZiT. If not, see . // #include #include #import #import "TikzGraphAssembler.h" #import "GraphElementProperty.h" extern char* yystr; extern int yylineno; extern int tokenpos; extern int yylex(void); extern void yyerror(const char *str); %} %union { NSPoint pt; NSString *nsstr; }; %error-verbose %token LATEXBEGIN %token LATEXEND %token TIKZPICTURE %token PGFONLAYER %token LEFTPARENTHESIS %token RIGHTPARENTHESIS %token LEFTBRACKET %token RIGHTBRACKET %token SEMICOLON %token COMMA %token FULLSTOP %token EQUALS %token DRAW %token TO %token NODE %token RECTANGLE %token PATH %token ALTNODE %token AT %token REALNUMBER %token NATURALNUMBER %token LWORD %token DELIMITEDSTRING %type nodename %type anchor %type optanchor %type nodeid %type coords %type propsym %type propsyms %type val %type number %% tikzpicture: LATEXBEGIN TIKZPICTURE optproperties expressions LATEXEND TIKZPICTURE; expressions: expressions expression | ; expression: node | edge | boundingbox | ignore; ignore: LATEXBEGIN PGFONLAYER DELIMITEDSTRING | LATEXEND PGFONLAYER; number: REALNUMBER { $$ = $1; } | NATURALNUMBER { $$ = $1; }; optproperties: LEFTBRACKET properties RIGHTBRACKET | ; properties: property extraproperties; extraproperties: COMMA property extraproperties | property extraproperties | ; property: val EQUALS val { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; GraphElementProperty *p = [[GraphElementProperty alloc] initWithPropertyValue:$3 forKey:$1]; [[a data] addObject:p]; [p release]; } | val { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; GraphElementProperty *p = [[GraphElementProperty alloc] initWithAtomName:$1]; [[a data] addObject:p]; [p release]; }; val: propsyms { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; propsyms: propsym { $$ = $1; } | propsyms propsym { NSString *s = [$1 stringByAppendingFormat:@" %@", $2]; $$ = s; }; propsym: LWORD { $$ = $1; } | number { $$ = $1; } | TO { $$ = @"to"; } | ALTNODE { $$ = @"node"; } | RECTANGLE { $$ = @"rectangle"; } | AT { $$ = @"at"; } | FULLSTOP { $$ = @"."; }; nodecmd : NODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; nodename: LEFTPARENTHESIS nodeid RIGHTPARENTHESIS { $$ = $2; }; node: nodecmd optproperties nodename AT coords nodelabel SEMICOLON { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [[a currentNode] setName:$3]; [[a currentNode] setPoint:$5]; [a finishNode]; }; nodelabel: DELIMITEDSTRING { Node *n = [[TikzGraphAssembler currentAssembler] currentNode]; [n setLabel:$1]; } anchor: LWORD { $$ = $1; } | NATURALNUMBER { $$ = $1; }; optanchor: { $$ = @""; } | FULLSTOP anchor { $$ = $2; }; source: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeSource:$2 anchor:$3]; }; nodeid: LWORD { $$ = $1; } | NATURALNUMBER { $$ = $1; }; coords: LEFTPARENTHESIS number COMMA number RIGHTPARENTHESIS { $$ = NSMakePoint([$2 floatValue], [$4 floatValue]); }; edgecmd : DRAW { [[TikzGraphAssembler currentAssembler] prepareEdge]; }; edge: edgecmd optproperties source TO optedgenode target SEMICOLON { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a finishEdge]; }; target: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeTarget:$2 anchor:$3]; } | selfloop { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeTarget:@"" anchor:@""]; }; selfloop: LEFTPARENTHESIS RIGHTPARENTHESIS; altnodecmd: ALTNODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; optedgenode: | altnodecmd optproperties nodelabel { [[TikzGraphAssembler currentAssembler] finishNode]; } bbox_ignoreprops: | LEFTBRACKET LWORD LWORD LWORD LWORD RIGHTBRACKET; boundingbox: PATH bbox_ignoreprops coords RECTANGLE coords SEMICOLON { Graph *g = [[TikzGraphAssembler currentAssembler] graph]; [g setBoundingBox:NSRectAroundPoints($3, $5)]; }; /* vi:ft=yacc:noet:ts=4:sts=4:sw=4 */