;;; wisent-calc.wy --- Grammar of the infix notation calculator ;; Copyright (C) 2002, 2003 David Ponce ;; Author: David Ponce ;; Maintainer: David Ponce ;; Created: 19 Feb 2002 ;; Keywords: syntax ;; X-RCS: $Id: wisent-calc.wy,v 1.1 2007-11-26 15:12:29 michaels Exp $ ;; This file is not part of GNU Emacs. ;; This program 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 2, or (at ;; your option) any later version. ;; This program 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 this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; This is a port of the Bison 1.28d Infix Calc sample program to the ;; Elisp LALR parser Wisent. It illustrates usage of operator ;; precedence and contextual precedence. Implementation is in the ;; file wisent-calc.el. ;;; History: ;; ;;%package wisent-calc-wy %token NUM %nonassoc '=' ;; comparison %left '-' '+' %left '*' '/' %left NEG ;; negation--unary minus %right '^' ;; exponentiation %% input: line | input line (format "%s %s" $1 $2) ; line: ';' {";"} | exp ';' (format "%s;" $1) | error ';' {"Error;"} ; exp: NUM (string-to-number $1) | exp '=' exp (= $1 $3) | exp '+' exp (+ $1 $3) | exp '-' exp (- $1 $3) | exp '*' exp (* $1 $3) | exp '/' exp (/ $1 $3) | '-' exp %prec NEG (- $2) | exp '^' exp (expt $1 $3) | '(' exp ')' {$2} ; %% (defun wisent-calc-setup-parser () "Setup buffer for parse." (wisent-calc-wy--install-parser) (setq semantic-number-expression (concat "\\([0-9]+\\([.][0-9]*\\)?\\([eE][-+]?[0-9]+\\)?" "\\|[.][0-9]+\\([eE][-+]?[0-9]+\\)?\\)") semantic-lex-analyzer 'wisent-calc-lexer semantic-lex-depth nil semantic-lex-syntax-modifications '((?\; ".") (?\= ".") (?\+ ".") (?\- ".") (?\* ".") (?\/ ".") (?\^ ".") (?\( ".") (?\) ".") ) ) ) ;;; wisent-calc.wy ends here