Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
namelessjon committed May 11, 2012
1 parent 33c7112 commit 492c001
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions README.rdoc
Expand Up @@ -5,35 +5,33 @@ implement simple (or not so simple) parsing of mathematics for Exalted character
sheets. Although I'm sure it could be used for other simple math situations. sheets. Although I'm sure it could be used for other simple math situations.
It consists of two parts; parser and abstract syntax tree. The parser It consists of two parts; parser and abstract syntax tree. The parser
constructs the abstract syntax tree as it parses the input string. The AST can constructs the abstract syntax tree as it parses the input string. The AST can
then be used to compute the value of the expression with a given context. The then be used to compute the value of the expression with a given context.
AST also has a simple method to simplify it if possible. The AST is based on an The AST can also simply itself, factoring out constant operations in some cases.
array class, which makes it very easy to serialize.


== Examples == Examples


@parser = Exalted::MathsParser.new @parser = ExaltedMath::MathsParser.new


# simple maths # simple maths
# The ast method results a two-tuple. # The parser returns the AST
# The first value is the success or failure of the parse # it raises a ParseFailedError in the case of error
# The second value is the AST, or failure message if it failed
@parser.ast('3 + 4') @parser.ast('3 + 4')
#=> true, simple_ast #=> simple_ast


# symbolic values # symbolic values
@parser.ast('Essence * 4') @parser.ast('Essence * 4')
#=> true, symbolic_ast #=> symbolic_ast


# complex maths # complex maths
@parser.ast('(Essence * 4) + Willpower + highest[2](Compassion,Conviction,Temperance,Valor)') @parser.ast('(Essence * 4) + Willpower + highest[2](Compassion,Conviction,Temperance,Valor)')
#=> true, complex_ast #=> complex_ast


# evaluate the Ast # evaluate the Ast
Exalted::Ast.value(simple_ast) simple_ast.value
#=> 7 #=> 7


# evaluate a more complex Ast # evaluate a more complex Ast
Exalted::Ast.value(symbolic_ast, {'essence' => 4}) symbolic_ast.value({'essence' => 4})
#=> 16 #=> 16


== Syntax == Syntax
Expand Down

0 comments on commit 492c001

Please sign in to comment.