Hello,

I'm going to be working on Lexical Analysis, but, both in Words / Characters as well as Integer values. The application will also allow input from both Text files, as well as passing the data through arrays, or variables. The Numeric analysis will be different from the Lexical Analysis in a few different ways, but they will each share the same method(s) of parsing in the data (In some way or another).

My first project with using the Lexical Analysis is to create an Application that enables me to pass in a piece of course work, which, parses in the data and then counts the number of words / characters there are, as well as checking for particular keywords that HAVE to be included in the assignment, and then after this, the particular assignment will be converted to PDF.

This is just one of the uses, but, in the future I want to be able to handle (for example) syntax highlighting..

I don't want help with code, I just need some advice on how to structure it..

I was thinking this:
1. Have an interface class that contains all the methods needed
2. Create a a base class that implements this particular interface
3. Create two more classes "Numeric", "Lexical" which inherit from the base class.

Would this work? Or would it better to have an interface for each of the Numeric, Lexical?

But the only problem is handling the methods for say, reading an entire word document, or just reading two arrays (for example). Would I therefore have to somehow override the parser function and then determine whether it's a word file, or it's an array?

The other thing is (lol) I want to be able to implement a new object/method of the object like this:

 <?php

        $this->Numeric->parser("numbers.doc"); // This would then load in a numeric file
        $this->Lexical->parser("document.doc"); // This would then load in a word/character file

            $this->Lexical->Characters('GET_NUMBER'); // This returns the number of characters      
    ?>

Could anyone offer any advice? Thanks :)

Would this work? Or would it better to have an interface for each of the Numeric, Lexical?

Yes, that would work. Although, if you are just implementing the interface for the base class, what's the point? You can just define public methods in the base class, which can then be used in the descendant classes. IMO an interface does not provide you additional help/structure here.

I'm not quite sure I know what you mean with your last question. Do you mean parser('file') is a static factory method, returning a class instance?

Hello,

Thanks for your reply...

Basically, the parser will allow for the data to be parsed through both file (e.g. .doc, .txt etc) as well as just an array so e.g:

<?php

   $this->Numeric->parser('file.txt');
   // OR
   $numerbers = array(1, 2, 3, 4, 5, 6);
   $this->Numeric->parser($numbers);
   ?>

Thanks :) but I don't want to change the name of the parser.. So it woudn't be like: parserTXT etc

Okay. If parser is a function that accepts different parameters, it is non-standard. You can pass a mixed parameter and check it's type. Depending on the type (string for file, of array) you can choose your processing.

Thanks for your reply. So the parser (function) would have an if statement that determined whether the parameter is infact a file or an array.. ?

Yes. Because in PHP you cannot have two methods with the same name, but with different parameters (yet).

Personally, I'd have two different methods. One for the array, and one for the file, which after loading the file's contents into an array will call the first one.

ay, and one for the file, which after loading the file's contents into an array will call the

Thanks for the advice :) I'll give that a go!

I'm trying to make this into a Platform, which then people can use for Data Analysis so I need it to be structured correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.