help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speed-up parsing


From: Hans Aberg
Subject: Re: speed-up parsing
Date: Tue, 18 Jun 2002 20:03:39 +0200

At 11:55 +0200 2002/06/18, Christian Kristukat wrote:
>> information. But there are several ways to tweak the setup; but then one
>> needs more information about what one wants to do than what you provide.
>
>I use the multifunction calculator from the bison tutorial. It recognizes
>basic operators, functions, numbers and variables. Let's say we have a parse
>string "f(x,a,b,c)". I call yyparse() a first time, then I set the symbols
>a,b,c and x to the desired values and call yyparse() again without having
>changed the parse string. So there is no need to call the lexer again, right?

The way to proceed is to first build a "closure", which is a binary
structure looking logically something what Anthony DeRobertis indicated.
When you know the values of the constants, you feed that it the closure and
evaluate it. This way, the process becomes very fast, because one never
re-consults the original source code twice.

Unfortunately, if you want to implement functions with variables and stuff,
then you are already trying to implement something advanced, a small lambda
calculus program. Simon Peyton Jones has a book on the subject, which you
can download for free:
    http://research.microsoft.com/Users/simonpj/Papers/pj-lester-book/

If you take a close look at your problem, you may escape at much less, say
merely reserving memory locations for the future variable, and then fill
them in later. But if you are going to allow nested function calls and
stuff, then you are already towards your way onto more advanced closures.


  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]