Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?B?Sm9zaHVhIENyYW5tZXIg8J+Qpw==?= Newsgroups: comp.lang.java.programmer Subject: Re: Parser Date: Tue, 29 Apr 2014 17:31:24 -0500 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: <535e1fc6$0$2975$e4fe514c@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 29 Apr 2014 22:31:31 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="8b6ddcc38ecbed2f71b30fabadb8aa0b"; logging-data="24151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qTcnodTjGn/V/LyUM6wxO4+VSz+/NBxs=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Thunderbird/29.0 In-Reply-To: Cancel-Lock: sha1:RDDGmRrF+j17aUjL64+iDwHpnE4= Xref: csiph.com comp.lang.java.programmer:28315 On 4/29/2014 3:15 PM, Roedy Green wrote: > On Mon, 28 Apr 2014 11:30:45 +0200, Silvio > wrote, quoted or indirectly quoted someone who said : > >> >> The fact that a no such keywords exist does not make parsing slower by >> definition. In the Java case it unlikely that such keywords would make >> parsing faster. The language grammar defines how fast a parser can be. >> Although the Java grammar is not strictly LALR(x) Java can be parsed >> pretty left-to-right with the use of some simple tweaks and assumptions >> to prevent expensive things like backtracking > > Consider how far you have to parse into definition to tell if you have > a variable or a method definition. A hand-written recursive-descent parser (which is what almost all production compilers use, since you can't get good error messages out of an automatic parser generator and you don't want to write anything other than recursive-descent by hand) can easily disambiguate it. You start by parsing a specifier sequence, then a type, then the name, and you call this set a declarator. The distinction between a method and a variable is that a method is immediately followed by a ( paren whereas a variable can be followed by a ,, =, or ;. [Java 1.0 is definitely LALR(1). Someone claims to have a Java 5 LALR(1) grammar, and I think Java 7 is LALR(1) as well. Don't know about Java 8. It also slightly depends on whether or not you consider, e.g., inappropriate specifiers to be syntactic or semantic issues.] > An IDE could insert visible markers to mark the begins and end of > things. I must waste at least an hour a day trying to figure out which > { } balances with what. It is not a task my eyes can do, especially > when the other half is offscreen. > > Another solution would be a SCID which would not let you cut/copy > paste an unbalanced block of code. You would think of program as > composed on units -- like plumbing, not a stream of characters. Neither of these tasks require much parsing, just lexing and keeping track of balanced [/