|
[cedet-semantic] expanding blocks
From: Joe Corneli <jcorneli@ma...> - 2004-05-11 02:30
|
I haven't gotten rid of that shift-reduce conflict, though I am
using %left EQ, %left NEQ (against the request of the spec, see
previous email). But my current question is about something else:
expanding blocks. I think I am just getting the hang of the TAG
system -- but tags or no tags, I'm still confused by the EXPAND
macros.
The basic problem I want to deal with are lists of things like
(a, b, c) [1 ; 2 ; 3] {int, bool}
or whatever you like. With my current set up (copied below),
the example
(1, 2, 3)
gets parsed as
(("number" expr
(:value "1")
nil #<overlay from 17 to 18 in example.simple>)
("number" expr
(:value "2")
nil #<overlay from 21 to 22 in example.simple>)
("number" expr
(:value "3")
nil #<overlay from 24 to 25 in example.simple>))
But I would like some extra structure to represent the fact that
these numbers are part of a parenthesized list! Currently that fact
seems to be being ignored by wisent.
The rule that is relevant here is
| PAREN_BLOCK
(format "printme %s" (EXPANDFULL $1 expr_seq))
Probably this is not the right way to get things to happen with the
expansion of the paren block. Can you tell me what I should be
doing instead?
;;; simple.wy -- LALR grammar for (simplified) Tiger
%package simple-wy
;; Not really necessary, as it is the default start symbol
%start expr
%start function_parameters
%start expr_seq
%type <punctuation>
%token <punctuation> COMMA ","
%type <symbol>
%token <symbol> symbol "[A-Za-z][_A-Za-z0-9]*"
%type <string>
%token <string> STRING_LITERAL
%type <number>
%token <number> NUMBER_LITERAL
%type <keyword>
%keyword NEQ "<>"
%keyword EQ "="
%left EQ
%left NEQ
%type <open-paren>
%token <open-paren> LPAREN "("
%type <close-paren>
%token <close-paren> RPAREN ")"
%type <block>
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%%
;; For use with Semantic, must return valid semantic tags!
expr
: STRING_LITERAL
(TAG "string" 'expr :value $1)
| NUMBER_LITERAL
(TAG "number" 'expr :value $1)
| expr EQ expr
(TAG "expr eq" 'expr :value (format "(equal %s %s)"
(value-of $1)
(value-of $3)))
| expr NEQ expr
(TAG "expr eq" 'expr :value (format "(not (equal %s %s))"
(value-of $1)
(value-of $3)))
| PAREN_BLOCK
(format "printme %s" (EXPANDFULL $1 expr_seq))
;
expr_seq
: LPAREN
()
| RPAREN
()
| expr COMMA function_parameters
(concat $1 (EXPANDFULL $3 function_parameters))
| expr RPAREN
(concat $1)
;
;; parameters: '(' [varargslist] ')'
function_parameters
: LPAREN
()
| RPAREN
()
| expr COMMA function_parameters
(TAG "function_parameter" 'function_parameter
:value
(concat
$1
(EXPANDFULL $3 function_parameters)))
| expr RPAREN
(TAG "function_parameter" 'function_parameter :value $1)
;
%%
(define-lex simple-lexer
"Simple lexical analyzer."
semantic-lex-ignore-whitespace
semantic-lex-ignore-newline
semantic-lex-ignore-comments
;;;; Auto-generated analyzers.
simple-wy--<block>-block-analyzer
simple-wy--<keyword>-keyword-analyzer
simple-wy--<punctuation>-string-analyzer
simple-wy--<number>-regexp-analyzer
;; From the documentation string for `semantic-lex-tokens':
;; "Always add this analyzer *after* `semantic-lex-number', or other
;; analyzers that match its regular expression." (my emphasis)
simple-wy--<symbol>-regexp-analyzer
simple-wy--<string>-sexp-analyzer
;;;;
semantic-lex-default-action)
;;; simple.wy ends here
;;; simple-mode.el -- major mode for a simple language
;;; Semantic parsing support
(require 'semantic-wisent)
(require 'simple-wy)
;;;###autoload
(defun semantic-default-simple-setup ()
"Set up a buffer for semantic parsing of a SIMPLE language."
;; Do some useful things.
(setq semantic-ignore-comments t)
;; Install the parser
(simple-wy--install-parser)
;; Setup the lexer
(setq semantic-lex-analyzer 'simple-lexer
;; Do a full depth lexical analysis.
semantic-lex-depth nil))
;;;###autoload
(add-hook 'simple-mode-hook 'semantic-default-simple-setup)
(defun value-of (tok)
(car
(cdaddr tok)))
;;; post parser processing
(defun clean-up-parser-output ()
(interactive)
(set-buffer (get-buffer "*Parser Output*"))
(flush-lines "overlay")
(flush-lines "expr")
;; (flush-lines "\"expr\" expr")
(goto-char (point-min))
(replace-regexp " (:value \"\\|\")$" "")
(goto-char (point-min))
(replace-regexp "\\\\\"" "\""))
(defun novinate ()
(interactive)
(bovinate)
(clean-up-parser-output)
(other-window 1))
;;; simple major mode
(defvar simple-mode-syntax-table
(let ((table (make-syntax-table (standard-syntax-table))))
(modify-syntax-entry ?\+ "." table) ;; Operator PLUS
(modify-syntax-entry ?\- "." table) ;; Operator MINUS
;; also deals with comments
(modify-syntax-entry ?\* ". 23" table) ;; Operator MULT
(modify-syntax-entry ?\/ ". 14" table) ;; Operator DIV
;; deal with brackets
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\{ "(}" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\} "){" table)
(modify-syntax-entry ?\] ")[" table)
table)
"Syntax table used in simple mode buffers.
Define operators as punctuations.")
;;;###autoload
(define-derived-mode simple-mode fundamental-mode "simple"
(setq comment-start-skip "/\\*+ *"))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.simple\\'" . simple-mode))
;(defvar simple-mode-hook nil)
(provide 'simple-mode)
;;; simple-mode.el ends here
|
| Thread | Author | Date |
|---|---|---|
| [cedet-semantic] expanding blocks | Joe Corneli <jcorneli@ma...> |