require 'parslet' include Parslet # Constructs a parser using a Parser Expression Grammar parser = str('"') >> ( str('\\') >> any | str('"').absnt? >> any ).repeat.as(:string) >> str('"') result = parser.parse %Q("this is a valid string") res... 続きを読む
A parsing expression grammar, or PEG, is a type of analytic formal grammar that describes a formal language in terms of a set of rules for recognizing strings in the language. A parsing expression grammar essentially represents a recursive de... 続きを読む
yacc/lexとは Cでプログラミング言語の処理系を実装するのであれば、 多くの場合、yaccとlexというツールを使います。 実のところ、Cとyacc/lexで簡単なプログラミング言語を作る、というのは、 以前、「C言語ヨタ話 」で書いた「 電卓を作ってみよう」 の焼き... 続きを読む