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 30 mg

cialis fast delivery

levitra cheap

canada levitra

buying viagra

best price levitra online

beta blockers and viagra

cialis dosagem

order propecia pill

canadian online pharmacy cialis

generic cialis

brand viagra professional

cialis for woman

cheap viagra canada or india

cialis uk

canadian drugs propecia

how much does cialis cost

levitra prices

cialis dosagem

chip cialis

levitra tabs

drug generic propecia

buy levitra american pharmacy

levitra presciptions online

cialis from mexico

buy propecia where

buy mg propecia

buy propecia online from usa pharmacy

cheapest propecia sale uk

buy viagra in canada no prescription

cialis alternatives

online pharmacy levitra

buy propecia without a prescription

cheapest viagra online

ordering viagra

cheap prescription propecia

cheapest cialis

buy cialis online canada

low cost canadian viagra

buy generic levitra online

buy cialis online canada

cialis canadian

cialis en mexico

cialis cost canada

buy now propecia

cialis usa

cialis no prescription

cialis price

combine cialis and levitra

levitra without prescription

buying viagra without prescription

order levitra

canadian healthcare

cialis dose

diuretics and viagra

healthcare of canada pharmacy

lowest price levitra

cialis 20 mg

levitra prescription

cialis for women

buy levitra online viagra

canadian viagra

map of france with cialis

online propecia prescription

cialis dosage

levitra cheapest

mail online order propecia

buy levitra with no prescription

cialis philippines

buy branded viagra online

buy cialis online

canadian healthcare pharmacy

buying cialis without a prescription

cialis 5 mg

mexico pharmacy cialis

cialis alternative

buy prescription propecia

buy propecia generic

effect of cialis on women

low price cialis

best online levitra

buy levitra online no prescription

order propecia online

cialis levitra

cheap levitra uk

cialis daily in canada

buy viagra germany canadian meds

generic levitra mexico

canadian drug viagra soft

levitra from canadian pharmacy

buy prescription propecia

buy cheap levitra

buying cialis next day delivery

cheapest online propecia

cheapest propecia uk

buy propecia now

brand viagra without prescription buy

generic form of propecia

buy cialis in canada

levitra online

buy levitra uk

how much is viagra

levitra for sale

buy cialis

buy generic propecia online

best price on propecia

info levitra

low cost viagra

buy viagra on line

buying levitra online

non pescription cialis

buying cialis in canada

buying cialis without a prescription

cialis testimonial

levitra info

buying viagra in canada

cheap cialis fast delivery time

levitra buying

buy canada in propecia

cialis online without prescription

cialis without prescription

cialis in mexico

buy levitra low price

discount drug propecia

levitra sale

canada viagra

cialis discount prices

levitra best price

buy levitra online us

one day delivery cialis

canadian pharmacy viagra

generic propecia india

cheap viagra online

i need to buy propecia

levitra canada prescription

best prices for propecia

cialis brand only

cheap fast levitra

cialis generic 100 mg

cheap generic levitra

cost levitra low

bestellen levitra online

buy cheap generic propecia

natural viagra pills

buying propecia

get cialis

bying viagra online cheap us

cheap viagra no prescription

bestellen levitra

how much cialis

cialis discounts

cialis by women

cialis daily price

cheap propecia no prescription

cialis canadian pharmacy

cheapest viagra

buy pfizer viagra online

buy mg propecia

buy real viagra online

buy propecia online usa

cialis discount

buy propecia and proscar

canadian viagra

how to get cialis

buy cialis in usa

5 mg daily cialis

cheap levitra online

cialis dose

buying cialis online

buying generic cialis mexico rx

buying viagra in canada

cialis soft tabs

buy generic viagra india rx

mail order propecia

buy prescription propecia without

buy viagra in canada

cialis headaches

buy propecia on line

buying cialis soft tabs 100 mg

getting cialis from canada

canadian cialis

lowest propecia price

levitra online order

lowest cost levitra

buy cialis usa

order prescription propecia

cialis fast

generic online propecia

levitra next day delivery

cheap viagra pills

generic levitra usa

buy viagra

daily cialis

online viagra gel to buy

cheap canadian viagra

online levitra us

buy generic propecia

cialis endurance

cialis daily dosing cost

cialis canada

levitra mail order

buy propecia online without prescription

buy now viagra

bio viagra herbal

cheap order prescription propecia

cheap propecia 5mg

cheap propecia uk

cialis 30 mg

cheap cialis fast delivery time

levitra online sales

buy dosages levitra

buy propecia no prescription

buying cialis in canada

low cost levitra

levitra tadalafil

cialis daily canada

cheap propecia order online

generic cialis india discount

mexico viagra

generic cialis india

cialis delivered overnight

cialis c 50

buy can from i propecia who

buy cheapest cialis

ganeric cialis

cialis 5 mg buy

brand name cialis overnight

buy drug propecia

buy cialis canada

generic cialis next day shipping

cheap viagra on line

cialis 20 mg

order propecia propecia

levitra 10 mg

cialis order

cheap levitra online

dose cialis

cialis from india

best deal for propecia

levitra canadian

canadian pharmacy cialis pfizer

cheapest prices on propecia

discount cialis india

5 mg daily cialis

buy cheap propecia

get propecia cheap

discount real viagra

buy cialis for daily use

get levitra online

buy propecia pills