{- Copyright 2010 Dominique Devriese This file is part of the grammar-combinators library. The grammar-combinators library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Foobar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Foobar. If not, see . -} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE FlexibleContexts #-} import Text.GrammarCombinators.Parser.RecursiveDescent import Text.GrammarCombinators.Parser.Packrat import Text.GrammarCombinators.Base import Text.GrammarCombinators.Utils.PrintGrammar import Text.GrammarCombinators.Utils.CalcFirst import Text.GrammarCombinators.Utils.IsReachable import Text.GrammarCombinators.Utils.EnumTokens import Text.GrammarCombinators.Transform.UnfoldRecursion import Text.GrammarCombinators.Transform.LeftCorner import Text.GrammarCombinators.Transform.UniformPaull import Text.GrammarCombinators.Transform.FilterDies import Text.GrammarCombinators.Transform.UnfoldDead import Text.GrammarCombinators.Transform.PenalizeErrors import Text.GrammarCombinators.Parser.Parsec import Text.GrammarCombinators.Parser.PenaltyParser import Text.GrammarCombinators.Parser.UUParse import Text.GrammarCombinators.Test.Evaluator import Text.GrammarCombinators.Test.Grammar import qualified Text.ParserCombinators.Parsec as Parsec test1 = "((2+1)*2)*(3+4)" evalgram :: ProcessingContextFreeGrammar ASTNode ASTToken NodeValue evalgram = applyProcessor grammar evaluator prTest1 = parsePackrat evalgram AdditiveExpr test1 rdTest1 = parseRecDec evalgram AdditiveExpr test1 psTest1 = parseParsec evalgram AdditiveExpr "test1" test1 uuTest1 = parseUU evalgram AdditiveExpr test1 main = case parseParsec (filterDies (unfoldDead (transformLeftCorner evalgram))) (LCBase AdditiveExpr) "" "1+(5*3+2)*9" of (Right (LCBV (NVA v))) -> putStr $ show v