Take the 2-minute tour ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

I am studying formal languages and playing with writing my own parsers for them. I have a context free grammar parser already that works well. I am wondering if anyone can point me towards actually implemented examples of rewriters. For example, suppose I had the rules

WORD: [A-Z]+

QUOTE: "

And I wanted to input a lot of words,put quotes around each one, and write out the string. Or go back and forth. Something like this:

(WORD [' '])+ <--> (QUOTE WORD QUOTE [' '])+

That seems kind of possible to implement automatically without ambiguity, but I was hoping someone had seen something along that line that already exists.

share|improve this question
2  
Stratego is a system that allows you to write term-rewrite rules and it will compile them for you. –  Dave Clarke Nov 21 '12 at 12:00
1  
A link: strategoxt.org –  Dave Clarke Nov 21 '12 at 12:26
    
Hi @Dave. I read up on it and it's pretty complex. Do you use it for anything? Can you describe the syntax for the above example? –  Dan Gelder Nov 21 '12 at 12:59
    
I haven't used it for years, unfortunately. I always mean to, but never find the time. –  Dave Clarke Nov 21 '12 at 15:08
    
Correct if I am wrong, but are you thinking in an imperative language? If so,consider using a functional language. –  Guy Coder Nov 21 '12 at 15:25
show 1 more comment

1 Answer

Thue language is based on string rewriting and it's just 179 lines of c code.

Pure is an LGPL'd functional language based on term rewriting.

Not an example, but a course with really complete slides on the theory of term rewriting systems.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.