Need help with custom syntax

edited 10:17AM in FastScript
Hello,

I am about to alter the C++ sytax to get it closer to the real C-syntax. So here is what I got so far, maybe you will find it useful.

Arrays:
int a[5,5,5], b[5][5][5]; // second is not allowed in C++Script
Fix:
 <array node="array">
    <loop>                                  // added
      <char text="["/>
      <loop text=",">
        <arraydim err="err2"/>
      </loop>
      <char text="]" err="err8"/>
    </loop>                                 // added
  </array>

  ...

  <designator node="dsgn">
    <optional>
      <char text="&" add="addr"/>
    </optional>
    <ident add="node"/>
    <optionalloop>
      <switch>
        <sequence>
          <char text="."/>
          <ident add="node"/>
        </sequence>
        <sequence>
          <char text="[" add="node"/>
          <exprlist err="err2"/>
          <char text="]" err="err8"/>
          <optionalloop>                    // added
            <char text="["/>                // added
            <exprlist err="err2"/>          // added
            <char text="]" err="err8"/>     // added
          </optionalloop>                   // added
        </sequence>
        <sequence>
          <char text="("/>
          <optional>
            <exprlist/>
          </optional>
          <char text=")" err="err7"/>
        </sequence>
      </switch>
    </optionalloop>
  </designator>


Function Declaration:
void test( int a, int b ) {}  // not allowed in C++Script
Fix:
 <formalparameters node="parameters">
    <char text="("/>
    <optionalloop text=",">                   // changed
      <formalparam/>
    </optionalloop>
    <char text=")" err="err7"/>
  </formalparameters>

  <formalparam node="var">
    <ident add="type"/>
    <optional>                                // removed 'loop'
      <char text="&" add="varparam"/>
    </optional>
    <ident add="ident" err="err1"/>
    <optional>
      <initvalue/>
    </optional>
  </formalparam>


FOR-Loop:
for ( a = 10, b = 0; a > 0; a--, b++ ) {}  // multipe declerations are not allowed in C++Script
Fix:
I did not succeded in fixing this. Is it possible to do so without changes in the code?
In a perfect world something like this should have worked:
 <forstmt node="cppforstmt">
    <keyword text="FOR"/>
    <char text="(" err="err12"/>
    <loop text=",">                   // added
      <forstmtitem/>
    </loop>                           // added
    <char text=";" err="err5"/>
    <expression err="err2"/>
    <char text=";" err="err5"/>
    <loop text=",">                   // added
      <forstmtitem/>
    </loop>                           // added
    <char text=")" err="err7"/>
    <statement/>
  </forstmt>


I hope it was helpful for you and maybe someone can help me with the FOR-Loop.

Comments

  • edited 10:17AM
    This should work:
      <!--    ForStmt -> FOR '(' ForCompoundStmt ';' Expression ';' ForCompoundStmt ')' Statement  -->
    
      <forstmt node="cppforstmt">
        <keyword text="FOR"/>
        <char text="(" err="err12"/>
        <forcompoundstmt/>
        <char text=";" err="err5"/>
        <expression err="err2"/>
        <char text=";" err="err5"/>
        <forcompoundstmt/>
        <char text=")" err="err7"/>
        <statement/>
      </forstmt>
    
      <!--    ForCompoundStmt -> (ForStmtItem/,)...  -->
    
      <forcompoundstmt node="compoundstmt">
        <loop text=",">
          <forstmtitem/>
        </loop>
      </forcompoundstmt>
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.