Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Foo {
- language Pipetest {
- interleave Whitespace = ' ' | '\t' | '\n' | '\r';
- token Identifier = ('a'..'z'|'A'..'Z'|'_')+;
- syntax ExprPrimary(HigherPrec)
- = ident:Identifier => Identifier { ident }
- | '(' e:HigherPrec ')' => e
- ;
- syntax ExpressionList(Expr)
- = e:Expr => [e]
- | lhs:ExpressionList(Expr) ',' rhs:Expr
- => [valuesof(lhs),rhs]
- ;
- syntax ExprPostfix(HigherPrec, Expr)
- = e:HigherPrec => e
- | lhs:(ExprPostfix(HigherPrec, Expr)) "++"
- => PostfixInc { valuesof(lhs) }
- | lhs:(ExprPostfix(HigherPrec, Expr)) "--"
- => PostfixDec { valuesof(lhs) }
- | lhs:(ExprPostfix(HigherPrec, Expr)) '(' rhs:ExpressionList(Expr)? ')'
- => FunctionCall { valuesof(lhs), rhs }
- | lhs:(ExprPostfix(HigherPrec, Expr)) '[' rhs:ExpressionList(Expr)? ']'
- => Subscript { valuesof(lhs), rhs }
- | lhs:(ExprPostfix(HigherPrec, Expr)) '.' rhs:Identifier
- => MemberAccess { valuesof(lhs), rhs }
- | lhs:(ExprPostfix(HigherPrec, Expr)) "->" rhs:Identifier
- => PointerMemberAccess { valuesof(lhs), rhs }
- ;
- syntax ExprUnary(HigherPrec)
- = e:HigherPrec => e
- | '-' rhs:(ExprUnary(HigherPrec))
- => Neg { valuesof(rhs) }
- | '+' rhs:(ExprUnary(HigherPrec))
- => Pos { valuesof(rhs) }
- | '!' rhs:(ExprUnary(HigherPrec))
- => Not { valuesof(rhs) }
- | '~' rhs:(ExprUnary(HigherPrec))
- => Complement { valuesof(rhs) }
- | "++" rhs:(ExprUnary(HigherPrec))
- => PrefixInc { valuesof(rhs) }
- | "--" rhs:(ExprUnary(HigherPrec))
- => PrefixDec { valuesof(rhs) }
- | '*' rhs:(ExprUnary(HigherPrec))
- => Dereference { valuesof(rhs) }
- | '&' rhs:(ExprUnary(HigherPrec))
- => AddressOf { valuesof(rhs) }
- ;
- syntax ExprPointerToMember(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprPointerToMember(HigherPrec)) ".*" rhs:HigherPrec
- => PointerToMember { valuesof(lhs), rhs }
- | lhs:(ExprPointerToMember(HigherPrec)) "->*" rhs:HigherPrec
- => PointerToPointerMember { valuesof(lhs), rhs }
- ;
- syntax ExprMultiplicative(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprMultiplicative(HigherPrec)) '*' rhs:HigherPrec
- => Mul { valuesof(lhs), rhs }
- | lhs:(ExprMultiplicative(HigherPrec)) '/' rhs:HigherPrec
- => Div { valuesof(lhs), rhs }
- | lhs:(ExprMultiplicative(HigherPrec)) '%' rhs:HigherPrec
- => Mod { valuesof(lhs), rhs }
- ;
- syntax ExprAdditive(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprAdditive(HigherPrec)) '+' rhs:HigherPrec
- => Add { valuesof(lhs), rhs }
- | lhs:(ExprAdditive(HigherPrec)) '-' rhs:HigherPrec
- => Sub { valuesof(lhs), rhs }
- ;
- syntax ExprShift(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprShift(HigherPrec)) "<<" rhs:HigherPrec
- => Shl { valuesof(lhs), rhs }
- | lhs:(ExprShift(HigherPrec)) ">>" rhs:HigherPrec
- => Shr { valuesof(lhs), rhs }
- ;
- syntax ExprCompare(HigherPrec)
- = e:HigherPrec => e
- | lhs:HigherPrec "<=>" rhs:HigherPrec
- => Compare { lhs, rhs }
- ;
- syntax ExprRelational(HigherPrec)
- = e:HigherPrec => e
- | lhs:HigherPrec '<' rhs:HigherPrec => Lt { lhs, rhs }
- | lhs:HigherPrec '>' rhs:HigherPrec => Gt { lhs, rhs }
- | lhs:HigherPrec "<=" rhs:HigherPrec => Le { lhs, rhs }
- | lhs:HigherPrec ">=" rhs:HigherPrec => Ge { lhs, rhs }
- ;
- syntax ExprEquality(HigherPrec)
- = e:HigherPrec => e
- | lhs:HigherPrec "==" rhs:HigherPrec => Eq { lhs, rhs }
- | lhs:HigherPrec "!=" rhs:HigherPrec => Ne { lhs, rhs }
- ;
- syntax ExprBitwiseAnd(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprBitwiseAnd(HigherPrec)) '&' rhs:HigherPrec
- => BitwiseAnd { valuesof(lhs), rhs }
- ;
- syntax ExprBitwiseXor(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprBitwiseXor(HigherPrec)) '^' rhs:HigherPrec
- => BitwiseXor { valuesof(lhs), rhs }
- ;
- syntax ExprBitwiseOr(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprBitwiseOr(HigherPrec)) '|' rhs:HigherPrec
- => BitwiseOr { valuesof(lhs), rhs }
- ;
- syntax ExprLogicalAnd(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprLogicalAnd(HigherPrec)) "&&" rhs:HigherPrec
- => LogicalAnd { valuesof(lhs), rhs }
- ;
- syntax ExprLogicalOr(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprLogicalOr(HigherPrec)) "||" rhs:HigherPrec
- => LogicalOr { valuesof(lhs), rhs }
- ;
- syntax ExprAssign(HigherPrec)
- = e:HigherPrec => e
- | lhs:HigherPrec "=" rhs:(ExprAssign(HigherPrec))
- => Assign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "+=" rhs:(ExprAssign(HigherPrec))
- => AddAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "-=" rhs:(ExprAssign(HigherPrec))
- => SubAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "*=" rhs:(ExprAssign(HigherPrec))
- => MulAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "/=" rhs:(ExprAssign(HigherPrec))
- => DivAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "%=" rhs:(ExprAssign(HigherPrec))
- => ModAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "<<=" rhs:(ExprAssign(HigherPrec))
- => ShlAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec ">>=" rhs:(ExprAssign(HigherPrec))
- => ShrAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "&=" rhs:(ExprAssign(HigherPrec))
- => AndAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "^=" rhs:(ExprAssign(HigherPrec))
- => XorAssign { lhs, valuesof(rhs) }
- | lhs:HigherPrec "|=" rhs:(ExprAssign(HigherPrec))
- => OrAssign { lhs, valuesof(rhs) }
- ;
- syntax ExpressionCPP
- = e:
- ExprAssign(
- ExprLogicalOr(
- ExprLogicalAnd(
- ExprBitwiseOr(
- ExprBitwiseXor(
- ExprBitwiseAnd(
- ExprEquality(
- ExprRelational(
- ExprCompare(
- ExprShift(
- ExprAdditive(
- ExprMultiplicative(
- ExprPointerToMember(
- ExprUnary(
- ExprPostfix(
- ExprPrimary(
- ExpressionCPP
- ),
- ExpressionCPP
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ) => e
- ;
- syntax ExprPostfixWithPipe(HigherPrec, Expr)
- = e:HigherPrec => e
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "|>" rhs:HigherPrec '(' e:ExpressionList(Expr)? ')'
- => Pipe { valuesof(lhs), FunctionCall { rhs, e } }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "++"
- => PostfixInc { valuesof(lhs) }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "--"
- => PostfixDec { valuesof(lhs) }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '(' ExpressionList(Expr)? ')'
- => FunctionCall { valuesof(lhs) }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '[' ExpressionList(Expr)? ']'
- => Subscript { valuesof(lhs) }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '.' rhs:Identifier
- => MemberAccess { valuesof(lhs), rhs }
- | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "->" rhs:Identifier
- => PointerMemberAccess { valuesof(lhs), rhs }
- ;
- syntax ExpressionR0
- = e:
- ExprAssign(
- ExprLogicalOr(
- ExprLogicalAnd(
- ExprBitwiseOr(
- ExprBitwiseXor(
- ExprBitwiseAnd(
- ExprEquality(
- ExprRelational(
- ExprCompare(
- ExprShift(
- ExprAdditive(
- ExprMultiplicative(
- ExprPointerToMember(
- ExprUnary(
- ExprPostfixWithPipe(
- ExprPrimary(
- ExpressionR0
- ),
- ExpressionR0
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ) => e
- ;
- syntax ExprPipe(HigherPrec)
- = e:HigherPrec => e
- | lhs:(ExprPipe(HigherPrec)) "|>" rhs:HigherPrec
- => Pipe { valuesof(lhs), rhs }
- ;
- syntax ExpressionR1
- = e: ExprAssign(
- ExprLogicalOr(
- ExprLogicalAnd(
- ExprBitwiseOr(
- ExprBitwiseXor(
- ExprBitwiseAnd(
- ExprEquality(
- ExprRelational(
- ExprCompare(
- ExprShift(
- ExprAdditive(
- ExprMultiplicative(
- ExprPipe(
- ExprPointerToMember(
- ExprUnary(
- ExprPostfix(
- ExprPrimary(
- ExpressionR1
- ),
- ExpressionR1
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ) => e
- ;
- syntax ExprPipe(HigherPrecLeft, HigherPrecRight)
- = e:HigherPrecLeft => e
- | lhs:(ExprPipe(HigherPrecLeft, HigherPrecRight)) "|>" rhs:HigherPrecRight
- => Pipe { valuesof(lhs), rhs }
- ;
- syntax ExprLimitedToPM(Expr)
- = e:ExprPointerToMember(
- ExprUnary(
- ExprPostfix(
- ExprPrimary(
- ExprLimitedToPM(Expr)
- ),
- Expr
- )
- )
- ) => e
- ;
- syntax ExpressionRx
- = e: ExprAssign(
- ExprPipe(
- ExprLogicalOr(
- ExprLogicalAnd(
- ExprBitwiseOr(
- ExprBitwiseXor(
- ExprBitwiseAnd(
- ExprEquality(
- ExprRelational(
- ExprCompare(
- ExprShift(
- ExprAdditive(
- ExprMultiplicative(
- ExprPointerToMember(
- ExprUnary(
- ExprPostfix(
- ExprPrimary(
- ExpressionRx
- ),
- ExpressionRx
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ),
- ExprLimitedToPM(ExpressionRx)
- )
- ) => e
- ;
- syntax CompilationUnit
- = "#pragma CPP" e:(e:ExpressionCPP "\r\n" => e)*
- => CPPExpressions [ valuesof(e) ]
- | "#pragma R0" e:(e:ExpressionR0 "\r\n" => e)*
- => R0Expressions [ valuesof(e) ]
- | "#pragma R1" e:(e:ExpressionR1 "\r\n" => e)*
- => R1Expressions [ valuesof(e) ]
- | "#pragma Rx" e:(e:ExpressionRx "\r\n" => e)*
- => RxExpressions [ valuesof(e) ]
- ;
- syntax Main
- = c:("----\r\n" c:CompilationUnit => c)*
- => CompilationUnits [ valuesof(c) ]
- ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement