module Roger.Alsing { language Common { // Parameterized List rule syntax List(element) = e:element => [e] | es:List(element) e:element => [valuesof(es), e] ; //predefined token Letter = "A".."Z" | "a".."z"; token Digit = "0".."9"; token AlphaNumeric = (Letter | Digit)+; token Printable = "\u0010".."\u007f"; token SingleQuote = "'"; token DoubleQuote = '"'; // Whitespace token LF = "\u000A"; token CR = "\u000D"; token Space = "\u0020"; @{Classification["Whitespace"]} token Whitespace = LF | CR | Space; } @{CaseSensitive[false]} language Simple { token tStringCh1 = Common.Printable - Common.DoubleQuote; token tStringCh2 = Common.Printable - Common.SingleQuote; @{Classification["String"]} token tStringLiteral = Common.DoubleQuote tStringCh1* Common.DoubleQuote | Common.SingleQuote tStringCh2* Common.SingleQuote ; @{Classification["Identifier"]} token tID = Common.Letter Common.AlphaNumeric*; token tIntegerLiteral = Common.Digit+; token tDecimalLiteral = Common.Digit* "." Common.Digit+; @{Classification["Numeric"]} token tNumberLiteral = tIntegerLiteral | tDecimalLiteral; @{Classification["Keyword"]} final token tDisplay = "display"; @{Classification["Keyword"]} final token tAssign = "assign"; @{Classification["Keyword"]} final token tWhile = "while"; @{Classification["Keyword"]} final token tIf = "if"; @{Classification["Keyword"]} final token tThen = "then"; @{Classification["Keyword"]} final token tElse = "else"; @{Classification["Keyword"]} final token tEnd = "end"; @{Classification["Keyword"]} final token tDo = "do"; @{Classification["Keyword"]} final token tRead = "read"; syntax Main = sStatements ; syntax sStatements = Common.List(sStatement) ; syntax sStatement = tDisplay sExpression | tDisplay sExpression tRead tID | tAssign tID "=" sExpression | tWhile sExpression tDo sStatements tEnd | tIf sExpression tThen sStatements tEnd | tIf sExpression tThen sStatements tElse sStatements tEnd ; syntax sExpression = sExpression ">" sAddExp | sExpression "<" sAddExp | sExpression "<=" sAddExp | sExpression ">=" sAddExp | sExpression "==" sAddExp | sExpression "<>" sAddExp | sAddExp ; syntax sAddExp = sAddExp "+" sMultExp | sAddExp "-" sMultExp | sAddExp "&" sMultExp | sMultExp ; syntax sMultExp = sMultExp "*" sNegateExp | sMultExp "/" sNegateExp | sNegateExp ; syntax sNegateExp = "-" sValue | sValue ; syntax sValue = tID | tStringLiteral | tNumberLiteral | "(" sExpression ")" ; //whitespace interleave Whitespace = Common.Whitespace; } }