Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Small Parser / processor

Reply
Thread Tools

Small Parser / processor

 
 
Ja0009
Guest
Posts: n/a
 
      10-12-2003
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
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      10-12-2003
"Ja0009" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Ja0009
Guest
Posts: n/a
 
      10-13-2003
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


http://www.velocityreviews.com/forums/(E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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

 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      10-14-2003
Mike Wahler <(E-Mail Removed)> 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.
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      10-14-2003
"Christopher Benson-Manica" <(E-Mail Removed)> wrote in message
news:bmfi2g$nit$(E-Mail Removed)...
> Mike Wahler <(E-Mail Removed)> 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


 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      10-14-2003
(E-Mail Removed) (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.

# (E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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?
 
Reply With Quote
 
Ja0009
Guest
Posts: n/a
 
      10-14-2003
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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> (E-Mail Removed) (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.
>
> # (E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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
> #
> #

 
Reply With Quote
 
Cedric LEMAIRE
Guest
Posts: n/a
 
      10-16-2003
(E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > (E-Mail Removed) (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.
> >
> > # (E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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
> > #
> > #

 
Reply With Quote
 
Ja0009
Guest
Posts: n/a
 
      10-17-2003
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

(E-Mail Removed) (Cedric LEMAIRE) wrote in message news:<(E-Mail Removed). com>...
> (E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > > (E-Mail Removed) (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.
> > >
> > > # (E-Mail Removed) (Ja0009) wrote in message news:<(E-Mail Removed) 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
> > > #
> > > #

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when do I see this? XSLTProcessor processor XSLTProcessor processor brahatha Java 1 06-15-2007 10:52 AM
win xp pro sp2 64 bit is a multi processor or a uni processor =?Utf-8?B?dW1lc2g=?= Windows 64bit 4 08-01-2006 05:24 AM
AMD 64 X2 Processor: Any what to tell what program/process is assigned to processor? The Frozen Canuck Windows 64bit 1 01-16-2006 07:45 PM
Small but significant memory leak in Pyana XSLT processor Ola Natvig Python 1 03-08-2005 02:54 PM
Processor fried, should I upgrade or just buy a processor? Dim Computer Support 6 06-21-2004 08:11 PM



Advertisments