Boost logo

Boost :

From: Chau Johnthan (chaujohnthan_at_[hidden])
Date: 2004-09-08 13:59:55


can I use the following bnf with boost?

comments are appreciated.

/*** Jscript.bnf ******************************************* 11-01-99 ***
* *
* Function: A Lingua-based BNF description of the JSCRIPT language. *
* *
* This translation copyright (C), 2000,2002,2003 Neuric Technologies. *
* All rights reserved. No part of this document may be used in in any *
* form, nor may derivative works be made from it, except as follows: *
* *
* This is a translation of an ECMASCRIPT description obtained from the *
* ECMA standards committee and available on the Internet. It is simi- *
* lar to Microsoft's JSCRIPT language, and is given as an example of *
* the conversion of typical industry language descriptions to Lingua *
* BNFs. *
* *
* The translation is provided AS-IS by Neuric Technologies as an *
* example of how to translate BNFs. It is not complete with C++ *
* interfaces, but demonstrate the processes. It is believed to be *
* functional, but is not guaranteed to free of errors. Compiled and *
* linked into Lingua's PTEST sample program, it then parses ANSI C *
* statements and produces a diagnostic listing of the results. *
* *
* As you can see, Lingua BNFs are extremely short compared to YACC/LEX *
* equivalents and are very readable. *
* *
* NOTICE: This sample parser is supplied "AS-IS", without support and *
* is not an exhaustive or necessarily complete parser for JSCRIPT. It *
* is supplied as a starting point from which a parser (for use with *
* Lingua, only) may be derived. *
* *
* *** Visit us at: www.neuric.com *** *
* Revision Record: *
* 1.00 11-1-99 *
* 1. Initial interpretation from ECMA *
* *
* 1.02 1-15-00; *
* 1. Simplification and speedup: VariableStatement, ForStatement. *
* 2. Addition of ",h" suffix for hiding of excess pattern tracing. *
* 3. Addition of patterns for Literal, NullLiteral, BooleanLiteral,*
* and other functions. *
* *
**************************************************** Thomas A. Visel ***/
includes {
    include "d:\lingua\ptest\pview.h"; // Decls for the ultimate view class.
    }

info {
    emit c++; // (Default) or... "emit c"
    author "Thomas A. Visel";
    viewclass "CPView"; // Class for the display view.
    }

patterns {
    string Symbol;
    numeric I;
    interface Record_Newflag (I);

/*** Program-level Grammer ***
    Program = autoskip SourceElements;

    SourceElements = SourceElement [SourceElement]*;

    SourceElement,h = {Statement | FunctionDeclaration};

    FunctionDeclaration = "function" Identifier "(" [FormalParameterList]
")" Block;

    FormalParameterList = Identifier ["," Identifier];

/*** Statement-level Grammer **/
    Statement = {
        Block | VariableStatement | EmptyStatement
      | IfStatement | IterationStatement | ContinueStatement |
BreakStatement
      | ReturnStatement | WithStatement | ExpressionStatement
        };

    Block = "{" [StatementList] "}";

    StatementList = Statement [Statement]*;

    VariableStatement = "var" VariableDeclaration ["," VariableDeclaration]*
";";

    VariableDeclaration = Identifier [Initializer];

// Initializer = {"=" AssignmentExpression | EmptyStatement | ";"};
    Initializer = "=" AssignmentExpression;

    EmptyStatement = ";";

    ExpressionStatement = Expression ";";

    IfStatement = "if" "(" Expression ")" Statement ["else" Statement];

    IterationStatement = {WhileStatement | ForStatement};

    WhileStatement = "while" "(" Expression ")" Statement;

    ForStatement = "for" "(" {
        "var" Identifier [Initializer] "in" Expression
      | LeftHandSideExpression "in" Expression
// | "var" VariableDeclarationList ";" [Expression] ";" [Expression]
      | VariableStatement [Expression] ";" [Expression]
      | [Expression] ";" [Expression] ";" [Expression]
        } ")" Statement;

    ContinueStatement = "continue" ";";

    BreakStatement = "break" ";";

    ReturnStatement = "return" [Expression] ";";

    WithStatement = "with" "(" Expression ")" Statement;

/*** Expression-level Grammer ***/
    PrimaryExpression = {"this" | Identifier | Literal | "(" Expression
")"};

    MemberExpression,h =
 [NewFlag]
 PrimaryExpression
 [{'.' Identifier | "[" Expression "]"}]*
 [Arguments];

// NewExpression = {MemberExpression | "new" NewExpression};
    NewExpression,h = [NewFlag] MemberExpression;

    NewFlag,h = "new ";

    CallExpression = MemberExpression Arguments
        [{Arguments | "[" Expression "]" | '.' Identifier}]*;

    Arguments = "(" {")" | [ArgumentList] ")"};

    ArgumentList = AssignmentExpression ["," AssignmentExpression]*;

    LeftHandSideExpression = {NewExpression | CallExpression};

    PostfixExpression = LeftHandSideExpression {"++" | "--" | };

    UnaryExpression,h =
        [{"delete" | "void" | "typeof" | "++" | "--" | "+" | "-" | "~" |
"!"}]
        PostfixExpression;

    MultiplicativeExpression,h = UnaryExpression
        [{"*" | "/" | "%"} UnaryExpression]*;

    AdditiveExpression,h = MultiplicativeExpression
        [{"=" | "+" | "-"} MultiplicativeExpression]*;

    ShiftExpression,h = AdditiveExpression
        [{"<<" | ">>>" | ">>"} AdditiveExpression]*;

    RelationalExpression,h = ShiftExpression
        [{"<=" | "<" | ">=" | ">"} ShiftExpression]*;

    EqualityExpression,h = RelationalExpression
        [{"==" | "!="} RelationalExpression]*;

    BitwiseANDExpression,h = EqualityExpression ["&" EqualityExpression]*;

    BitwiseXORExpression,h = BitwiseANDExpression ["^"
BitwiseXORExpression]*;

    BitwiseORExpression,h = BitwiseXORExpression ["|"
BitwiseXORExpression]*;

    LogicalANDExpression,h = BitwiseORExpression ["&&"
BitwiseORExpression]*;

    LogicalORExpression,h = LogicalANDExpression ["||"
LogicalANDExpression]*;

    ConditionalExpression,h = LogicalORExpression
        ["?" AssignmentExpression ":" AssignmentExpression];

/* AssignmentExpression = {ConditionalExpression
      | LeftHandSideExpression AssignmentOperator AssignmentExpression
        } */

    AssignmentExpression = {ConditionalExpression
      | LeftHandSideExpression [AssignmentOperator ConditionalExpression]*
        };

    AssignmentOperator = {
        "=" | "*=" | "/=" | "%=" | "+=" | "-="
      | "<<=" | ">>>=" | ">>=" | "&=" | "^=" | "|="
        };

// Expression = {AssignmentExpression | Expression ","
AssignmentExpression};
    Expression = AssignmentExpression ["," AssignmentExpression]*;

/*** Low level (intrinsic-based) items ***/
    Identifier,h = bspan {alpha | '_' | '$'} [{alfnum | '_' | '$'}]*;

    Literal,h = {NumericLiteral | StringLiteral | BooleanLiteral |
NullLiteral};

    NumericLiteral = {cfloat | cint | HexLiteral};

    HexLiteral = {"0x" | "0X"} xdigit [xdigit]*;

    StringLiteral = cstring;

    BooleanLiteral = {"true" | "false"};

    NullLiteral = "null";
    }

"Chau Johnthan" <chaujohnthan_at_[hidden]> wrote in message
news:chi7om$qb4$1_at_sea.gmane.org...
> I am totally a newbie of boost lib, I am finding ebnf of jscript,
> and I wish I can gen c source of lexer, parser by using boost.
>
>
>
> thanks.
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk