Archive

Posts Tagged ‘grammar’

GLR parsing is the future

August 27th, 2009 Derek-Jones 1 comment

Traditionally parser generators have required that their input grammar be LALR(1) or some close variant (I would include LL(1) in this set). Back when 64k was an unimaginably large amount of memory being able to squeeze parser tables in a few kilobytes was very important; people received PhDs on parser table compression.

There is still a market for compact, fast parsers. Formal language grammars abound in communication protocols and vendors of communications hardware are very interested in keeping down costs by using minimizing the storage needed by their devices.

The trouble with LALR(1) is that value 1. It means that the parser only looks ahead one token in the input stream. This often means that a grammar is flagged as being ambiguous (i.e., it contains shift/reduce or reduce/reduce conflicts) when it is actually just locally ambiguous, i.e., reading tokens further head on the input stream would provide sufficient context to unambiguously specify the appropriate grammar production.

Restructuring a grammar to make it LALR(1) requires a lot of thought and skill and inexperienced users often give up. I once spent a month trying to remove the conflicts in the SQL/2 grammar specified by the SQL ISO standard; I managed to get the number down from over 1,000 to a small number that I decided I could live with.

It has taken a long time for parser generators to break out of the 64k mentality, but over the last few years it has started to happen. There have been two main approaches: 1) LR(n) provides a mechanism to look further ahead than one token, ie, n tokens, and 2) GLR parsing.

I think that GLR parsing is the future for two reasons:

  • It is supported by the most widely used parser generator, bison.
  • It enables working parsers to be created with much less thought and effort than a LALR(1) parser. (I don’t know how it compares against LR(n)).

GLR parsers resolve any language ambiguities by effectively delaying decisions until runtime in the hope that reading enough tokens will resolve local ambiguities. If an ambiguity in the token stream cannot be resolved a runtime error occurs (this is the one big downside of a GLR parser, the parser generated by a LALR(1) parser generator may produce lots of build time warnings but never produces errors when the parser is executed).

One example of a truly ambiguous construct (discussed here a while ago) is:

x * y;

which in C/C++ could be a declaration of y to be a pointer to x, or an expression that multiplies x and y.

Tools that can detect these global ambiguities in a grammar are starting to appear, e.g., DTWA is a bison extension.

I reviewed an early draft of the new O’Reilly book “flex & bison” and tried to get the author to be more upbeat on GLR support in bison; I think I got him to be a bit less cautious.

Finding the ‘minimum’ faulty program

March 17th, 2009 Derek-Jones No comments

A few weeks ago I received an inquiry about running a course/workshop on compiler writing. This does not does not happen very often and it reminded me that many years ago the ACCU asked if I would run a mentored group on compiler writing, I was busy writing a book at the time. The inquiry got me thinking it would be fun to run a compiler writing mentored group over a 6-9 month period and I emailed the general ACCU reflector asking if anybody was interested in joining such a group (any reader wanting to join the group has to be a member of the ACCU).

Over the weekend I had a brainwave for a project, automatic compiler test generation coupled with a program source code minimizer (I need a better name for this bit). Automatic test generation sounds great in theory but in practice whittling down the source code of those programs that result in a fault being exhibited, to create a usable sized test case that is practical for debugging purposes can be a major effort. What is needed is a tool to automatically do the whittling, i.e., a test case minimizer.

A simple algorithm for whittling down the source of a large test program is to continually throw away that half/third/quarter of the code that is not needed for the fault to manifest itself. A compiler project that took as input source code, removed half/third/quarter of the code and generated output that could be compiled and executed is realistic. The input/reduce/output process could be repeated until the generated source was considered to have reached some minima. Ok, this will soak up some cpu time, but computers are cheap and people are expensive.

Where does the test source code come from? Easy, it is generated from the same yacc grammar that the compiler, written by the mentored group member, uses to parse its input. Fortunately such a generation tool is available and ready to use.

The beauty is using the same grammar to generate tests and parse input. This means there is no need to worry about which language subset to use initially and support for additional language syntax can be added incrementally.

Experience shows that automatically generated test programs quickly uncover faults in production compilers, even when working with language subsets. Compiler implementors are loath to spend time cutting down a large program to find the statement/expression where the fault lies, this project will produce a tool that does the job for them.

So to recap, the mentored group is going to write one or more automatic source code generators that will be used to stress test compilers written by other people (e.g., gcc and Microsoft). Group members will also write their own compiler that reads in this automatically generated source code, throws some of it away and writes out syntactically/semantically correct source code. Various scripts will be be written to glue this all together.

Group members can pick the language they want to work with. The initial subset could just include supports for integer types, if-statements and binary operators.

If you had trouble making any sense all this, don’t join the group.

FireStats icon Powered by FireStatscialis on line pricing in canada

cialis woman

levitra tablet

cialis online without prescription

cheapest overnight cialis

cialis daily in canada

5 mg daily cialis

cialis without prescription

best price generic propecia

buy propecia where

cheap propecia canada

canada levitra

map of france with cialis

cialis medication

buy cheap propecia online

cialis canada

buy cheapest cialis

online levitra

order levitra online

bio viagra herbal

bio viagra herbal

about cialis

indian cialis

buy viagra germany canadian meds

cialis fast delivery usa

cialis discount prices

brand viagra without prescription buy

cialis 100 mg

cialis fast delivery usa

cialis c 50

discount cialis

cheapest prices for viagra

cialis cheap us pharmacy

cialis generic

buy levitra online us

brand cialis

best price cialis

buy pfizer viagra

cialis 30 mg

levitra viagra cialis

cialis prices

online propecia cheap

generic levitra cialis

buy dosages levitra

buy propecia pills

get cialis online

buy propecia international pharmacy

info levitra

once daily cialis

cialis from canada

cialis canada illegal buy

lowest propecia prices

generic viagra in canada

generic cialis sale

cheapest propecia pharmacy online

cheap propecia order online

is pfizer viagra available in india

cheap propecia canada

order levitra

online viagra gel to buy

natural levitra

best way to use cialis

levitra online prescription

cialis soft

order propecia now

cheap cialis

generic propecia cheap

generic cialis

cialis discount

cialis canada illegal buy

best cialis price

buying propecia online

buy canada in propecia

cialis daily dosage pharmacy

buy can from i propecia who

online levitra tablet

order prescription propecia

levitra price

cialis dosage

buy now online propecia

china viagra

original brand cialis

cialis angioplasty

growth hair propecia

how to get cialis in canada

cialis discounts

cheapest propecia in uk

buy propecia now

cialis okay for women

drug hair loss propecia

cialis 50 mg

online pharmacy propecia

cialis brand only

online prescription propecia

cost of daily cialis

buying viagra in the us

cialis order

best price cialis

cialis on line pricing in canada

buy cialis fedex shipping

canada generic propecia

bestellen levitra online

cialis next day

cialis 100 mg generic

for sale levitra

levitra tadalafil

buy discount viagra

get viagra fast

mail order propecia

buy viagra on line

levitra cheap fast

canadian healthcare viagra

bying viagra online cheap us

cheepest cialis

cialis 100 mg

buy propecia generic

cialis india

china viagra

how does viagra work

canadian pharmacy discount code viagra

cialis dose

buy cialis without prescription

buy propecia online

best viagra

cialis alternatives

cheapest propecia online

buy cialis canada

canadian propecia rx

5 mg original brand cialis

buy levitra with no prescription

cialis express delivery

name brand cialis

buy levitra american pharmacy

cialis dosagem

cialis no prescription

cheap viagra canada or india

buying generic propecia

cialis 100 mg

baldness male propecia

levitra prices

obtain viagra without prescription

50 mg cialis dose

buy propecia online from usa pharmacy

buy branded viagra

cialis from mexico

lowest cost propecia uk

cialis daily canada

cheap viagra pills

cheap cialis fast delivery time

buying cialis online

cialis 20 mg

best doses for propecia

canadian pharmacy viagra legal

buying cialis soft tabs 100 mg

cialis and ketoconazole

cialis once daily

levitra online us

indian cialis canada

best price on propecia

online order viagra overnight delivery

how to get cialis

bying viagra online cheap us

cialis generic

cialis woman

buy cialis online canada

cialis arterial fibrillation

canadian healthcare pharmacy

best viagra

buy cialis 5 mg

cialis canadian cost

cheap levitra prescription

cheapest viagra usa

lowest price on non generic levitra

levitra vs viagra

canadian women viagra

how to buy cialis in canada

generic cialis canada

canadian drug viagra soft

cheap fast levitra

buy levitra vardenafil

cialis alternative

generic propecia sale

buy cialis 5 mg

cialis and ketoconazole

how to get cialis no prescription

50 mg cialis dose

canadian drug viagra soft

canadian viagra and healthcare

buy viagra in canada no prescription

healthcare of canada pharmacy

cialis 50 mg dose

buy cialis online without prescription

buy drug propecia

cialis canada

buy real cialis

buy propecia online without prescription

levitra in india

buy cheapest cialis

cheap viagra pills

cialis and canada custom

generic levitra pill

cialis endurance

cialis 50 mg

herbal viagra

levitra in canada

discount levitra pharmacy purchase

buy prescription propecia

buy cialis without a prescription

cialis 5 mg

generic viagra in canada

buying cialis

cialis canadian

buy viagra online cheap us

buy cialis once daily

cialis alternitives

canadian women viagra

low cost canadian viagra

best way to take cialis

cialis daily canada

cialis angioplasty

cialis soft tabs

cialis brand

cialis buy overnight

5 mg cialis canada

gerenic cialis

cialis philippines

cheap generic levitra

cialis for sale

buy propecia without a prescription

buy cialis professional

best propecia prices

canada online pharmacy levitra

50 mg cialis

buy cheap levitra

brand name cialis overnight

best online generic levitra

best price propecia

cialis 20 mg

cheap fast levitra

buy cialis

order cheap levitra

best price levitra

buy levitra low price

canadian online pharmacy cialis

buy propecia in canada

buy levitra us

buy generic cialis

buy levitra online viagra

cialis uk

cialis for less 20 mg