471,344 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Pascal code checker!

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!
Dec 12 '07 #1
7 5349
You can use subprocess to run the pascal program and capture the
output/results. See here
http://blog.doughellmann.com/2007/07...ubprocess.html
Dec 12 '07 #2
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

Dec 12 '07 #3
On 2007-12-12, SMALLp <po***@email.t-com.hrwrote:
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?
Dec 12 '07 #4
On Dec 12, 3:03 pm, Tim Chase <python.l...@tim.thechases.comwrote:
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
Dec 12 '07 #5
>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


Dec 12 '07 #6
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
Dec 13 '07 #7
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.
Dec 13 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Chris Gordon-Smith | last post: by
28 posts views Thread by Skybuck Flying | last post: by
3 posts views Thread by =?gb2312?B?zfW2rA==?= | last post: by
6 posts views Thread by sanjay | last post: by
3 posts views Thread by Mike | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.