Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 grammar and LIST1
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: Re: [Caml-list] camlp4 grammar and LIST1

On Mar 10, 2009, at 9:48 PM, Jake Donham wrote:

>> statement: [ [ s = openStatement -> s | s = closedStatement -> s ] ];
>
> Syntactically it is fine but I don't think this is going to do what
> you want. Camlp4 parsers aren't backtracking; you have to distinguish
> openStatement from closedStatement by parsing a token.

I have it like this at the moment. Are you saying it won't work?

What does it mean to parse a token then?

Does that token have to be in the same rule?

	Thanks, Joel

---

   statement: [ [ openStatement | closedStatement ] ];

   openStatement: [ [ openIfStatement ] ];

   openIfStatement:
   [
     [ "If"; e = expr; "Then"; s1 = closedStatement; "Else"; s2 =  
openStatement -> If (e, s1, s2)
     | "If"; e = expr; "Then"; s = statement -> If (e, s, Skip)
     ]
   ];

   closedIfStatement:
   [
     [ "If"; e = expr; "Then"; s1 = closedStatement; "Else"; s2 =  
closedStatement -> If (e, s1, s2) ]
   ];

   closedStatement:
   [
     [ inputDeclarations
     | varDeclarations
     | arrayDeclarations
     | compoundStatement
     | assignment
     | closedIfStatement
     | whileStatement
     | forStatement
     | tradeStatement
     | preprocessorStatement
     | procCall
     ]
   ];

   inputDeclarations:
   [
     [ "Input"; ":";
       l = LIST1 [ x = inputDeclaration -> x ] SEP "," -> InputDecls l
     ]
   ];
   ...

---
http://tinyco.de
--- Mac & iPhone