<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/221b156fe02eecb4e025b96c11a623ae"
  from="Andrew Lenharth &lt;andrewl@d...&gt;"
  author="Andrew Lenharth"
  date="2003-10-17T21:46:35"
  subject="[Caml-list] a patch to support + and * in ocamlyacc"
  prev="2003/10/a89055e7791771326b90f63885a5f60f"
  next="2003/10/2547e7d7d785deed112b4caad2e8f5c2"
  prev-thread="2003/10/a89055e7791771326b90f63885a5f60f"
  next-thread="2003/10/17bc62c90007181f0de2c5f10ef09f44"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] a patch to support + and * in ocamlyacc">
<msg 
  url="2003/10/221b156fe02eecb4e025b96c11a623ae"
  from="Andrew Lenharth &lt;andrewl@d...&gt;"
  author="Andrew Lenharth"
  date="2003-10-17T21:46:35"
  subject="[Caml-list] a patch to support + and * in ocamlyacc">
</msg>
</thread>

<contents>
I find myself having to often implement rules such as:

foo_plus: foo {[$1]} | foo foo_plus {$1::$2} ;
foo_star: foo_plus {$1} | {[]} ;

in my parsers.  To get rid of this annoyance, here 
is a patch that add support for * and + to ocamlyacc.

http://vilya.homelinux.net/~andrewl/ocamlyacc_p1.diff

it is a bit hackish, but even limited support for * and + makes
writting grammers less painful.

I modify get_name to check for + and *, and rewrite the name
it finds if those exist.  It also adds appropriate rules to a 
buffer to implement the rewritten name.  I change the read character
rutine such that at EOF I switch to the buffer holding the generated
rules.  This has been tested not to break the bootstrapping system.

An example:

%token &lt;int&gt; INT_LITERAL
%token EOF

%start main /* entry point */
%type &lt;int list&gt; main

%%
main:
  INT_LITERAL+ EOF {$1}
  ;


Andrew Lenharth

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

