NAME

Soar::Production::Parser - PARSES SOAR PRODUCTIONS

VERSION

version 1.122830

SYNOPSIS

use Soar::Production::Parser;
use Data::Dumper;
my $parser = Soar::Production::Parser->new;
my @trees=$parser->parse_file("foo.soar");
print Dumper(\@trees);

DESCRIPTION

Soar is a cognitive modeling architecture for programming and experimenting with intelligent agents. Soar is programmed using productions that look like this:

sp{name
	(state <s>)
	-->
	(<s> ^foo bar)
}

The preceding production matches any state and adds an element named "foo" with the value "bar" to it. Productions can get much more complicated than that. This module can be used to parse these productions. Underlyingly, a Parse::RecDescent grammar is used to convert a production into a parse tree. There are also methods for extracting all of the productions from a file string, and to remove comments (not that I think you'll ever want to do that!).

NAME

Soar::Production::Parser - Perl extension for parsing angst grammar files

METHODS

new

Creates a new parser.

parse_text

Argument: the text of a single Soar production. Returns: a parse tree for the given production.

get_parses

Argument: Reference to array containing text for individual productions. Return: Reference to an array containing parse trees for each of the productions in the input array reference.

no_comment

Argument: Text which contains Soar productions or commands Return: Same text, but with all comments removed. Comments are indicated with a # (pound), optionally preceded by a ; (semicolon) and whitespace.

productions

This method extracts productions from a given text. It returns a reference to an array containing either the text of each of the productions, or a parse tree for each of them. Note that all comments are removed as a preprocessing step to detecting and extracting productions. It takes a set of named arguments: 'file'- the name of a file to read. 'text'- the text to split. 'parse'- set to true if the return value should be an array of parse trees for the extracted productions; otherwise an array containing the production text will be returned. For example, if you would like to extract all of the productions from a file and print their parse trees, you could do this:

    use Soar::Production::Parser;
	use Data::Dumper;
	
	my $file = shift;
	my $parser = Soar::Production::Parser->new();
	my $parses = $parser->productions(
		file => $file,
		parse => 1
	);
	
	for my $prod(@$productions){
		print Dumper($prod);
	}

SEE ALSO

The documentation for Soar is located at https://code.google.com/p/soar/. You may also be interested in what a production system is, since this module parses Soar productions: http://en.wikipedia.org/wiki/Production_system.

AUTHOR

Nathan Glenn <garfieldnate@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Nathan Glenn.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.