Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Clunky parsing problem, looking for simple solution

by clintp (Curate)
on Jun 17, 2002 at 16:38 UTC ( #175125=note: print w/ replies, xml ) Need Help??


in reply to Re: Clunky parsing problem, looking for simple solution
in thread Clunky parsing problem, looking for simple solution

(background aside for other's listening, AM's deserve no replies)

First let me clarify a few things. Firstly, within the BASIC interpreter itself, there's no formal "grammar" at all. Lines are dissected to find the statement being executed (the first token following the line number) and each statement's execution block has hard-wired into it a series of possible templates for that statement.

As one rude monk asked, "The art of language design hasn't been around for 25+ years without having come up with solutions to this kind of thing (...) did you do any research into language design before embarking on this project?" As a matter of fact I did. 25 years ago when I first saw this language, and shortly thereafer obtained assembler source code for implementations of the language, I learned how it was done. When I thought to recreate it for the Parrot CPU this is how it happened. The total number of assembly instructions is about 2k (for interactive mode, runtime, parser, everything).

When I get around to porting a pig like QuickBasic, I'll think about using a more open design with a formal grammar.

So discounting comments directed towards the interpreter itself, I'm left with the GW-BASIC to Parrot BASIC Perl script. This is (so far, and can remain) a simple filter. I don't want to teach it BASIC. The only statement's that's "special" is IF..THEN..ELSE. If the parser gets confused, it gets confused. This is what GW-BASIC was like.

(specifically to jepri)

Looking at talexb's solution and your description, I think I'm going to write a small state machine to process tokens on an IF..THEN line and arrange them accordingly. kvale's notes triggered a few light-bulbs as well. I'll post something shortly...


Comment on Re: Re: Clunky parsing problem, looking for simple solution
Re: Re: Re: Clunky parsing problem, looking for simple solution
by jepri (Parson) on Jun 17, 2002 at 21:56 UTC
    I think the academic computer world now calls small state machines Discrete Finite Automations or something. I read about how to do it in a lecture series I pulled of the net. Available upon request, or google for it. The upshot was that it was an interesting way of approaching the problem. To me it sounds like you are flogging yourself unnecessarily, but each to his own :)

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

      the academic computer world now calls small state machines Discrete Finite Automations or something

      I think a lot of terms are used, this being one of them. Determinisitic Finite State Automata, Turing Machines, Finite State Machines, Finite Sate Automata, State Transition Machine are all terms ive seen.

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://175125]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-19 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls