472,984 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 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 5719
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

84
by: Andy Glew | last post by:
I am in search of any rigourous, scientific, academic or industrial studies comparing naming conventions in C++ or similar languages such as Ada: Specifically, are names formed with...
4
by: Chris Gordon-Smith | last post by:
I am tying to call a Pascal function from C++, and vice versa. Does anyone know how to do this, or where detailed information on this topic can be found? For the C++ to Pascal call I have...
28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
3
by: Bas Wassink | last post by:
Hello there, I'm having trouble understanding a warning produced by 'splint', a code-checker. The warning produced is: keywords.c: (in function keyw_get_string) keywords.c:60:31: Released...
6
by: Don | last post by:
I am looking for a C/C++ code spell checker, a tool that checks for spelling errors in C++ source code. Linux/Unix platforms. Prefer command line tool. Open source preferred, but will consider...
3
by: =?gb2312?B?zfW2rA==?= | last post by:
I need a C++ code style checker. Which is the best choice? free or for fee.
3
by: abraxas91 | last post by:
Hi, my name is Stephan. I've been working on this program off and on over the past few days. I have yet to perfect it. I would really appreciate any help! For some reason the output begins to...
6
by: sanjay | last post by:
Hi, Is there any tool that would do static detection (doesnt execute the application) of dead code for C++ application. Few tools do show which code flow would never get executed, but i am...
3
by: Mike | last post by:
I have an app running at a client where, when the spell checker is supposed to run, it reports "Can't start spell checker because it is not installed". I have never had this before - it works...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.