PLY 0.1
Primitive Lex Yacc

Copyright 2007 Logan Lee

WHAT IS PLY?
PLY roughly emulates lex & yacc UNIX tools commonly used to generate compilers. It is written entirely in Bash script and operates in Bash shell environment. You can use PLY to parse a combination of known tokens and to execute them in a meaningful way.

INSTALLATION
PLY reads off two files - ply_source and ply_combo. ply_source contains your 'source code', and ply_combo contains definitions to a combination of tokens. To run PLY, you must define 'combos' to be used to parse your source by editing ply_combo file, then write your code in a meaningful way(able to be parse through using rules in ply_combo) in ply_source file. Then you execute parser program, which will hopefully generate for you a working script named 'run'. run file should be executable by doing 'source run` in your current directory.

USAGE
Let's look at a sample ply_combo file:
	? = ? : export ?1=?2 && echo $?1
	? u= ? : unset ?1 && echo $?1

I'll explain this line by line. '?' means non-tags, which may be substituted by anything that is not one of defined tags. '=' is a tag that you have defined right here. '?1' refers to the value of the first '?' as in '? = ?', and of course ?2 refers to the value of the second occurring '?' on the left hand side(before ':'). The line 1 is saying that if the parser recognizes the pattern '? = ?', then execute the right portion after ':', that is 'export ?1=?2 && echo $?1'. The line 2 is saying that if the parser recognizes the pattern '? u= ?', then execute 'unset ?1 && echo $?1'. Note that you must separate non-tags(?) and tags(=, u=, or any other you define) must be separated by space or blank on the left hand side.

Let's now look at a sample ply_source file:
	apple = red
	banana u= yellow
	pineapple = green

The first and third lines match with the pattern '? = ?' as defined in our sample ply_combo file above. The second line matches with '? u= ?'. So as you can guess, the parser will come and parse the file line by line then execute 'export ?1=?2 && echo $?1' for lines 1 and 3, and execute 'unset ?1 && echo $?1' for line 2. If you are still confused by ?1 or ?2, let me spell out precisely what will be executed for line 2:
	unset pineapple && echo $pineapple

Obviously, since you have just unset the variable pineapple, the value of it will be null.

To do the parsing and to generate run file do:
	$ parser

If you execute parser using the given sample ply_source and ply_combo files, the following run file will be generated:
	export apple=red && echo $apple
	unset banana && echo $banana
	export pineapple=green && echo $pineapple

You should realize by now that applying the given example above, you can create your own syntax and to parse and to generate run file for it using PLY. 

If you have any questions or suggestions or comments please direct them to 10464307@uts.edu.au.
