From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: APL mode Date: Sat, 12 Oct 2013 15:08:37 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1381840472 13527 80.91.229.3 (15 Oct 2013 12:34:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Oct 2013 12:34:32 +0000 (UTC) Cc: emacs-devel@gnu.org To: Rustom Mody Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 15 14:34:35 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VW3pa-00036G-Hv for ged-emacs-devel@m.gmane.org; Tue, 15 Oct 2013 14:34:34 +0200 Original-Received: from localhost ([::1]:41645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW3pZ-0000px-Tm for ged-emacs-devel@m.gmane.org; Tue, 15 Oct 2013 08:34:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW3pQ-0000ok-Nl for emacs-devel@gnu.org; Tue, 15 Oct 2013 08:34:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VW3pJ-0003Zr-Di for emacs-devel@gnu.org; Tue, 15 Oct 2013 08:34:24 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:59201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW3pJ-0003Zm-7y for emacs-devel@gnu.org; Tue, 15 Oct 2013 08:34:17 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id r9FCYFhk017976; Tue, 15 Oct 2013 08:34:15 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 17C3C6617D; Sat, 12 Oct 2013 15:08:37 -0400 (EDT) In-Reply-To: (Rustom Mody's message of "Sat, 12 Oct 2013 21:39:24 +0530") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.4 X-NAI-Spam-Rules: 2 Rules triggered DATE_IN_PAST_48_96=0.4, RV4732=0 X-NAI-Spam-Version: 2.3.0.9362 : core <4732> : inlines <145> : streams <1056272> : uri <1565975> X-NAI-Spam-Level: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:164218 Archived-At: >>> What does sexp mean for non-lisp languages like C etc? >>> (Needed for functions like forward-sexp) >> It means "a subtree in the abstract syntax tree". > In principle, that's fine. However in practice there are things like > a. comments which do not exist in the AST comments should normally be skipped by forward-sexp. > b. preprocessor commands that appear and disappear before ASTs are on the > scene Indeed, there are cases where the source code does not correspond to a tree (and not even a DAG either). In that cases, the expected behavior of forward-sexp is undefined (i.e. total freedom). > c. (most important) emacs doesnt really do a full-scale context free > grammar analysis does it? Not sure what you man by "Emacs" here: Emacs just runs the code provided by the major mode author, so it's the major mode's author's responsibility to make sure forward-sexp works as it should. > So I guess I am asking: Emacs uses regular exps to fudge a semblance of > context free structure. How does it do this? There's `forward-sexp-function' which lets you write your parser by hand. Else, there's a very simplistic builtin parser, which doesn't know about infix operators and only know how to skip "normal" comments, how to recognize "normal" strings, and how to skip parentheses (and related pairs, with restrictions such as: the opening and closing markers are single chars). The "grammar" for this parser is given in the form of what we call a "syntax-table". In between, there's SMIE which does precedence parsing. It's a very weak grammar, but since we want to parse backward (for backward-sexp), it's a good option since, contrary to LL/LR and friends it's fully symmetric. We use it for various different modes: Coq, SML, OCaml, Prolog, sh, Ruby, Modula-2, Octave, css. Stefan "who doesn't know much about APL's syntax"