<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 3, 2016 at 10:34 AM Metin Akat <<a href="mailto:akat.metin@gmail.com">akat.metin@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><br><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">P 2015/11/21 02:18:02 USD 1.1 EUR</div></div><div class="gmail_msg"><br class="gmail_msg"></div><br><div class="gmail_msg">So my question is: How do I tackle this? Do I just accept "P" as a WORD token and somehow instruct yecc to parse based on the WORD's value? Is it even possible to do?</div><br class="gmail_msg"></div></blockquote><div><br></div><div>(This is loosely from memory)<br><br></div><div>The reason ^ and $ are not implemented is because they are never needed in an LALR(1) parser/scanner construction. We want the above line to be scanned into<br><br></div><div>[{cmd, "P"}, {int, 2015}, '/', {int, 11}, '/', {int, 21}, {int, 2}, ':', ...<br></div><div> {id, "USD"}, {float, 1.1}, {id, "EUR}]<br><br></div><div>Then we can define a yecc-grammar which can turn these into meaningful constructions:<br><br></div><div>Command -> Cmd Date Time Currency Amount Currency<br></div><div>  : {command, $1, $2, $3, {$4, $5, $5}}.<br></div><div><br></div><div>Date -> Year '/' Month '/' Date : {$1, $3, $5}.<br></div><div>Year -> int : $1.<br></div><div>Month -> int : $1.<br>...<br><br></div><div>Sometimes, the indentation in the file does matter. But then it can be smarter to code the lexer by hand or pre-pass over the input file and insert markers for newlines etc. In other words, give structure to the input before actually parsing it. This is used in many languages which uses indentation-based-scope: a pre-pass inserts the scope markers based on newlines and indentation. Then the scanner takes over and handles the stream which has structure.<br><br></div><div><br></div><div><br></div></div></div>