Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: php/cordy/extracted
Source used for this grammar: James R. Cordy, TXL Grammar for PHP 3,4,5, Version 1.0, June 2007
program
, Document
, PHPCloseTagDocumentSection
, PHPOpenTagPHPSection
, PHPSection
, PHPOpenTag
, PHPCloseTag
, HTMLSection
, InlineHTML
, InlineHTMLtoken
, tag_token_or_key
, tag
, bigtag_id
, tag_attribute
, xml_colon
, id_or_key
, TopStatement
, FunctionDecl
, ClassDecl
, ClassType
, ExtendsClause
, ImplementsClause
, Name
, ClassMember
, InterfaceDecl
, InterfaceExtendsClause
, InterfaceMember
, InstanceVariable
, TVariable
, EqualsStaticScalar
, VarModifiers
, VarModifier
, Param
, TypeHint
, Statement
, ExprStatement
, BlockStatement
, Block
, IfStatement
, ElseIfStatement
, ElseStatement
, AltElseifStatement
, AltElseStatement
, WhileStatement
, DoStatement
, ForStatement
, SwitchStatement
, Case
, CaseSeparator
, ControlStatement
, GlobalStaticStatement
, StaticVariable
, UnsetStatement
, EchoStatement
, PrintStatement
, InlineHTMLStatement
, ForEachStatement
, ForEachPattern
, ForEachKey
, ForEachVar
, NullStatement
, DeclareStatement
, Directive
, TryStatement
, Catch
, ThrowStatement
, Expr
, LogicalOrExpr
, OrLogicalXorExpr
, LogicalXorExpr
, LogicalXorLogicalAndExpr
, LogicalAndExpr
, LogicalAndAssignmentExpr
, AssignmentExpr
, AssignOpAssignmentExpr
, AssignOp
, TernaryExpr
, IfConditionalOrExpr
, ConditionalOrExpr
, ConditionalOrConditionalAndExpr
, ConditionalAndExpr
, ConditionalAndBitOrExpr
, BitOrExpr
, BitOrBitXorExpr
, BitXorExpr
, BitXorBitAndExpr
, BitAndExpr
, BitAndEqualityExpr
, EqualityExpr
, EqualityOpInequalityExpr
, EqualityOp
, InequalityExpr
, InequalityOpShiftExpr
, InequalityOp
, ShiftExpr
, ShiftOpCatExpr
, ShiftOp
, CatExpr
, CatAddExpr
, AddExpr
, AddOpMultExpr
, AddOp
, MultExpr
, MultOpNotExpr
, MultOp
, NotExpr
, InstanceExpr
, InstanceOfUnaryExpr
, UnaryExpr
, UnaryOp
, CastType
, IncDecExpr
, IncDec
, Primary
, ScalarConstant
, PlusMinus
, NumericConstant
, StringConstant
, EncapsedInlineHTML
, popid
, token_or_key
, BooleanConstant
, StaticScalar
, Array
, ArrayPair
, ArrayKey
, ArrayValue
, VariableOrFunctionCall
, ObjectCVar
, ClassNameColonColon
, CallParam
, CallParams
, ClassName
, ArrowObjectProperty
, ObjectProperty
, CVar
, ReferenceVariable
, VariableExtension
, CompoundVariable
, VariableName
, SimpleVariableName
, IdOrKey
, List
, ListElem
, InternalFunction
, exit_value
), 1 root (program
), 2 top (popid
, token_or_key
), 17 bottom (key
4, NL
68, SP
, CommandString
, SPON
6, id
19, token
3, EX
16, SPOFF
6, MagicConstant
, number
, Hexa
, FL
2, stringlit
, IN
16, charlit
, Octa
).program ::= Document
Document ::= PHPOpenTagPHPSection PHPCloseTagDocumentSection HTMLSection PHPOpenTagPHPSection PHPCloseTagDocumentSection
PHPCloseTagDocumentSection ::=
PHPCloseTag HTMLSection PHPCloseTagDocumentSection
PHPOpenTagPHPSection ::= PHPOpenTag PHPSection
PHPSection ::=
TopStatement
PHPOpenTag ::= "<?php" NL "<?" NL "<%" NL "<?=" NL
PHPCloseTag ::= "?>" NL "%>" NL
HTMLSection ::= InlineHTML
InlineHTML ::=
InlineHTMLtoken
InlineHTMLtoken ::= tag_token_or_key
tag_token_or_key ::=
tag
";" NL
token
key
tag ::= "<" SPOFF bigtag_id tag_attribute ">" SPON IN NL EX FL "<" SPOFF "/" bigtag_id ">" SPON FL "<" SPOFF "!" id_or_key tag_attribute ">" SPON NL "<" SPOFF "/" id_or_key ">" SPON NL "<" SPOFF id_or_key tag_attribute "/>" SPON NL
bigtag_id ::= "html" "body" "head" "form" "table" "tr" "td" "script" "select" "label" "div"
tag_attribute ::= SP xml_colon"=" tokenid_or_key
xml_colon ::=
"xml:"
id_or_key ::= id "-" id key
TopStatement ::= FunctionDecl ClassDecl Statement InterfaceDecl
FunctionDecl ::= "function" "&" id "(" Param "," ")" NL Block
ClassDecl ::= ClassType id NL ExtendsClause"{" NL IN ClassMember EX "}" NLImplementsClause
ClassType ::= "class" "abstract" "class" "final" "class"
ExtendsClause ::=
"extends" id NL
ImplementsClause ::= "implements" Name "," NL
Name ::= id
ClassMember ::= VarModifiers"abstract" VarModifiers "function" "&" id "(" Param "," ")" ";" NL "var" InstanceVariable "," ";" NL "const" id "=" StaticScalar ";" NL VarModifiers InstanceVariable "," ";" NLFunctionDecl VarModifiers
InterfaceDecl ::= "interface" id NL InterfaceExtendsClause "{" NL IN InterfaceMember EX NL "}"
InterfaceExtendsClause ::= "extends" Name ","
InterfaceMember ::= VarModifiers"function" "&" id "(" Param "," ")" ";" NL
InstanceVariable ::=
TVariable EqualsStaticScalar
TVariable ::= SimpleVariableName
EqualsStaticScalar ::=
"=" StaticScalar
VarModifiers ::=
VarModifier
VarModifier ::= "public" "protected" "private" "static" "final"
Param ::= TypeHint"&" TVariable EqualsStaticScalar "const" TVariable
TypeHint ::= id
Statement ::= ExprStatement BlockStatement IfStatement WhileStatement DoStatement ForStatement SwitchStatement ControlStatement GlobalStaticStatement UnsetStatement EchoStatement PrintStatement InlineHTMLStatement ForEachStatement NullStatement DeclareStatement TryStatement ThrowStatement
ExprStatement ::= Expr ";" NL
BlockStatement ::= Block
Block ::= "{" NL IN TopStatement EX "}" NL
IfStatement ::= "if" "(" Expr ")" NL Statement ElseIfStatement ElseStatement "if" "(" Expr ")" ":" NL IN TopStatement EX AltElseifStatement AltElseStatement "endif" ";" NL
ElseIfStatement ::= "elseif" "(" Expr ")" NL Statement
ElseStatement ::=
"else" NL Statement
AltElseifStatement ::= "elseif" "(" Expr ")" ":" NL IN TopStatement EX
AltElseStatement ::= "else" ":" NL IN TopStatement EX
WhileStatement ::= "while" "(" Expr ")" NL Statement "while" "(" Expr ")" ":" NL IN TopStatement EX "endwhile" ";" NL
DoStatement ::= "do" NL Statement "while" "(" Expr ")" ";" NL
ForStatement ::= "for" "(" Expr "," ";" Expr "," ";" Expr "," ")" NL Statement "for" "(" Expr "," ";" Expr "," ";" Expr "," ")" ":" NL IN Statement EX "endfor" ";" NL
SwitchStatement ::= "switch" "(" Expr ")" NL "{" ";" NL IN Case EX "}" NL "switch" "(" Expr ")" ":" ";" NL IN Case EX "endswitch" ";" NL
Case ::= "case" Expr CaseSeparator NL IN TopStatement EX "default" CaseSeparator NL IN TopStatement EX
CaseSeparator ::= ";" ":"
ControlStatement ::= "break" Expr ";" NL "continue" Expr ";" NL "return" Expr ";" NL
GlobalStaticStatement ::= "global" CVar "," ";" NL "static" StaticVariable "," ";" NL
StaticVariable ::=
TVariable EqualsStaticScalar
UnsetStatement ::= "unset" "(" ObjectCVar "," ")" ";" NL
EchoStatement ::= "echo" Expr "," ";" NL
PrintStatement ::= "print" Expr "," ";" NL
InlineHTMLStatement ::= PHPCloseTag InlineHTML PHPOpenTag
ForEachStatement ::= "foreach" "(" Expr "as" ForEachPattern ")" NL Statement "foreach" "(" Expr "as" ForEachPattern ")" ":" NL IN Statement EX "endforeach" ";" NL
ForEachPattern ::=
ForEachKey
ForEachVarForEachKey ::=
ForEachVar "=>"
ForEachVar ::=
CVar
"&" CVar
NullStatement ::=
";" NL
DeclareStatement ::= "declare" "(" Directive ")" NL Statement
Directive ::= id
TryStatement ::= "try" NL Block Catch
Catch ::= "catch" "(" id TVariable ")" NL Block
ThrowStatement ::= "throw" Expr ";" NL
Expr ::= LogicalOrExpr
LogicalOrExpr ::=
LogicalXorExpr OrLogicalXorExpr
OrLogicalXorExpr ::=
"or" LogicalXorExpr
LogicalXorExpr ::=
LogicalAndExpr LogicalXorLogicalAndExpr
LogicalXorLogicalAndExpr ::=
"xor" LogicalAndExpr
LogicalAndExpr ::=
AssignmentExpr LogicalAndAssignmentExpr
LogicalAndAssignmentExpr ::=
"and" AssignmentExpr
AssignmentExpr ::=
TernaryExpr AssignOpAssignmentExpr
AssignOpAssignmentExpr ::= AssignOp AssignmentExpr
AssignOp ::= ".=" "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "=&"
TernaryExpr ::=
ConditionalOrExpr IfConditionalOrExpr
IfConditionalOrExpr ::= "?" Expr ":" Expr
ConditionalOrExpr ::=
ConditionalAndExpr ConditionalOrConditionalAndExpr
ConditionalOrConditionalAndExpr ::=
"||" ConditionalAndExpr
ConditionalAndExpr ::=
BitOrExpr ConditionalAndBitOrExpr
ConditionalAndBitOrExpr ::=
"&&" BitOrExpr
BitOrExpr ::=
BitXorExpr BitOrBitXorExpr
BitOrBitXorExpr ::=
"|" BitXorExpr
BitXorExpr ::=
BitAndExpr BitXorBitAndExpr
BitXorBitAndExpr ::=
"^" BitAndExpr
BitAndExpr ::=
EqualityExpr BitAndEqualityExpr
BitAndEqualityExpr ::=
"&" EqualityExpr
EqualityExpr ::=
InequalityExpr EqualityOpInequalityExpr
EqualityOpInequalityExpr ::= EqualityOp InequalityExpr
EqualityOp ::= "==" "!=" "===" "!=="
InequalityExpr ::=
ShiftExpr InequalityOpShiftExpr
InequalityOpShiftExpr ::= InequalityOp ShiftExpr
InequalityOp ::= "<>" "<" "<=" ">" ">="
ShiftExpr ::=
CatExpr ShiftOpCatExpr
ShiftOpCatExpr ::= ShiftOp CatExpr
ShiftOp ::= "<<" ">>"
CatExpr ::=
AddExpr CatAddExpr
CatAddExpr ::=
"." AddExpr
AddExpr ::=
MultExpr AddOpMultExpr
AddOpMultExpr ::= AddOp MultExpr
AddOp ::= "+" "-"
MultExpr ::=
NotExpr MultOpNotExpr
MultOpNotExpr ::= MultOp NotExpr
MultOp ::= "*" "/" "%"
NotExpr ::= "!" InstanceExpr
InstanceExpr ::=
UnaryExpr InstanceOfUnaryExpr
InstanceOfUnaryExpr ::=
"instanceof" UnaryExpr
UnaryExpr ::=
UnaryOp
IncDecExprUnaryOp ::= "~" "-" "@" "(" CastType ")" "@" "!"
CastType ::= "int" "integer" "bool" "boolean" "real" "double" "float" "string" "array" "object" "unset"
IncDecExpr ::= IncDecPrimary IncDec
IncDec ::= "++" "--"
Primary ::= VariableOrFunctionCall ScalarConstant Array List InternalFunction "(" Expr ")"
ScalarConstant ::= PlusMinus"null"NumericConstant StringConstant MagicConstant BooleanConstant
PlusMinus ::= "+" "-"
NumericConstant ::= number Hexa Octa
StringConstant ::= stringlit charlit CommandString "<<<" id IN NL EncapsedInlineHTML id EX
EncapsedInlineHTML ::= tag_token_or_key
popid ::= id
token_or_key ::= token key
BooleanConstant ::= "true" "false"
StaticScalar ::= Primary
Array ::= "array" "(" IN ArrayPair "," "," EX ")"
ArrayPair ::=
NL ArrayKey
ArrayValueArrayKey ::=
Expr "=>"
ArrayValue ::=
Expr
"&" ObjectCVar
VariableOrFunctionCall ::= ObjectCVar
ObjectCVar ::= ClassNameColonColonCVar CallParams ArrowObjectProperty
ClassNameColonColon ::=
ClassName "::"
CallParam ::= "&" Expr
CallParams ::= "(" CallParam "," ")"
ClassName ::= id
ArrowObjectProperty ::= "->" ObjectProperty CallParams
ObjectProperty ::= VariableName IdOrKey ObjectProperty VariableExtension ObjectCVar
CVar ::= ReferenceVariable
ReferenceVariable ::=
CompoundVariable VariableExtension
VariableExtension ::= "[" Expr "]" "{" Expr "}"
CompoundVariable ::= VariableName
VariableName ::= SimpleVariableName "$" VariableName "{" SimpleVariableName "}" "{" Expr "}"
SimpleVariableName ::=
id
"$" SPOFF IdOrKey SPON
IdOrKey ::= id key
List ::= "list" "(" ListElem "," ")"
ListElem ::= List ObjectCVar ε
InternalFunction ::= "new" Primary "clone" Primary "isset" "(" ObjectCVar "," ")" "empty" "(" ObjectCVar ")" "intval" "(" ObjectCVar ")" "eval" "(" Expr ")" "exit" exit_value "include" Expr "include_once" Expr "require" Expr "require_once" Expr
exit_value ::= "(" Expr ")"