473,557 Members | 2,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Parsing] How do I process loops with PLY?

I'm rather new to high level parsing with lex/yacc (and realy impressed so
far).

I'd like to parse *and execute* files like this:

A=12
B=23
G X=A Y=B Z=34 # Move to X, Y, Z
G Z=0

etc.

No problems so far.

But when loops enter the game, things seem to become more difficult:

A=12
B=23
C=45
D=56
DX=0

FOR C # Exec the following lines C times
G X=A+DX Y=B Z=34 # Move to X, Y, Z

# more statements...

DX=DX+67
NEXT

How can I tell PLY to go back to the beginning of the FOR-loop's body to
execute it C-1 more times? A syntax checker would not need to do that, but
an interpreter (which actually I am building) has to.

Any hints are welcome.

Kind regards
Franz GEIGER
Jul 18 '05 #1
1 1835
"F. GEIGER" <f.******@vol.a t> writes:
But when loops enter the game, things seem to become more difficult:

A=12
B=23
C=45
D=56
DX=0

FOR C # Exec the following lines C times
G X=A+DX Y=B Z=34 # Move to X, Y, Z

# more statements...

DX=DX+67
NEXT

How can I tell PLY to go back to the beginning of the FOR-loop's
body to execute it C-1 more times? A syntax checker would not need
to do that, but an interpreter (which actually I am building) has
to.


Typically, you would separate parsing from executing the code. Use PLY
to parse the whole thing once and produce a data structure
representing the code (usually called an 'abstract syntax tree') then
write an interpreter which uses that tree as its input.

Regards,
--
Edwin
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2232
by: Fuzzyman | last post by:
I want to parse some text and generate an output that is similar but not identical to the input. The string I produce will be of similar length to the input string - but a bit longer. I'm parsing character by character and adding the characters of the input string to the output until I come to ones I want to modify. This means creating a...
77
4520
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a...
0
4108
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We have an schema (s1) on an Oracle 9i database with database links pointing to a schema (s2) on another Oracle 9i database.
8
1711
by: Darius Fatakia | last post by:
Hello, I have a file that I have opened for reading and this file contains lines with several different types of constraint information. For example, here are a few lines: length(0) = 10 Duration of task 0 is 10. needs(16,1) Operation 16 uses resource 1. before(49,9) Operation 49 must be before operation 9.
2
999
by: Wade G | last post by:
How do I use XmlDocument class to parse an xml file such as the following - note the key issue is the number of <stuff> elements is not fixed so if I use m_nodelist = m_xmld.SelectNodes("/start/level/stuff") to process the nodes they all run together and I can't separate them by the <level> that they are at because the number of times they...
22
1496
by: gene.ariani | last post by:
I have a string like the following: 10AF101-25 I would like to extract any numerical number that precedes the "-" and stops when it encounters any string character like AF So my result should be 101.
3
4367
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
9
1973
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a...
3
4676
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I've come to the conclusion that a scripting language will make a fine solution for a feature that I want to program for an app. I do not expect any problems parsing the script the old fashion way by manually searching the string. However, if there are good tools - tutorials - on the matter I would like to know about it. I've come...
0
7835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5455
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1164
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.