Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2015
    Posts
    1
    Rep Power
    0

    Example interpreter


    Originally Posted by tesla1969
    Hi to all,i am new here..
    also iam not new in programming but i am not C programmer
    i use few free basic compilers and i am trying to create simple basic- like interpreter
    actually i already built two but are not fast enough ...have
    they are direct interpreters ...
    so i need some help about scaner,lexer...parser

    i found this topic and i have question for scorpions4ever
    you said that you have source codes is still free to use?
    Or you may help me to writte proper scaner.lexer.parser?
    thanks in advance...!
    Here I explained how to write an interpreter;

    How to Learn Writing a Compiler | Mehmet's Internet

    And here is the toy interpreter I wrote for my book;

    https://github.com/mehmetcnet/contra

    You can study its source code and write an interpreter from scratch. It is easy to understand.

    And here is book that teaches how to write an interpreter from scratch;

    https://leanpub.com/pic

    Writing a compiler or an interpreter is pretty rewarding and teaching programming activity. It makes you better programmer.
    I advice all serious programmer to do it.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0
    Hi Tesla 1969

    I'm pretty much well informed in parsing, so I could help or mentor you in your task if you wish. Lets just say that there are at least four, more or less simple ways to program a parser. There are well known algorithms for parsing, so you don't have to reinvent hot water. I think you should start by examining Backus-Naur Form (BNF) language that is used for constructing grammars for languages.

    The fastest way to parsing artificial languages is certainly PEG parsing, but it doesn't cover all grammars one could think of. Other methods that I can recommend deal with complete "context free grammar" domain (CFG) and are slower than PEG in some extent. These other methods include "CYK parser" (the slowest, but the simplest), "Earley parser" (a bit faster and still somewhat simple) and "GLL parser" (more fast, but more complicated). Of course there are other methods, but I recommend one of these four because implementing any of these methods would give you a general parsing library that accept any grammar for any language before actually parsing the real code to interpret or process. That means that by programming any of above methods once, you can apply it to any language you want to parse, being Basic, Python, Java, or anything else.

    This was a brief introduction to parsing methods, but for further help I suggest you post me a PM, or to open a separate thread, specific to your case.
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    2
    Rep Power
    0

    Smile


    Hi Tesla 1969

    I'm pretty much well informed in parsing, so I could help or mentor you in your task if you wish. Lets just say that there are at least four, more or less simple ways to program a parser. There are well known algorithms for parsing, so you don't have to reinvent hot water. I think you should start by examining Backus-Naur Form (BNF) language that is used for constructing grammars for languages.

    The fastest way to parsing artificial languages is certainly PEG parsing, but it doesn't cover all grammars one could think of. Other methods that I can recommend deal with complete "context free grammar" domain (CFG) and are slower than PEG in some extent. These other methods include "CYK parser" (the slowest, but the simplest), "Earley parser" (a bit faster and still somewhat simple) and "GLL parser" (more fast, but more complicated). Of course there are other methods, but I recommend one of these four because implementing any of these methods would give you a general parsing library that accept any grammar for any language before actually parsing the real code to interpret or process. That means that by programming any of above methods once, you can apply it to any language you want to parse, being Basic, Python, Java, or anything else.

    This was a brief introduction to parsing methods, but for further help I suggest you post me a PM, or to open a separate thread, specific to your case.
    Hi
    Ivan vodišek
    first thanks for reply..
    you present so many parsers that names i never heard before,,i only
    know for recursive descent and top down, bootom up.
    As i said i use basic compiler which support OOP programming and i simply
    dont like this way of programming ..to much to thinking for me ..
    what i want is simple as possible parser which can translate source
    code to array of tokens ,syntax of interpreter should be close to BASIC or REXX
    so to say simple ..right
    and there is no need for new thread
    when i get something i will post here
  6. #19
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,785
    Rep Power
    4300
    Originally Posted by tesla1969
    Hi to all,i am new here..
    also iam not new in programming but i am not C programmer
    i use few free basic compilers and i am trying to create simple basic- like interpreter
    actually i already built two but are not fast enough ...have
    they are direct interpreters ...
    so i need some help about scaner,lexer...parser

    i found this topic and i have question for scorpions4ever
    you said that you have source codes is still free to use?
    Or you may help me to writte proper scaner.lexer.parser?
    thanks in advance...!
    Here's a link to some code. Bear in mind that this code is old and I hand coded a lexer and parser from scratch, instead of using a code generation tool. The code is released under a BSD license, so feel free to use in your own projects.
    Last edited by Scorpions4ever; January 6th, 2017 at 06:34 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0
    Tesla1969, did you consider using a "parser generator"? I think that would be the simplest solution without getting into much detail. You pass wanted grammar, after which the generator constructs your custom parser source code and saves it as a file. Then you use generated file as a library, independent of the generator, like you built it on your own, from the scratch. Check the web, maybe there is a generator for your host language.

    But writing a parser from the scratch is a fun thing to do
  10. #21
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,785
    Rep Power
    4300
    If anyone is interested, I also wrote a pl0 parser + compiler + interpreter for a PL/0 machine in C++ 14 (mainly to muck around with the new C++ 14 features). The language is based on a tiny language described by Niklaus Wirth in his book "Algorithms + Data Structures = Programs", which you can google for, if you want some notes.

    Code's available on github here: https://bitbucket.org/scorpions4ever/pl0_interpreter/
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo