Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-socketcan]: src/external/bsd/bc/dist 2109065



details:   https://anonhg.NetBSD.org/src/rev/6209388bec24
branches:  bouyer-socketcan
changeset: 820861:6209388bec24
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 10 15:13:05 2017 +0000

description:
2109065

diffstat:

 external/bsd/bc/dist/bc.y |  799 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 799 insertions(+), 0 deletions(-)

diffs (truncated from 803 to 300 lines):

diff -r 24af496aac45 -r 6209388bec24 external/bsd/bc/dist/bc.y
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/bc/dist/bc.y Mon Apr 10 15:13:05 2017 +0000
@@ -0,0 +1,799 @@
+/*     $NetBSD: bc.y,v 1.2.2.2 2017/04/10 15:13:05 christos Exp $ */
+
+/*
+ * Copyright (C) 1991-1994, 1997, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
+ * Copyright (C) 2016-2017 Philip A. Nelson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The names Philip A. Nelson and Free Software Foundation may not be
+ *    used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY PHILIP A. NELSON ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL PHILIP A. NELSON OR THE FREE SOFTWARE FOUNDATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* bc.y: The grammar for a POSIX compatable bc processor with some
+         extensions to the language. */
+
+%{
+
+#include "bcdefs.h"
+#include "global.h"
+#include "proto.h"
+
+/* current function number. */
+int cur_func = -1;
+
+/* Expression encoded information -- See comment at expression rules. */
+#define EX_ASSGN 0 
+#define EX_REG   1
+#define EX_COMP  2
+#define EX_PAREN 4
+#define EX_VOID  8 
+#define EX_EMPTY 16
+
+%}
+
+%start program
+
+%union {
+       char     *s_value;
+       char      c_value;
+       int       i_value;
+       arg_list *a_value;
+       }
+
+/* Extensions over POSIX bc.
+   a) NAME was LETTER.  This grammar allows longer names.
+      Single letter names will still work.
+   b) Relational_expression allowed only one comparison.
+      This grammar has added boolean expressions with
+      && (and) || (or) and ! (not) and allowed all of them in
+      full expressions.
+   c) Added an else to the if.
+   d) Call by variable array parameters
+   e) read() procedure that reads a number under program control from stdin.
+   f) halt statement that halts the the program under program control.  It
+      is an executed statement.
+   g) continue statement for for loops.
+   h) optional expressions in the for loop.
+   i) print statement to print multiple numbers per line.
+   j) warranty statement to print an extended warranty notice.
+   k) limits statement to print the processor's limits.
+   l) void functions.
+*/
+
+%token <i_value> ENDOFLINE AND OR NOT
+%token <s_value> STRING NAME NUMBER
+/*     '-', '+' are tokens themselves          */
+/*     '=', '+=',  '-=', '*=', '/=', '%=', '^=' */
+%token <c_value> ASSIGN_OP
+/*     '==', '<=', '>=', '!=', '<', '>'        */
+%token <s_value> REL_OP
+/*     '++', '--'                              */
+%token <c_value> INCR_DECR
+/*     'define', 'break', 'quit', 'length'     */
+%token <i_value> Define    Break    Quit    Length
+/*     'return', 'for', 'if', 'while', 'sqrt', 'else'  */
+%token <i_value> Return    For    If    While    Sqrt   Else
+/*     'scale', 'ibase', 'obase', 'auto', 'read', 'random'     */
+%token <i_value> Scale Ibase Obase Auto    Read    Random
+/*     'warranty', 'halt', 'last', 'continue', 'print', 'limits'   */
+%token <i_value> Warranty  Halt  Last  Continue  Print  Limits
+/*     'history', 'void' */
+%token <i_value> UNARY_MINUS HistoryVar Void
+
+
+/* Types of all other things. */
+%type <i_value> expression return_expression named_expression opt_expression
+%type <c_value> '+' '-' '*' '/' '%' 
+%type <a_value> opt_parameter_list opt_auto_define_list define_list
+%type <a_value> opt_argument_list argument_list
+%type <i_value> program input_item semicolon_list statement_list
+%type <i_value> statement function statement_or_error required_eol
+%type <i_value> opt_void
+
+/* precedence */
+%left OR
+%left AND
+%nonassoc NOT
+%left REL_OP
+%right ASSIGN_OP
+%left '+' '-'
+%left '*' '/' '%'
+%right '^'
+%nonassoc UNARY_MINUS
+%nonassoc INCR_DECR
+
+%%
+program                        : /* empty */
+                           {
+                             $$ = 0;
+                             if (interactive && !quiet)
+                               {
+                                 show_bc_version ();
+                                 welcome ();
+                               }
+                           }
+                       | program input_item
+                       ;
+input_item             : semicolon_list ENDOFLINE
+                           { run_code (); }
+                       | function
+                           { run_code (); }
+                       | error ENDOFLINE
+                           {
+                             yyerrok;
+                             init_gen ();
+                           }
+                       ;
+opt_newline            : /* empty */
+                       | ENDOFLINE
+                           { ct_warn ("newline not allowed"); }
+                       ;
+semicolon_list         : /* empty */
+                           { $$ = 0; }
+                       | statement_or_error
+                       | semicolon_list ';' statement_or_error
+                       | semicolon_list ';'
+                       ;
+statement_list         : /* empty */
+                           { $$ = 0; }
+                       | statement_or_error
+                       | statement_list ENDOFLINE
+                       | statement_list ENDOFLINE statement_or_error
+                       | statement_list ';'
+                       | statement_list ';' statement
+                       ;
+statement_or_error     : statement
+                       | error statement
+                           { $$ = $2; }
+                       ;
+statement              : Warranty
+                           { warranty (""); }
+                       | Limits
+                           { limits (); }
+                       | expression
+                           {
+                             if ($1 & EX_COMP)
+                               ct_warn ("comparison in expression");
+                             if ($1 & EX_REG)
+                               generate ("W");
+                             else 
+                               generate ("p");
+                           }
+                       | STRING
+                           {
+                             $$ = 0;
+                             generate ("w");
+                             generate ($1);
+                             free ($1);
+                           }
+                       | Break
+                           {
+                             if (break_label == 0)
+                               yyerror ("Break outside a for/while");
+                             else
+                               {
+                                 snprintf (genstr, genlen, "J%1d:",
+                                           break_label);
+                                 generate (genstr);
+                               }
+                           }
+                       | Continue
+                           {
+                             ct_warn ("Continue statement");
+                             if (continue_label == 0)
+                               yyerror ("Continue outside a for");
+                             else
+                               {
+                                 snprintf (genstr, genlen, "J%1d:", 
+                                           continue_label);
+                                 generate (genstr);
+                               }
+                           }
+                       | Quit
+                           { bc_exit (0); }
+                       | Halt
+                           { generate ("h"); }
+                       | Return return_expression
+                           { generate ("R"); }
+                       | For 
+                           {
+                             $1 = break_label; 
+                             break_label = next_label++;
+                           }
+                         '(' opt_expression ';'
+                           {
+                             if ($4 & EX_COMP)
+                               ct_warn ("Comparison in first for expression");
+                             if ($4 & EX_VOID)
+                               yyerror ("first expression is void");
+                             if (!($4 & EX_EMPTY))
+                               generate ("p");
+                             $4 = next_label++;
+                             snprintf (genstr, genlen, "N%1d:", $4);
+                             generate (genstr);
+                           }
+                         opt_expression ';'
+                           {
+                             if ($7 & EX_VOID)
+                               yyerror ("second expression is void");
+                             if ($7 & EX_EMPTY ) generate ("1");
+                             $7 = next_label++;
+                             snprintf (genstr, genlen, "B%1d:J%1d:", $7,
+                                       break_label);
+                             generate (genstr);
+                             $<i_value>$ = continue_label;
+                             continue_label = next_label++;
+                             snprintf (genstr, genlen, "N%1d:", 
+                                       continue_label);
+                             generate (genstr);
+                           }
+                         opt_expression ')'
+                           {
+                             if ($10 & EX_COMP)
+                               ct_warn ("Comparison in third for expression");
+                             if ($10 & EX_VOID)
+                               yyerror ("third expression is void");
+                             if ($10 & EX_EMPTY)
+                               snprintf (genstr, genlen, "J%1d:N%1d:", $4, $7);
+                             else
+                               snprintf (genstr, genlen, "pJ%1d:N%1d:", $4, $7);
+                             generate (genstr);
+                           }
+                         opt_newline statement
+                           {
+                             snprintf (genstr, genlen, "J%1d:N%1d:",
+                                      continue_label, break_label);
+                             generate (genstr);
+                             break_label = $1;
+                             continue_label = $<i_value>9;
+                           }
+                       | If '(' expression ')' 
+                           {
+                             if ($3 & EX_VOID)
+                               yyerror ("void expression");
+                             $3 = if_label;
+                             if_label = next_label++;
+                             snprintf (genstr, genlen, "Z%1d:", if_label);
+                             generate (genstr);
+                           }
+                         opt_newline statement  opt_else
+                           {
+                             snprintf (genstr, genlen, "N%1d:", if_label); 
+                             generate (genstr);
+                             if_label = $3;
+                           }
+                       | While 
+                           {
+                             $1 = continue_label;
+                             continue_label = next_label++;
+                             snprintf (genstr, genlen, "N%1d:", 
+                                       continue_label);
+                             generate (genstr);
+                           }
+                       '(' expression 
+                           {



Home | Main Index | Thread Index | Old Index