Pascal code checker!

Discussion in 'Python' started by SMALLp, Dec 12, 2007.

  1. SMALLp

    SMALLp Guest

    Hy! I desperately need help!

    I need to make application that would accept Pascal code and check if it
    returns good results.

    My idea is (from a beginner point of view) to make application in python
    that would send code (text) to pascal compiler (Free pascal compiler
    that can be used from command prompt in windows) and it would return
    result and then application would show that result.

    Problem starts Here. I have no idea what to search for and where to even
    start. So what i need is some help (better say ideas) what to search and
    what to do. Please help, I have a lot of time and will to learn. I only
    need to know what.

    Thanks in advance!
     
    SMALLp, Dec 12, 2007
    #1
    1. Advertising

  2. SMALLp

    Zentrader Guest

    Zentrader, Dec 12, 2007
    #2
    1. Advertising

  3. SMALLp

    Tim Chase Guest

    > I need to make application that would accept Pascal code and check if it
    > returns good results.


    well, it depends on how much work you want your program to do.
    My understanding is that most compilers will return a non-zero
    error code when there's some sort of problem. Thus, you could
    just shell out to compile the code and check the resulting code.
    Time to implementation: likely less than 20 minutes, testing
    included.

    OTOH, you could actually parse the pascal file(s). This gives
    you infinte flexibility to do whatever you want with the
    parse-tree. Things get hairy when you have included ("uses")
    files, and you also have to write up a grammar for Pascal that
    can be understood by Python. The common wisdom seems to be to
    use PyParsing[1] for such parsing tasks. You'd also have to
    decide which flavor of Pascal you intend to parse (pascal, turbo
    pascal, object pascal, delphi, etc). You might be able to use
    some of the parser definitions from the Free Pascal[2] project as
    a model on which to base your parser's syntax. Time to break out
    the old Pascal language rail-road diagrams from CSC101.
    Time to implementation: weeks or months or even years

    As you can see, if you can get an existing pascal parser to do
    the work for you, and all you need to know is whether it built
    successfully, option "A" should be your obvious choice. If you
    have some deeper need to wander around this parsed structure,
    you're stuck with the labor involved in option "B".

    -tkc

    [1] pyparsing.wikispaces.com
    [2] www.freepascal.org
     
    Tim Chase, Dec 12, 2007
    #3
  4. On 2007-12-12, SMALLp <-com.hr> wrote:

    > Hy! I desperately need help!
    >
    > I need to make application that would accept Pascal code and check if it
    > returns good results.


    That application is called a Pascal compiler.

    > My idea is (from a beginner point of view) to make application in python
    > that would send code (text) to pascal compiler (Free pascal compiler
    > that can be used from command prompt in windows) and it would return
    > result and then application would show that result.


    I don't see why you need to write a Python program at all.

    > Problem starts Here. I have no idea what to search for and where to even
    > start.


    I'd Google for "pascal compiler"

    > So what i need is some help (better say ideas) what to search
    > and what to do. Please help, I have a lot of time and will to
    > learn. I only need to know what.


    --
    Grant Edwards grante Yow! I wonder if I could
    at ever get started in the
    visi.com credit world?
     
    Grant Edwards, Dec 12, 2007
    #4
  5. SMALLp

    Paul McGuire Guest

    On Dec 12, 3:03 pm, Tim Chase <> wrote:
    > OTOH, you could actually parse the pascal file(s). This gives
    > you infinte flexibility to do whatever you want with the
    > parse-tree. Things get hairy when you have included ("uses")
    > files, and you also have to write up a grammar for Pascal that
    > can be understood by Python. The common wisdom seems to be to
    > use PyParsing[1] for such parsing tasks. ...


    Oof! Fond as I am of promoting pyparsing, writing a Pascal compiler
    (or even just syntax checker) is not a job I would tackle lightly,
    much less suggest to a new Python developer.

    A Pascal *subset* might be a good first step, and check for
    feasibility. But the shell-out-to-a-compiler strategy has a much
    higher chance of success.

    -- Paul
     
    Paul McGuire, Dec 12, 2007
    #5
  6. SMALLp

    Tim Chase Guest

    >> Oof! Fond as I am of promoting pyparsing, writing a Pascal
    >> compiler (or even just syntax checker) is not a job I would
    >> tackle lightly, much less suggest to a new Python developer.


    True enough...thus my weeks/months/years estimate for such an
    undertaking :)

    But if not mentioned, you know the next question would be "how do
    I create a regular expression to match valid Pascal programs?"

    :-o

    -tkc
     
    Tim Chase, Dec 12, 2007
    #6
  7. On Wed, 12 Dec 2007 16:53:15 -0600, Tim Chase wrote:

    > >> Oof! Fond as I am of promoting pyparsing, writing a Pascal
    > >> compiler (or even just syntax checker) is not a job I would tackle
    > >> lightly, much less suggest to a new Python developer.

    >
    > True enough...thus my weeks/months/years estimate for such an
    > undertaking :)
    >
    > But if not mentioned, you know the next question would be "how do I
    > create a regular expression to match valid Pascal programs?"


    A *one-line* regular expression.

    --
    Steven
     
    Steven D'Aprano, Dec 13, 2007
    #7
  8. SMALLp

    Neil Cerutti Guest

    On 2007-12-13, Dotan Cohen <> wrote:
    > On 13/12/2007, Tim Chase <> wrote:
    >> >> Oof! Fond as I am of promoting pyparsing, writing a Pascal
    >> >> compiler (or even just syntax checker) is not a job I would
    >> >> tackle lightly, much less suggest to a new Python developer.

    >>
    >> True enough...thus my weeks/months/years estimate for such an
    >> undertaking :)
    >>
    >> But if not mentioned, you know the next question would be "how do
    >> I create a regular expression to match valid Pascal programs?"
    >>

    >
    > Go track down the source code of an open source text editor
    > that supports Pascal highlighting. Kate comes to mind. It's not
    > written in Python, but it will have Pascal parsing code for the
    > highlighter.


    A syntax highlighter usually knows very little about the syntax
    of a language. Mostly, it just finds keywords and highlights
    them. The improvements beyond that will generally be haphazard,
    e.g., the Vim syntax highlighting code for Python knows basically
    what a function header looks like so it can highlight the
    function name. It also (doesn't really) know how to figure out
    what's a string and what isn't.

    The auto-indenter is often smarter about syntax, but knows just a
    small subset of syntax rules, enought to do proper indenting. For
    some languages, e.g., Python, that's a fairly small subset. For
    others, it's cumbersomely large and Vim's support is cruddy.

    --
    Neil Cerutti
     
    Neil Cerutti, Dec 13, 2007
    #8
  9. SMALLp

    Zentrader Guest

    The OP was not talking about a Python program to check the Pascal
    program as I read it

    > to make application in python
    > that would send code (text) to pascal compiler...and it would return
    > result and then application would show that result.


    So he/she/it would want subprocess to compile the Pascal program/file
    and get the resulting output. Let's not complicate the issue since
    this appears to be someone relatively new to Python.
     
    Zentrader, Dec 13, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ivan Vecerina
    Replies:
    1
    Views:
    1,249
    Jerry Coffin
    Oct 21, 2003
  2. Twinkle
    Replies:
    3
    Views:
    458
    Martin Gregorie
    Apr 16, 2008
  3. LL
    Replies:
    9
    Views:
    524
  4. Pager O Rama

    MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS

    Pager O Rama, Apr 4, 2006, in forum: ASP General
    Replies:
    0
    Views:
    248
    Pager O Rama
    Apr 4, 2006
  5. Jacob Grover
    Replies:
    5
    Views:
    318
    Jacob Grover
    Jul 18, 2008
Loading...

Share This Page