|
Re: [cedet-semantic] using semantic/wisent as a parser
From: Joe Corneli <jcorneli@ma...> - 2004-04-26 18:41
|
(defun semantic-default-simple-setup ()
"Set up a buffer for semantic parsing of a SIMPLE language."
(simple-wy--install-parser)
(setq document-comment-start "/*"
document-comment-end " */"
))
where `simple-wy--install-parser' is a function generated from your
simple.wy grammar, that setups for you the wisent parser, based on
what is generated in the simple-wy.el library.
Probably you will also need to add (require 'simple-wy) in your
semantic-simple library.
I have set it up as you suggested, but this time upon running
(semantic-parse-region (point-min) (point-max)) I just get `nil'.
I'd appreciate it if you could take a look. I seem to have gotten
down to the bare bones here, and I think I've followed all your
instructions, and it still doesn't seem to be working as expected.
Everything I'm working with, including the auto-generated parser
is below. I hope I'm just making a simple error.
/* example.simple -- about the simplest possible example */
abc + xyz
/* example.simple ends here */
;;; semantic-hacks.el -- actually just a simple setup
(load "~/cedet-1.0beta2a/common/cedet.el")
;; Make my working directory available to Emacs
(add-to-list 'load-path "~/Parser/simple/")
;; my parser-generator code to be "compiled" with keyboard command C-c C-c
(find-file "/Users/arided/Parser/simple/simple.wy")
;; the elisp parser automatically pops up and loads but just to be sure...
(load "/Users/arided/Parser/simple/simple-wy.el")
;; this is code to set up the parser. In particular, it contains the code
;; (add-hook 'simple-mode-hook 'semantic-default-simple-setup)
(load "/Users/arided/Parser/simple/semantic-simple.el")
;; we might want to take a look at this file!
(find-file "/Users/arided/Parser/simple/semantic-simple.el")
;; tiny major mode that works on files with suffix ".simple"
(load "~/site-lisp/simple-mode.el")
;;; semantic-hacks.el ends here
;;; simple.wy -- LALR grammar for (much simplified) Tiger
%package simple-wy
;; apparently not useful for wisent?
%start expr
%type <punctuation>
%token <punctuation> PLUS "+"
%type <symbol>
%token <symbol> symbol "[A-Za-z][_A-Za-z0-9]*"
%%
expr
: ;; empty
| symbol
(quote $1)
| symbol PLUS symbol
(quote (+ $1 $3))
;
;;; simple.wy ends here
;;; semantic-simple.el -- parser support for a simple language.
(require 'simple-wy) ;; The parser
(define-mode-overload-implementation
semantic-parse-region simple-mode
(start end &optional nonterminal depth returnonerror)
"Over-ride in order to initialize some variables."
(semantic-parse-region-default
start end nonterminal depth returnonerror))
;; As instructed by the info node Semantic Overload Mechanism,
;; looking at examples
;;;###autoload
(defun semantic-default-simple-setup ()
"Set up a buffer for semantic parsing of a SIMPLE language."
(simple-wy--install-parser)
(setq document-comment-start "/*"
document-comment-end " */" ))
;;;###autoload
(add-hook 'simple-mode-hook 'semantic-default-simple-setup)
(provide 'semantic-simple)
;;; semantic-simple.el ends here
;;; simple-mode.el --- simple mode to get my parser set up
(defvar simple-mode-hook nil)
(define-derived-mode simple-mode text-mode "simple"
""
(run-hooks 'simple-mode-hook))
(provide 'simple-mode)
;;; simple-mode.el ends here
;;; simple-wy.el --- Generated parser support file
;; Copyright (C) 2004 arided
;; Author: arided <arided@...>
;; Created: 2004-04-26 13:25:35-0500
;; Keywords: syntax
;; X-RCS: $Id$
;; 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 software 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; PLEASE DO NOT MANUALLY EDIT THIS FILE! It is automatically
;; generated from the grammar file simple.wy.
;;; History:
;;
;;; Code:
;;; Prologue
;;
;;; Declarations
;;
(defconst simple-wy--keyword-table
(semantic-lex-make-keyword-table 'nil 'nil)
"Table of language keywords.")
(defconst simple-wy--token-table
(semantic-lex-make-type-table
'(("symbol"
(symbol . "[A-Za-z][_A-Za-z0-9]*"))
("punctuation"
(PLUS . "+")))
'(("symbol" :declared t)
("punctuation" :declared t)))
"Table of lexical tokens.")
(defconst simple-wy--parse-table
(progn
(eval-when-compile
(require 'wisent-comp))
(wisent-compile-grammar
'((PLUS symbol)
nil
(expr
(nil)
((symbol)
'$1)
((symbol PLUS symbol)
'(+ $1 $3))))
'(expr)))
"Parser table.")
(defun simple-wy--install-parser ()
"Setup the Semantic Parser."
(semantic-install-function-overrides
'((parse-stream . wisent-parse-stream)))
(setq semantic-parser-name "LALR"
semantic--parse-table simple-wy--parse-table
semantic-debug-parser-source "simple.wy"
semantic-flex-keywords-obarray simple-wy--keyword-table
semantic-lex-types-obarray simple-wy--token-table)
;; Collect unmatched syntax lexical tokens
(semantic-make-local-hook 'wisent-discarding-token-functions)
(add-hook 'wisent-discarding-token-functions
'wisent-collect-unmatched-syntax nil t))
;;; Analyzers
;;
(require 'semantic-lex)
(define-lex-regex-type-analyzer simple-wy--<symbol>-regexp-analyzer
"regexp analyzer for <symbol> tokens."
"\\(\\sw\\|\\s_\\)+"
'((symbol . "[A-Za-z][_A-Za-z0-9]*"))
'symbol)
(define-lex-string-type-analyzer simple-wy--<punctuation>-string-analyzer
"string analyzer for <punctuation> tokens."
"\\(\\s.\\|\\s$\\|\\s'\\)+"
'((PLUS . "+"))
'punctuation)
;;; Epilogue
;;
(provide 'simple-wy)
;;; simple-wy.el ends here
|
| Thread | Author | Date | |
|---|---|---|---|
| Re: [cedet-semantic] using semantic/wisent as a parser | David PONCE <david.ponce@wa...> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|