compiler theory stuff

    Date: 03/30/05 (Computer Geeks)    Keywords: no keywords

    question:
    Develop the BNF for simplified C Boolean expressions.
    Assume that you have a lexical analyser that can recognise the terminal symbols:
    IDENTIFIER, INTEGER, AND, OR,'!', EQUAL, NOTEQUAL, '<', '>', '(', ')'
    Note that in C, any IDENTIFIER is a legal Boolean expression, as is any INTEGER.
    Also note that any valid Boolean expression is also valid if enclosed in brackets, '( )' , but that brackets are optional.
    You need not worry about any other data types (e.g., floating point numbers or chars), nor should you worry about other types of expressions, like mathematical or functional calls, that would need to be included in a more complete definition.
    (Note that operator precedence is not a concern at this phase).


    and my answer:
    booleanExpr ::= expression ';'
    ;

    expression ::= side relationalOp side
    | '(' expression ')'
    | expression logicalOp expression
    ;

    side ::= var
    | INTEGER
    ;


    var ::= IDENTIFIER
    | !var
    ;

    logicalOp ::= AND
    | OR
    ;

    relationalOp::= EQUAL
    | NOTEQUAL
    | '<'
    | '>'
    ;

    I'm sure it's missing a few things though so please jump in :)

    Source: http://www.livejournal.com/community/computergeeks/647090.html

« Computer Services Offered || Tre Help? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home