Analyze lists using bash scrip

Completed Posted Feb 18, 2013 Paid on delivery
Completed Paid on delivery

I Need a bash script that does the following:

step 1: parse

You are given 2 lists of strings.

In the first list each entry has the following format:

@protocol protocolName

we will define a hashmap

var protocolToSuperProtocols = new hashmap<string, set>

protocolToSuperProtocols should contain all protocolNames as keys, and a list of implementedProtocol as the values.

* Ignore any trailing spaces

* if an implementedProtocol appears more than once, add it only one

Example:

@protocol p1

@protocol p2

@protocol p4

will output:

protocolToSuperProtocols='([p1]="p2,p3" , [p2]="", [p4]="p5" )'

The second list contains the following entries:

@interface className : superClass

the entries must have className but superClass and implementedProtocol list are optional.

lets define two hashMaps:

var classToSuperClass = new hashmap

var classToProtocols = new hashmap<string, set>

classToSuperClass will contain className as key and superClass as value

* if a class does not have a superclass, ignore the entry

* a class will have only one superclass

* ignore spaces

classToProtocols will contain className as key and the list of implementedProtocol as value

* if a class has implementedProtocol it will always have a super class

* if a class does not have implementedProtocol list, leave blank

* if a value repeats itself in implementedProtocol list, add it only once

* ignore spaces

example:

@interface A : B

@interface B : C

@interface D

@interface C : D

will output:

classToSuperClass ='([A]="B" , [B]="C", [C]="D", [D]="" )'

classToProtocols ='([A]="" , [B]="p1,p2,p3", [C]="p1,p4", [D]="" )'

step 2: processing

we will define our result datastructure:

var protocolToImps = new hashmap<string, set >

do the following:

for (classToSuperClass as (className => superClass)) {

travereOverClassHierarchAndAct(className);

}

echo protocolToImps;

function travereOverClassHierarchAndAct(className) {

if (className == null) return;

implementingProtocols = classToProtocols[className];

addBindToResultList(className, implementingProtocols);

superClass = classToSuperClass[className];

travereOverClassHierarchAndAct(superClass)

}

function addBindToResultList(classname, protocolList) {

if (protocolList == null) return;

for (implementingProtocols as protocol) {

protocolToImps[protocol] += className;

addBindToResult(className, protocolToSuperProtocols[protocol] );

}

}

the following should output (for the above dataset):

protocolToImps ='([p1]="A,B,C",[p2]="A,B,C",[p3]="A,B,C",[p4]="A,B,C",[p5]="A,B,C")'

*Please not that == null means empty list or undefined key

*There should be not circular dependencies in the data set

*Please use bash 4 with associative arrays and test for bash script version in the beginning of the script

Mac OS Shell Script

Project ID: #4256753

About the project

4 proposals Remote project Active Feb 27, 2013

Awarded to:

kaloyan13

Bash programmer.

$40 USD in 2 days
(281 Reviews)
7.0

4 freelancers are bidding on average $55 for this job

gyaseen1986

Hi there, i am very interested to complete this project. please see my past reviews lets complete this project

$50 USD in 3 days
(17 Reviews)
4.6
srinichal

Ready to discuss further

$80 USD in 3 days
(8 Reviews)
4.3
mantzoun

I've been using bash scripts in my work extensively for the past 6 years, so this project shouldn't be any problem. However I will need additional clarifications, because it is not clear to me in the examples you pr More

$50 USD in 3 days
(0 Reviews)
0.0