473,386 Members | 1,708 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.

Small Parser / processor

Hello,
I need a small help with peace of code, does not have to be
whole code.
I need function or similar that can read from infile.txt open rules.txt
and read or import 'rules' to process and write to outfile.txt
results.
Rules in rules.txt
are like this:
[Case1]
9,5 = 70435
186,6 ="SELKOW"
86,3 ="ACC"
[Case2]
9,4 = 4330
22,2 <> "GY"
112, 2 = 18

where
9,5 = 70435
means that from character 9 next 5 char are 70435

Output should be like
"#0001 - Case1"
"#0002 - Case2"
"#0003 - NO RULE FOUND" where "#0001 is line number and
CaseX is Casename

Thank you in advance
Nov 13 '05 #1
8 1578
"Ja0009" <li*********@linkseurope.com> wrote in message
news:2e*************************@posting.google.co m...
Hello,
I need a small help with peace of code,

If you want help with a piece of code, you need
to show us that code, and ask specific questions.
does not have to be
whole code.
Which implies to me that you already have part of it.
Where is it?
I need function or similar that can read from infile.txt open rules.txt
and read or import 'rules' to process and write to outfile.txt
results.
Rules in rules.txt
are like this:
[Case1]
9,5 = 70435
186,6 ="SELKOW"
86,3 ="ACC"
[Case2]
9,4 = 4330
22,2 <> "GY"
112, 2 = 18

where
9,5 = 70435
means that from character 9 next 5 char are 70435

Output should be like
"#0001 - Case1"
"#0002 - Case2"
"#0003 - NO RULE FOUND" where "#0001 is line number and
CaseX is Casename


If you want this program written for you, hire a
programmer. I'm available for hire. :-)

-Mike
Nov 13 '05 #2
I am just figguring out.
So I'll make variables to hold strins, in each line test
for value and than apply to function or expression for futher processing.
Thanks.
P.S. I am concerned the most with how to apply rules.txt to my program.
Regards
li*********@linkseurope.com (Ja0009) wrote in message news:<2e*************************@posting.google.c om>...
Hello,
I need a small help with peace of code, does not have to be
whole code.
I need function or similar that can read from infile.txt open rules.txt
and read or import 'rules' to process and write to outfile.txt
results.
Rules in rules.txt
are like this:
[Case1]
9,5 = 70435
186,6 ="SELKOW"
86,3 ="ACC"
[Case2]
9,4 = 4330
22,2 <> "GY"
112, 2 = 18

where
9,5 = 70435
means that from character 9 next 5 char are 70435

Output should be like
"#0001 - Case1"
"#0002 - Case2"
"#0003 - NO RULE FOUND" where "#0001 is line number and
CaseX is Casename

Thank you in advance

Nov 13 '05 #3
Mike Wahler <mk******@mkwahler.net> spoke thus:
If you want this program written for you, hire a
programmer. I'm available for hire. :-)


I hope this is tongue-in-cheek and not indicative of actual unemployment ;)

--
Christopher Benson-Manica | Upon the wheel thy fate doth turn,
ataru(at)cyberspace.org | upon the rack thy lesson learn.
Nov 13 '05 #4
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:bm**********@chessie.cirr.com...
Mike Wahler <mk******@mkwahler.net> spoke thus:
If you want this program written for you, hire a
programmer. I'm available for hire. :-)


I hope this is tongue-in-cheek and not indicative of actual unemployment

;)

I can always use extra 'beer money' :-)

-Mike
Nov 13 '05 #5
li*********@linkseurope.com (Ja0009) wrote:
# I am just figguring out.
# So I'll make variables to hold strins, in each line test
# for value and than apply to function or expression for futher processing.
# Thanks.
# P.S. I am concerned the most with how to apply rules.txt to my program.
# Regards

Is there a reason why this has to be C? In other languages like Perl or Tcl,
you can probably code a solution in an hour or much less.

# li*********@linkseurope.com (Ja0009) wrote in message news:<2e*************************@posting.google.c om>...
# > Hello,
# > I need a small help with peace of code, does not have to be
# > whole code.
# > I need function or similar that can read from infile.txt open rules.txt
# > and read or import 'rules' to process and write to outfile.txt
# > results.
# > Rules in rules.txt
# > are like this:
# > [Case1]
# > 9,5 = 70435
# > 186,6 ="SELKOW"
# > 86,3 ="ACC"
# > [Case2]
# > 9,4 = 4330
# > 22,2 <> "GY"
# > 112, 2 = 18
# >
# > where
# > 9,5 = 70435
# > means that from character 9 next 5 char are 70435
# >
# > Output should be like
# > "#0001 - Case1"
# > "#0002 - Case2"
# > "#0003 - NO RULE FOUND" where "#0001 is line number and
# > CaseX is Casename
# >
# > Thank you in advance
#
#

--
Derk Gwen http://derkgwen.250free.com/html/index.html
If your job was as meaningless as theirs, wouldn't you go crazy too?
Nov 13 '05 #6
Thanks Derk,
should be basic,pascal or c,c++.
As I am not familiar with basic or pascal, in C/C++ not so much experienced but
I can try :)
You are right I would do same thing in ASP/VB or Java/JavaScript or
XSL good but hm here I have a problem :(.
RGS

Derk Gwen <de******@HotPOP.com> wrote in message news:<vo************@corp.supernews.com>...
li*********@linkseurope.com (Ja0009) wrote:
# I am just figguring out.
# So I'll make variables to hold strins, in each line test
# for value and than apply to function or expression for futher processing.
# Thanks.
# P.S. I am concerned the most with how to apply rules.txt to my program.
# Regards

Is there a reason why this has to be C? In other languages like Perl or Tcl,
you can probably code a solution in an hour or much less.

# li*********@linkseurope.com (Ja0009) wrote in message news:<2e*************************@posting.google.c om>...
# > Hello,
# > I need a small help with peace of code, does not have to be
# > whole code.
# > I need function or similar that can read from infile.txt open rules.txt
# > and read or import 'rules' to process and write to outfile.txt
# > results.
# > Rules in rules.txt
# > are like this:
# > [Case1]
# > 9,5 = 70435
# > 186,6 ="SELKOW"
# > 86,3 ="ACC"
# > [Case2]
# > 9,4 = 4330
# > 22,2 <> "GY"
# > 112, 2 = 18
# >
# > where
# > 9,5 = 70435
# > means that from character 9 next 5 char are 70435
# >
# > Output should be like
# > "#0001 - Case1"
# > "#0002 - Case2"
# > "#0003 - NO RULE FOUND" where "#0001 is line number and
# > CaseX is Casename
# >
# > Thank you in advance
#
#

Nov 13 '05 #7
li*********@linkseurope.com (Ja0009) wrote in message news:<2e************************@posting.google.co m>...

If it could be in a scripting language, you'll find below your program
written
in CodeWorker (http://www.codeworker.org).

If not, it gives you the outline to follow for writing it in a
general-purpose programming language.

//------------------------- file "ja0009.gen"
----------------------------
traceLine("Example of command line:");
traceLine("\tCodeWorker -script ja0009.gen");
traceLine("\t\t-D INPUT=infile.txt -D RULES=rules.txt -D
OUTPUT=outfile.txt");

if !getProperty("INPUT") error("input filename expected; type -D
INPUT=<infile.txt>");
if !getProperty("RULES") error("filename of rules expected; type -D
RULES=<rules.txt>");
if !getProperty("INPUT") error("output filename expected; type -D
OUTPUT=<outfile.txt>");

/**
* Parsing of rules. Structure of the parse tree:
* cases[]: array of cases,
* |
* +-- antecedents[]: array of conditions the rule must validate,
* |
* +-- position: position in the line (starting at
0),
* |
* +-- operator: '=' or "<>"
* |
* +-- constant: string or value to compare
**/
parseAsBNF(
{
rules ::=
=> local iCase = 1;
#ignore(blanks)
[
case(iCase)
=>increment(iCase);
]*
;
case(iCase : value) ::= '[' "Case" #readText(iCase) ']'
[antecedent(iCase)]*;
antecedent(iCase : value) ::=
#readInteger:iPosition ',' #readInteger
=> decrement(iPosition);
=> pushItem this.cases[iCase].antecedents;
=> localref current = this.cases[iCase].antecedents#back;
=> insert current.position = iPosition;
['=' | "<>"]:current.operator
[#readNumeric:current.constant |
#readCString:current.constant]
;
}, project, getProperty("RULES"));

// Make the output file empty
deleteFile(getProperty("OUTPUT"));

/**
* Splitting of the input file to lines, and iteration of cases up to
find
* one that matches. Result of the study in the output file.
**/
parseAsBNF(
{
infile_parser ::=
=> local iLine = 1;
[
[->['\n' | #empty]]:sLine
=> {
local iCase; // number of the rule that matches
foreach i in this.cases {
local bAccept; // do we accept a case?
foreach j in i.antecedents {
local bFound = (sLine.findNextString(j.constant,
j.position) == j.position);
set bAccept = (bFound == (j.operator == '='));
if !bAccept break; // all antecedents must match
}
if bAccept {
set iCase = i.key();
break;
}
}
local iFormatedNumber = iLine.completeLeftSpaces(4);
set iFormatedNumber = iFormatedNumber.replaceString(' ',
'0');
local sOutput = '#' + iFormatedNumber + " - ";
if iCase set sOutput += "Case" + iCase;
else set sOutput += "NO RULE FOUND";
appendFile(getProperty("OUTPUT"), sOutput + endl());
}
=> increment(iLine);
]*
;
}, project, getProperty("INPUT"));
//---------------------------- end of file
--------------------------------

Derk Gwen <de******@HotPOP.com> wrote in message news:<vo************@corp.supernews.com>...
li*********@linkseurope.com (Ja0009) wrote:
# I am just figguring out.
# So I'll make variables to hold strins, in each line test
# for value and than apply to function or expression for futher processing.
# Thanks.
# P.S. I am concerned the most with how to apply rules.txt to my program.
# Regards

Is there a reason why this has to be C? In other languages like Perl or Tcl,
you can probably code a solution in an hour or much less.

# li*********@linkseurope.com (Ja0009) wrote in message news:<2e*************************@posting.google.c om>...
# > Hello,
# > I need a small help with peace of code, does not have to be
# > whole code.
# > I need function or similar that can read from infile.txt open rules.txt
# > and read or import 'rules' to process and write to outfile.txt
# > results.
# > Rules in rules.txt
# > are like this:
# > [Case1]
# > 9,5 = 70435
# > 186,6 ="SELKOW"
# > 86,3 ="ACC"
# > [Case2]
# > 9,4 = 4330
# > 22,2 <> "GY"
# > 112, 2 = 18
# >
# > where
# > 9,5 = 70435
# > means that from character 9 next 5 char are 70435
# >
# > Output should be like
# > "#0001 - Case1"
# > "#0002 - Case2"
# > "#0003 - NO RULE FOUND" where "#0001 is line number and
# > CaseX is Casename
# >
# > Thank you in advance
#
#

Nov 13 '05 #8
Thanks,
I believe that CodeWorker does the work
perfect.
Anywhere it needs to be in C or C++
At the moment I am writing it in C
but am I still trying to pass (read) rules to
program (function)
Ned

co********@free.fr (Cedric LEMAIRE) wrote in message news:<db**************************@posting.google. com>...
li*********@linkseurope.com (Ja0009) wrote in message news:<2e************************@posting.google.co m>...

If it could be in a scripting language, you'll find below your program
written
in CodeWorker (http://www.codeworker.org).

If not, it gives you the outline to follow for writing it in a
general-purpose programming language.

//------------------------- file "ja0009.gen"
----------------------------
traceLine("Example of command line:");
traceLine("\tCodeWorker -script ja0009.gen");
traceLine("\t\t-D INPUT=infile.txt -D RULES=rules.txt -D
OUTPUT=outfile.txt");

if !getProperty("INPUT") error("input filename expected; type -D
INPUT=<infile.txt>");
if !getProperty("RULES") error("filename of rules expected; type -D
RULES=<rules.txt>");
if !getProperty("INPUT") error("output filename expected; type -D
OUTPUT=<outfile.txt>");

/**
* Parsing of rules. Structure of the parse tree:
* cases[]: array of cases,
* |
* +-- antecedents[]: array of conditions the rule must validate,
* |
* +-- position: position in the line (starting at
0),
* |
* +-- operator: '=' or "<>"
* |
* +-- constant: string or value to compare
**/
parseAsBNF(
{
rules ::=
=> local iCase = 1;
#ignore(blanks)
[
case(iCase)
=>increment(iCase);
]*
;
case(iCase : value) ::= '[' "Case" #readText(iCase) ']'
[antecedent(iCase)]*;
antecedent(iCase : value) ::=
#readInteger:iPosition ',' #readInteger
=> decrement(iPosition);
=> pushItem this.cases[iCase].antecedents;
=> localref current = this.cases[iCase].antecedents#back;
=> insert current.position = iPosition;
['=' | "<>"]:current.operator
[#readNumeric:current.constant |
#readCString:current.constant]
;
}, project, getProperty("RULES"));

// Make the output file empty
deleteFile(getProperty("OUTPUT"));

/**
* Splitting of the input file to lines, and iteration of cases up to
find
* one that matches. Result of the study in the output file.
**/
parseAsBNF(
{
infile_parser ::=
=> local iLine = 1;
[
[->['\n' | #empty]]:sLine
=> {
local iCase; // number of the rule that matches
foreach i in this.cases {
local bAccept; // do we accept a case?
foreach j in i.antecedents {
local bFound = (sLine.findNextString(j.constant,
j.position) == j.position);
set bAccept = (bFound == (j.operator == '='));
if !bAccept break; // all antecedents must match
}
if bAccept {
set iCase = i.key();
break;
}
}
local iFormatedNumber = iLine.completeLeftSpaces(4);
set iFormatedNumber = iFormatedNumber.replaceString(' ',
'0');
local sOutput = '#' + iFormatedNumber + " - ";
if iCase set sOutput += "Case" + iCase;
else set sOutput += "NO RULE FOUND";
appendFile(getProperty("OUTPUT"), sOutput + endl());
}
=> increment(iLine);
]*
;
}, project, getProperty("INPUT"));
//---------------------------- end of file
--------------------------------

Derk Gwen <de******@HotPOP.com> wrote in message news:<vo************@corp.supernews.com>...
li*********@linkseurope.com (Ja0009) wrote:
# I am just figguring out.
# So I'll make variables to hold strins, in each line test
# for value and than apply to function or expression for futher processing.
# Thanks.
# P.S. I am concerned the most with how to apply rules.txt to my program.
# Regards

Is there a reason why this has to be C? In other languages like Perl or Tcl,
you can probably code a solution in an hour or much less.

# li*********@linkseurope.com (Ja0009) wrote in message news:<2e*************************@posting.google.c om>...
# > Hello,
# > I need a small help with peace of code, does not have to be
# > whole code.
# > I need function or similar that can read from infile.txt open rules.txt
# > and read or import 'rules' to process and write to outfile.txt
# > results.
# > Rules in rules.txt
# > are like this:
# > [Case1]
# > 9,5 = 70435
# > 186,6 ="SELKOW"
# > 86,3 ="ACC"
# > [Case2]
# > 9,4 = 4330
# > 22,2 <> "GY"
# > 112, 2 = 18
# >
# > where
# > 9,5 = 70435
# > means that from character 9 next 5 char are 70435
# >
# > Output should be like
# > "#0001 - Case1"
# > "#0002 - Case2"
# > "#0003 - NO RULE FOUND" where "#0001 is line number and
# > CaseX is Casename
# >
# > Thank you in advance
#
#

Nov 13 '05 #9

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

Similar topics

2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
3
by: Simon Foster | last post by:
Anyone have any experience or pointers to how to go about creating a parser lexer for assemble in Python. I was thinking of using PLY but wonder whether it's too heavyweight for what I want. ...
1
by: Ola Natvig | last post by:
Hi all I'm working with a long running, threaded server which serves HTTP requests with content which are passed through a XSLT processor. The XSLT processor I'm using is the Pyana processor. ...
0
by: Pud | last post by:
Hiya, I was wondering if anyone could help me, I am trying to create an example program that uses the xerces XML parser in Java. Unfortunately I have come across a problem when using this...
7
by: Michael | last post by:
Hi, I have a problem parsing XML file using XSLT stylesheet by using : using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; // load Xsl stylesheet XslTransform myXslTrans = new...
4
by: M Arora | last post by:
Hi All I am using Xerces parser to convert my xml to the output given below and for this i am using the xslt. How shall i create href attribute in xerces parser? When i am using MSDOM parser...
8
by: Elmar Brandt | last post by:
Hello, we are looking for a fast XML parser. The XML-files are very big (>2GB) and we want to convert them into other formats via XSLT. Has anyone an idea? With best regards Elmar Brandt
11
by: Jean-François Michaud | last post by:
Hello all, I'm having a little problem, The UTF-8 parser we are using converts the newline entity ( ) within an attribute that we are using to paliate CSS limitations. After the parser has...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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,...

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.