473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Exact constant representation in compiler Const node needed?


I think for some purposes it might be handy to have and exact value representation
in the compiler parse tree, without having to use strings as carrier. I.e.,
from exactdec import ED
import compiler
compiler.parse('.1','eval') Expression(Const(0.10000000000000001)) compiler.parse('.1','eval').node.value 0.10000000000000001 ED(compiler.parse('.1','eval').node.value,'all') ED('0.10000000000000000555111512312578270211815834 04541015625')

Obviously the constant is a floating point number, but should one have to write one's
own parser based on tokenizer output in order to use the numeric literal differently,
e.g. as representing an _exact_ value? Is the conversion to floating point premature?

From a little utility that uses the tokenizer, one sees NUMBER identified, but the value
still in string form. Perhaps the Const instance could have the string value as well, in case
someone wants to re-interpret it exactly?

[18:43] C:\pywk\Decimal>echo .1 |python C:\pywk\tok\prtokens.py -
---- - ----
<NUMBER '.1'> <NEWLINE '\n'>
<ENDMARKER ''>

Even the sign on signed numbers is separate in this low level stuff, and the comma operators
are just tokenized not parsed. Hate to have to go back to that stream to get the info:

[18:46] C:\pywk\Decimal>echo 1, -1, 1., .1, 'sss' |python C:\pywk\tok\prtokens.py -
---- - ----
<NUMBER '1'> <OP ','> <OP '-'> <NUMBER '1'> <OP ','> <NUMBER '1.'> <OP ','> <NUMBER '.1'> <OP ',
'> <STRING "'sss'"> <NEWLINE '\n'>
<ENDMARKER ''>

vs
compiler.parse("1, -1, 1., .1, 'sss'",'eval').node.nodes

[Const(1), UnarySub(Const(1)), Const(1.0), Const(0.10000000000000001), Const('sss')]
Is there an easy way I can write a walker/visitor that can access the source text of nodes
so I can rewrite using exact math if I want to? (Not that this is an important immediate goal,
it just occurred to me after writing the little exactdec.py module ;-)

Regards,
Bengt Richter
Jul 18 '05 #1
0 1275

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

Similar topics

6
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
20
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to...
3
by: William Payne | last post by:
Hi, I recently upgraded my compiler to a version that's a lot more touchy about code not conforming to the ISO standard. Right now I am in the process of compiling my old programs with the new...
4
by: cayblood | last post by:
Hello, I have the following class declaration in an include file: class Node { public: Node(string name = ""); Node(const Node& node); Node& operator=(const Node& node); bool...
11
by: Mantorok Redgormor | last post by:
Is const really constant? And on an OT note: how can I post with a modified e-mail address so I don't get so much spam?
13
by: devdatta_clc | last post by:
Hi C experts I've a bunch of questions. Consider this simplified piece of code. const int a = 10; int main () { static int b = a;
20
by: karthikbalaguru | last post by:
Hi, String constant being modifiable in C++ but, not modifiable in C. that is, In C++, the following example output will be "Mplusplus" char *str1 = "Cplusplus"; *str1 = 'M'; In C, the above...
22
by: Tomás Ó hÉilidhe | last post by:
I've been developing a C89 microcontroller application for a while now and I've been testing its compilation using gcc. I've gotten zero errors and zero warnings with gcc, but now that I've moved...
8
by: PJ6 | last post by:
Const factor As Double = Math.Sqrt(3) / 6 Error 1 Constant expression is required. This looks like laziness to me. In SQL Server, functions are given a distinction between ones that always...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.