r5352 - developers/werner/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Fri Jul 31 18:39:51 CEST 2009


Author: werner
Date: 2009-07-31 18:39:51 +0200 (Fri, 31 Jul 2009)
New Revision: 5352

Modified:
   developers/werner/fped/README
   developers/werner/fped/TODO
   developers/werner/fped/fpd.l
   developers/werner/fped/fpd.y
   developers/werner/fped/qfn.fpd
Log:
syntax cleanup:
- keywords no longer begin with a dot
- variable assignments must begin with the keyword "set", e.g., set a = 5
- vectors must begin with the keyword "vec", e.g., vec @(1mm, 2mm)
- named points use <name>: instead of <name> =, e.g., pos: vec @(1mm, 2mm)
- loops use the keyword "loop", not "set"



Modified: developers/werner/fped/README
===================================================================
--- developers/werner/fped/README	2009-07-31 15:52:32 UTC (rev 5351)
+++ developers/werner/fped/README	2009-07-31 16:39:51 UTC (rev 5352)
@@ -36,8 +36,8 @@
 
 Units can be mixed in calculations, e.g.,
 
-a = 1mm+20mil
-b = 10*1mm
+set a = 1mm+20mil
+set b = 10*1mm
 
 All values used as dimensions must be either mm or mil.
 
@@ -47,21 +47,21 @@
 
 Vectors can be anonymous or they can be named for future reference:
 
-<base> ( <x-expr>, <y-expr> )
-<identifier> = <base>  ( <x-expr>, <y-expr> )
+vec <base> ( <x-expr>, <y-expr> )
+<identifier>: vec <base>  ( <x-expr>, <y-expr> )
 
 The base can be one of the following items:
 
-- @: the origin of the frame containing the vector
-- .: the end of the previous vector in this frame
-- <identifier>: the name of a previous vector in the same frame
+- @ is the origin of the frame containing the vector
+- . is the end of the previous vector in this frame
+- <identifier> is the name of a previous vector in the same frame
 
 The following example would draw the line described in the previous
 section:
 
-a = @(1mm, 1mm)
-b = .(1mm, 1mm)
-.line a b
+a: vec @(1mm, 1mm)
+b: vec .(1mm, 1mm)
+line a b
 
 
 Silk screen objects
@@ -74,7 +74,7 @@
 
 A line connects two points:
 
-.line <point-a> <point-b>
+line <point-a> <point-b>
 
 The points can be specified with @, ., and an identifier, just like
 a vector base.
@@ -82,30 +82,30 @@
 A rectangle has sides parallel to the x and y axis and is defined
 by two diagonally opposite corners:
 
-.rect <point-a> <point-b>
+rect <point-a> <point-b>
 
 A circle is defined by its center and a point on the circle:
 
-.circ <center> <point>
+circ <center> <point>
 
 This example draws a unit circle:
 
-@(1mm, 0mm)
-.circ @ .
+vec @(1mm, 0mm)
+circ @ .
 
 An arc is like a circle, but the part of the circle drawn is determined
 by two points. The first point determines the radius and the starting
 angle. The second point only determines the end angle but its distance
 from the center is ignored.
 
-.arc <center> <radius> <end>
+arc <center> <radius> <end>
 
 The arc is drawn in a counter-clockwise direction. The following example
 draws an arc of the unit circle in the x > 0, y > 0 quadrant:
 
-from = @(1mm, 0mm)
-to = @(0mm, 1mm)
-.arc @ from to
+from: vec @(1mm, 0mm)
+to: vec @(0mm, 1mm)
+arc @ from to
 
 
 Pads
@@ -113,15 +113,15 @@
 
 Pads are similar to rectangles, but they also have a name.
 
-.pad "<name>" <point-a> <point-b>
+pad "<name>" <point-a> <point-b>
 
 Variables can be expanded in a pad's name by prefixing their name with
 a dollar sign. The ${name} syntax is also available.
 
 Example:
 
-@(1mm, 1mm)
-.pad "1" @ .
+vec @(1mm, 1mm)
+pad "1" @ .
 
 
 Frames
@@ -130,13 +130,13 @@
 Frames are used to group things and to reuse them multiple times. Frames
 must be defined before they can be used:
 
-.frame <name> {
+frame <name> {
     ... items ...
 }
 
 Once defined, a frame is placed at a given location with
 
-.frame <name> <point>
+frame <name> <point>
 
 The frame definitions must precede all other items in a footprint
 description. Frames cannot be defined inside other frames, but frames
@@ -145,15 +145,15 @@
 For example, this puts two unity squares, one centered at (0 mm, 0 mm),
 the other at (2 mm, 0 mm):
 
-.frame unit_square {
-	a = @(-0.5mm, -0.5mm)
-	b = .(1mm, 1mm)
-	.rect a b
+frame unit_square {
+	a: vec @(-0.5mm, -0.5mm)
+	b: vec .(1mm, 1mm)
+	rect a b
 }
 
-.frame unit_square @
-@(2mm, 0mm)
-.frame unit_square .
+frame unit_square @
+vec @(2mm, 0mm)
+frame unit_square .
 
 
 Names and variables
@@ -176,8 +176,8 @@
 
 Note that names cannot be redefined. E.g., this does not work:
 
-a = 1
-a = a+1
+set a = 1
+set a = a+1
 
 The names spaces of frames, vectors, variables, and pads are separate
 from each other.
@@ -189,11 +189,11 @@
 A variable with a single value is defined with the usual C-like
 assignment syntax:
 
-<identifier> = <expression>
+set <identifier> = <expression>
 
 Example:
 
-a = b+2
+set a = b+2
 
 
 Loops
@@ -201,16 +201,16 @@
 
 A loop is a variable with a range of values:
 
-<identifier> = <from>, <to>
+loop <identifier> = <from>, <to>
 
 The variable assumes all the values i for <from> <= i <= <to>, in
 increments of one. E.g.,
 
-n = 1, 3
+loop n = 1, 3
 
 and
 
-n = 1, 3
+loop n = 1, 3
 
 both assigns the values 1, 2, and 3 to the variable "n".
 
@@ -222,9 +222,9 @@
 The following example draws three concentric circles around the
 origin, with radii 1, 2, and 3:
 
-x = 1, 3
-@(x*1mm, 0mm)
-.circ @ .
+loop x = 1, 3
+vec @(x*1mm, 0mm)
+circ @ .
 
 
 Tables
@@ -235,7 +235,7 @@
 variable names, followed by one or more rows with values. Rows are
 enclosed in curly braces and their elements are separated by commas.
 
-.table
+table
     { <identifier>, ... }
     { <expression>, ... }
     ...
@@ -243,20 +243,20 @@
 Like loops, tables are iterated to generate objects. The following
 example is equivalent to the one in the previous section:
 
-.table
+table
     { x }
     { 1mm }
     { 2mm }
     { 3mm }
-@(x, 0mm)
-.circ @ .
+vec @(x, 0mm)
+circ @ .
 
 Note that we can set the unit of the values directly in this case.
 
 Iteration is performed over rows. All variables of the table are set
 to the value in the respective row at the same time. For example, in
 
-.table
+table
     { x, y }
     { 1, 2 }
     { 3, 4 }

Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO	2009-07-31 15:52:32 UTC (rev 5351)
+++ developers/werner/fped/TODO	2009-07-31 16:39:51 UTC (rev 5352)
@@ -15,7 +15,6 @@
 - add incremental expression parser (for editor)
 - add default unit (combine with grid unit selection ?)
 - consider adding auto/mm/mil selection for each dimension
-- syntax seems a little cryptic. too many dots and at signs.
 - add measurements
 - Q: allow reassignment of vector names ? (no: would cause confusion in GUI)
 - add KiCad output

Modified: developers/werner/fped/fpd.l
===================================================================
--- developers/werner/fped/fpd.l	2009-07-31 15:52:32 UTC (rev 5351)
+++ developers/werner/fped/fpd.l	2009-07-31 16:39:51 UTC (rev 5352)
@@ -21,9 +21,16 @@
 
 #include "y.tab.h"
 
+
+static int disable_keywords = 0;
+static int is_table = 0;
+
 %}
 
 
+/* keywords are only accepted at the beginning of a line */
+%s NOKEYWORD
+
 NUM	[0-9]+\.?[0-9]*
 SP	[\t ]*
 
@@ -31,14 +38,32 @@
 %%
 
 
-".frame"			return TOK_FRAME;
-".table"			return TOK_TABLE;
-".pad"				return TOK_PAD;
-".rect"				return TOK_RECT;
-".line"				return TOK_LINE;
-".circ"				return TOK_CIRC;
-".arc"				return TOK_ARC;
+<INITIAL>"set"			{ BEGIN(NOKEYWORD);
+				  return TOK_SET; }
+<INITIAL>"loop"			{ BEGIN(NOKEYWORD);
+				  return TOK_LOOP; }
+<INITIAL>"frame"		{ BEGIN(NOKEYWORD);
+				  is_table = 0;
+				  return TOK_FRAME; }
+<INITIAL>"table"		{ BEGIN(NOKEYWORD);
+				  is_table = 1;
+				  return TOK_TABLE; }
+<INITIAL>"vec"			{ BEGIN(NOKEYWORD);
+				  return TOK_VEC; }
+<INITIAL>"pad"			{ BEGIN(NOKEYWORD);
+				  return TOK_PAD; }
+<INITIAL>"rect"			{ BEGIN(NOKEYWORD);
+				  return TOK_RECT; }
+<INITIAL>"line"			{ BEGIN(NOKEYWORD);
+				  return TOK_LINE; }
+<INITIAL>"circ"			{ BEGIN(NOKEYWORD);
+				  return TOK_CIRC; }
+<INITIAL>"arc"			{ BEGIN(NOKEYWORD);
+				  return TOK_ARC; }
 
+[a-zA-Z_][a-zA-Z_0-9]*:		{ *strchr(yytext, ':') = 0;
+				  yylval.id = unique(yytext);
+				  return LABEL; }
 [a-zA-Z_][a-zA-Z_0-9]*		{ yylval.id = unique(yytext);
 				  return ID; }
 
@@ -60,8 +85,19 @@
 				  return STRING; }
 
 {SP}				;
-\n				lineno++;
+\n				{ if (!disable_keywords)
+					BEGIN(INITIAL);
+				  lineno++; }
 
-^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n lineno = strtol(yytext+2, NULL, 0);
+"{"				{ BEGIN(NOKEYWORD);
+				  disable_keywords = is_table;
+				  return '{'; }
+"}"				{ disable_keywords = 0;
+				  return '}'; }
 
+^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
+				  if (!disable_keywords)
+				  	BEGIN(INITIAL);
+				  lineno = strtol(yytext+2, NULL, 0); }
+
 .				return *yytext;

Modified: developers/werner/fped/fpd.y
===================================================================
--- developers/werner/fped/fpd.y	2009-07-31 15:52:32 UTC (rev 5351)
+++ developers/werner/fped/fpd.y	2009-07-31 16:39:51 UTC (rev 5352)
@@ -122,12 +122,12 @@
 };
 
 
-%token		TOK_FRAME TOK_TABLE
+%token		TOK_SET TOK_LOOP TOK_FRAME TOK_TABLE TOK_VEC
 %token		TOK_PAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
 
 %token	<num>	NUMBER
 %token	<str>	STRING
-%token	<id>	ID
+%token	<id>	ID LABEL
 
 %type	<table>	table
 %type	<var>	vars var
@@ -135,7 +135,6 @@
 %type	<value>	row value
 %type	<vec>	vec base
 %type	<obj>	obj
-%type	<expr>	opt_range
 %type	<expr>	expr add_expr mult_expr unary_expr primary_expr
 
 %%
@@ -187,19 +186,20 @@
 
 frame_item:
 	table
-	| ID '=' expr opt_range
+	| TOK_SET ID '=' expr
 		{
-			if ($4)
-				make_loop($1, $3, $4);
-			else
-				make_var($1, $3);
+			make_var($2, $4);
 		}
+	| TOK_LOOP ID '=' expr ',' expr
+		{
+			make_loop($2, $4, $6);
+		}
 	| vec
-	| ID '=' vec
+	| LABEL vec
 		{
 			if (find_vec($1))
 				yyerrorf("duplicate vector \"%s\"", $1);
-			$3->name = $1;
+			$2->name = $1;
 		}
 	| obj
 		{
@@ -208,16 +208,6 @@
 		}
 	;
 
-opt_range:
-		{
-			$$ = NULL;
-		}
-	| ',' expr
-		{
-			$$ = $2;
-		}
-	;
-
 table:
 	TOK_TABLE
 		{
@@ -310,15 +300,15 @@
 	;
 
 vec:
-	base '(' expr ',' expr ')'
+	TOK_VEC base '(' expr ',' expr ')'
 		{
 			$$ = alloc_type(struct vec);
 			$$->name = NULL;
-			$$->base = $1;
-			if ($1)
-				$1->n_refs++;
-			$$->x = $3;
-			$$->y = $5;
+			$$->base = $2;
+			if ($2)
+				$2->n_refs++;
+			$$->x = $4;
+			$$->y = $6;
 			$$->n_refs = 0;
 			$$->next = NULL;
 			last_vec = $$;

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd	2009-07-31 15:52:32 UTC (rev 5351)
+++ developers/werner/fped/qfn.fpd	2009-07-31 16:39:51 UTC (rev 5352)
@@ -7,23 +7,23 @@
  * http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
  */
 
-.frame pad_up {
-	c = @(-D/2, 0mm)
-	.(D, C)
-	pad = n+1
-	.pad "$pad" c .
+frame pad_up {
+	c: vec @(-D/2, 0mm)
+	vec .(D, C)
+	set pad = n+1
+	pad "$pad" c .
 }
 
-.frame pads {
-	n = 0, N/4-1
+frame pads {
+	loop n = 0, N/4-1
 
-	@(P*(n-(N/4-1)/2), -Ay/2)
-	.frame pad_up .
+	vec @(P*(n-(N/4-1)/2), -Ay/2)
+	frame pad_up .
 
 }
 
 
-N = 24
+set N = 24
 
 /*
  * Note that this table is not a great example because it contains lots of
@@ -31,30 +31,30 @@
  * the GUI to extremes.
  */
 
-.table
+table
     { P, Ax, Ay, Bx, By, C, D, SLx, SLy, SPx_tot, SPy_tot, SPx, SPy, Gx, Gy, Hx, Hy }
     { 0.5mm, 5mm, 5mm, 3.2mm, 3.2mm, 0.9mm, 0.24mm, 2.1mm, 2.1mm, 1.2mm,
       1.2mm, 0.45mm, 0.45mm, 4.3mm, 4.3mm, 5.25mm, 5.25mm }
 
-h_x0y0 = @(-Hx/2, -Hy/2)
-h_x1y1 = .(Hx, Hy)
-.rect h_x0y0 h_x1y1
+h_x0y0: vec @(-Hx/2, -Hy/2)
+h_x1y1: vec .(Hx, Hy)
+rect h_x0y0 h_x1y1
 
-g_x0y0 = @(-Gx/2, -Gy/2)
-g_x1y1 = .(Gx, Gy)
-.rect g_x0y0 g_x1y1
+g_x0y0: vec @(-Gx/2, -Gy/2)
+g_x1y1: vec .(Gx, Gy)
+rect g_x0y0 g_x1y1
 
-.frame pads @
+frame pads @
 
 // ARC, just for testing
 
-c = @(-1mm, 1mm)
-r = c(0mm, 0.5mm)
-e = c(-0.5mm, 0mm)
-.arc c r e
+c: vec @(-1mm, 1mm)
+r: vec c(0mm, 0.5mm)
+e: vec c(-0.5mm, 0mm)
+arc c r e
 
-r2 = c(0mm, 0.8mm)
-.circ c r2
+r2: vec c(0mm, 0.8mm)
+circ c r2
 
 /*
 x1 = 1+2*3




More information about the commitlog mailing list